Maker.io main logo

Control a USB Power Supply with an Arduino

2017-10-20 | By All About Circuits

License: See Original Project Capacitors Switches Arduino

Courtesy of All About Circuits

Arduinos have the ability to automatically control all kinds of circuits. For this project, we’ll look at an easy way Arduinos can be used to make a power supply that will automatically adjusts its output to maintain a constant voltage or current. This particular circuit will run on USB power, designed specifically for small, low-voltage applications. However, the project can be modified to use larger power supplies for higher power applications.

Materials

Materials

How to Power the Circuit

For this project, power is supplied by a USB port routed through the Arduino with a standard USB connector cable. We will be connecting the power supply circuit to the 5V pin on the Arduino, which can supply 5V and up to 200mA. The code provided for this particular project is designed so the current of the power supply circuit will not got above 150mA.

Power is Supplied by a USB Port

The Output Circuit

The Output Circuit

A transistor circuit built around an IR520 power MOSFET is the main part of the output circuit.

Pin 9 supplies a PWM signal to the circuit, sent through a 1 kOhm resistor and 1000 microfarad capacitor. There will still be some fluctuations, but these will be mostly smoothed out to a relatively constant DC signal, which is sent to the MOSFET gate.

Between the gate of the transistor and 5V we will place a 470 ohm resistor in order to raise the gate voltage to a point where the source-drain junction will conduct. You may need to adjust values to calibrate the circuit for the specific parts you are using in this project. The 1 kohm resistor and the 470 ohm resistor can both be substituted for higher values, allowing you to use a small value for the capacitor.

A 10 ohm, 10 watt reference resistor is connected to the MOSFET’s drain, which is also connected to analog pin 2 on our Arduino.

Analog pin 1 is connected to the opposite side of the 10 ohm resistor. This connection is used to sense the power supply’s output. The power supply’s output terminals are connected to the reference resistor and 5V. To make access a bit easier, use a pair of screw terminals to connect and disconnect the wires from the output.

The Output Circuit Schematic

The Switches

Switches on Separate Breadboard Control the Circuit

For simplicity’s sake, the switches that control the circuit are mounted on a separate breadboard. To adjust the output of the power supply, two momentary pushbuttons are used. One end of each switch connects to GND. The other end connects digital pins 10 and 11. These digital pins also connect to the 5V with 100 kOhm resistors, which act as pull-up resistors and set the digital pins to HIGH until we press the button. The third switch’s job is as a single pole double throw toggle switch, which sets the output mode. The two end pins of the switch connect to GND and 5V. The center pin connects to digital pin 12, which, when connected to 5V the system output is a constant voltage and when connected to GND the system output is a constant current.

The Switches Schematic

The Code

The first item found at the top of the code is the resistance variable. This refers to the value of the reference resistor we use in the circuit. Make sure to use a multimeter to measure the value exactly, rather than assuming it is the labeled value. If the labeled value is assumed, you could find yourself with inaccurate readings when you attempt using your power supply. After measuring the resistor, write the value in ohms into the code.The first section of the main loop of code uses the analogRead function to measure voltages at both side of the reference resistor. Once you have these values, you can calculate the terminal voltage of the power supply as well as the current going through the load.

After that, use the digitalRead function to determine the state of the switches. The toggle switch works to set the operating mode of the power supply. One mode is set so the output is set to a constant voltage and the other mode, the output is set to a constant current. If you press one of the momentary pushbuttons, the target output level adjusts up or down. To avoid false triggering from switch bounce and to also limit how quickly you can change the output, these function have a built-in delay.

The output of the power supply displays with the Serial.print command, which is useful when debugging the power supply’s operation.

There are various safety limits built into the code. The first is at startup, where a delay is built, allowing the output to reset before the circuit begins automatically adjusting itself. The output is limited to 150mA to save the Arduino from damage. The analogWrite functions controlling the outputs can not exceed 250 or go below 0. There is also a limit in place for how quickly the output can change within the system.

Operation

This circuit performs pretty well within the designated operating range with an accuracy of about +/- mA or +/- 0.05 V. Although the output is fairly steady, there are still some fluctuations due to the fact that a PWM signal drives the circuit.

The Circuit Driven by a PWM Signal

All code for this project can be downloaded here.

 

 

制造商零件编号 A000066
ARDUINO UNO R3 ATMEGA328P BOARD
Arduino
¥190.97
Details
制造商零件编号 IRF510PBF
MOSFET N-CH 100V 5.6A TO220AB
Vishay Siliconix
¥10.74
Details
制造商零件编号 CF14JT1K00
RES 1K OHM 5% 1/4W AXIAL
Stackpole Electronics Inc
¥0.81
Details
制造商零件编号 CF14JT470R
RES 470 OHM 5% 1/4W AXIAL
Stackpole Electronics Inc
¥0.81
Details
制造商零件编号 CF14JT100K
RES 100K OHM 5% 1/4W AXIAL
Stackpole Electronics Inc
¥0.81
Details
制造商零件编号 PTS645SM43SMTR92 LFS
SWITCH TACTILE SPST-NO 0.05A 12V
C&K
¥2.60
Details
制造商零件编号 153
JUMPER WIRE M TO M VARIOUS
Adafruit Industries LLC
¥40.29
Details
制造商零件编号 25PX1000MEFCT810X16
CAP ALUM 1000UF 20% 25V RADIAL
Rubycon
¥5.37
Details
制造商零件编号 RSMF3JT10R0
RES 10 OHM 5% 3W AXIAL
Stackpole Electronics Inc
¥3.34
Details
制造商零件编号 OSTTA020161
TERM BLK 2POS SIDE ENTRY 5MM PCB
On Shore Technology Inc.
¥7.90
Details
制造商零件编号 321010008
CABLE A PLUG TO B PLUG 4.92'
Seeed Technology Co., Ltd
¥15.87
Details
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum