Providing the right voltage and limiting the current to a circuit you are prototyping can help avoid damaging components that are incorrectly used or installed. Here we have a power supply solution that you can build yourself.
BUILD TIME: 6 Hours
DIFFICULTY RATING: Intermediate
I recently had the opportunity to work alongside a group of electronics students who were completely new to building electronic circuits on breadboards. This opportunity allowed me to see their struggles but also remember my own when I first started on my electronics adventure.
The most obvious struggle I both remembered and witnessed in this group of students, was just how difficult it was starting out to power your project. With that in mind, I began thinking of a simple to build tool which should alleviate the stress for newcomers to the electronics field. From that thought came this Breadboard power supply, with voltage and current limiting switchmode boost-buck converter.
THE BROAD OVERVIEW
The idea of this project was to give students and those new to electronics, not only the ability to limit the voltage to their circuit, but also the ability to limit the current. A current limiting feature would reduce the chance of destroying sensitive electronics as you begin to experiment.
To operate, the user first selects the voltage they require using the Voltage potentiometer. They then simply short out the supply and use the Current potentiometer to reduce or increase the current to the desired level. This ensures that if something is wrong with their circuit, the supply is limited to only providing the maximum pre-set current, thus reducing the current to any incorrectly wired components and hopefully preventing any damage (i.e. letting the smoke out!).
HOW IT WORKS
The Buck / Boost Converter
The core of this project revolves around the switchmode voltage regulator, the fundamentals of which was covered in DIYODE Issue 11. In case you missed that issue, a switchmode power supply takes advantage of the energy storage capabilities of two major components; the capacitor which resists changes in voltages and the inductor which resists changes in current. The keyword here, of course, is changing.
Inductors and capacitors need a changing state in order to utilise this function. Something that our steady state DC cannot provide by itself. Therefore, we need to provide a constantly changing state. This is where we get the switch in switchmode.
This changing state usually comes in the form of a pulse width modulated signal (PWM) applied to the base of a transistor/MOSFET, which is connected to a feedback circuit so that it is able to adjust for load fluctuations, but alas let’s keep it simple.
Let’s assume there is no load on the circuit and we have a VCC of 12VDC. Let’s say we want 6V on the output. If we applied a fast pulsating DC square wave with a duty cycle of 50% to the base of the transistor in the schematic shown here, we are effectively only allowing current to flow into the circuit for 50% of the time. The capacitors and inductor smooth out the sudden changes in voltage and we effectively get 50% of the voltage or 6V (AVG) on the output.
This basic schematic shows a buck boost circuit. Now, of course, this isn’t on its own very useful as if any load is applied it changes the circuit and we would need to modify the PWM to suit. This is where the feedback circuit comes in which requires a PWM controller and a bunch of tricky circuitry. That is, however, the basics for a switchmode power supply.
Despite this added complexity, switchmode regulators have one huge benefit over their linear regulator brethren - they are comparatively extremely efficient. Linear regulators simply sink the excess voltage to ground causing them to get insanely hot, requiring big heatsinks and added expense etc. They are, for the most part, only used today in low current applications. Whereas switchmode regulators are widely used in all manner of products from power supplies for computers to power supplies for wrist watches.
It goes without saying, designing a switchmode power supply isn’t as simple as designing a linear regulated one. Therefore rather than designing and building the circuit in its entirety, it is significantly easier and also more cost effective to purchase an off the shelf module.
For this project, I opted for an LM2577 based Boost Buck regulator module, largely as it had included on the module a constant current feature which was ideal for the project.
This module essentially takes a voltage between 4V and 35V and allows you to output an adjustable output voltage between 1.25V and 25V with a maximum current output of 2A, which is much more than the average person is likely to need for their breadboard prototyping. It is an inexpensive module, with a fairly stable output at lower currents.
The Microcontroller and Display
Having the ability to limit the voltage and current of our supply is only half of the equation. We need a way to display the values so that the user can easily see the voltage and current being supplied to their circuit.
For this, I opted for the Arduino Nano development board and the Nokia 5110 LCD. The Nano is a perfect size to keep the overall dimensions of the device to a minimum and the LCD is big and clear, allowing for the instant acquisition of the necessary values.
The Voltage Divider
With the display and controller figured out, we need a way for the microcontroller to take a measurement of the voltage, so it could be displayed on the LCD. Given our output voltage can range from 1.25V to 25V it wasn’t possible to simply use an analog pin on the Arduino to measure the voltage, as the analog pins can only handle a voltage of up to 5V. Therefore, we needed a way to take the maximum 25V of the output and reduce it to a maximum of 5V for the Arduino to read, without changing the accuracy of course.
To do this I needed a voltage divider. You can read about voltage dividers in the Circuit Analysis article in Issue 11.
In this case, we need a maximum voltage output of 5V when the voltage into the network exceeds 25V.
Let’s say, for example, our power supply puts out 30V. To reduce this 30V down to 5V we need to pick a resistance value for which is high enough to ensure the current would be low, thus not wasting power, and yet low enough to allow the divider to work correctly. Let’s pick a value of 10KΩ.
Using the voltage divider rule, we can calculate the required resistance value of Ra.
VOUT = E(Rb/(Ra+Rb)) = 30(10000/(Ra + 10000)) = 5V
Ra = 50000 (that is, 50,000Ω)
Therefore, our voltage divider needs to consist of a 10,000Ω (10kΩ) resistor for Rb and 50,000Ω (50kΩ) resistor for Ra.
To calculate this, we simply needed Ohm's law.
I = V/R = 30/60000 = 500 × 10-6 A or .5mA
Therefore, we have half a milliamp of current flowing into this divider at all times. This is low enough to not be wasting power and comfortably high enough to mean the ADC load will have a minimal/negligible impact on its operation.
The Shunt Resistor and Amplifier
With the easy part of reading voltage out of the way, I needed to tackle how to measure the current (The FUNdamentals of this can be read in Issue 8).
Rather than buying a big bulky current shunt (which would increase the size of the enclosure) I opted to use a small 5W ceramic 0.01Ω resistor.
Arguably, a 5W resistor is total overkill for what we're doing, but it makes us feel better about things, and ensures low heat generation regardless.
I could read the voltage drop across the resistor and then, using Ohm's law, solve for the current. However, the voltage drop across the resistor is way too small for the ADC on the Arduino to read. For example, if we had 1 amp of current flowing through the 0.01Ω resistor we would only get a voltage drop of:
V = IR = 1 × 0.01 = 0.01V
This value is of course, way too small for the Arduino ADC to reliably read. I tried using higher values of resistors for the shunt, however, the added resistance would often have an undesired loading effect on the rest of the circuit. I eventually decided that the resistance would need to be lower than 0.1Ω.
This meant I needed to amplify the signal to a level the Arduino’s ADC can read. For this, I originally opted for a simple operational amplifier (Op-amp) in the Non-Inverting configuration. After building the circuit using the LM358 operational amplifier I quickly learned that my choice of op-amp was incorrect as the LM358 had difficulty amplifying the tiny voltage drop in a stable and consistent manner.
To rectify this, I needed what is known as an instrumentation op-amp. I came across an all-inclusive module that could easily measure the voltage and current in one unit.
The INA219 Voltage and Current Sensor
This module made by Adafruit Industries and sold by Core Electronics. It is an all-in-one module which can measure both the voltage and the current at the same time, all with awesome accuracy making it perfect for this project.
The module has a 12bit ADC compared to the ATmega328’s 10bit, meaning the resolution is significantly higher, thus making the module four times more accurate compared to using the Arduino alone.
It has a maximum voltage input of 32V meaning it is fine to work with our 25V supply. It also uses the I2C protocol which means it only needs 2 communication lines again adding to the simplicity of the project.
All this combined with the amazing library from Adafruit makes this sensor a perfect choice for this project.
CAUTION: It is very important that you do not program the Arduino while it is attached to the circuit. Doing so can cause the LM7805 voltage regulator to malfunction which could destroy the LM7805, Arduino, INA219 and even the boost buck converter.
This is because at no point should the linear voltage regulator have a higher voltage on it's output than it does it's input. Either program the Arduino before building the circuit or remove it for programming.
The Fundamental Build:
With all the theory and planning done, and components on-hand, I made the following prototype to ensure that everything was capable of playing nicely together.
|Parts Required:||Jaycar||Altronics||Core Electronics|
|1 × 830 Tie Point Breadboard||PB8815||P1009A||CE00304|
|1 × Arduino Nano or Compatible Board||XC4414||Z6372||CE05101|
|1 × Nokia 5110 LCD||XC4616||Z6348||LCD-10168|
|2 × 100nF Monolythic Capacitor||RC5360||R2865||CE05188|
|2 × 100μf 50V Electrolytic Capacitors||RE6150||R4827||CE05258|
|1 × 7805 Voltage Regulator||ZV1505||Z0505||CE05291|
|1 × INA219 Current Sense Module||-||-||ADA904|
|4 × 10k ¼W Resistors||RR0596*||R7582*||COM-08374*|
|1 x 1k 1/4W Resistor||RR0572||R7558||PRT-14492|
|1 × 330Ω ¼W Resistor||RR0560*||R7546*||PRT-14490*|
You’ll also need a breadboard and prototyping hardware. * Quantity shown, may be sold in packs.
Prototyping the electronics was a fairly time-consuming process. I realised at several points I was making incorrect decisions such as the incorrect choice of operational amplifier etc. This is of course why we prototype, however, despite the setback I was able to successfully build the entire design on a breadboard and make the adjustments to the circuit to achieve the desired functionality.
After building the circuit on the breadboard I tested the operation of the circuit. Using a multimeter, I discovered it was very accurate thanks to the 12bit ADC. I did notice however my module was a few milliamps out when I was testing, by calculating the expected current from known resistance and voltages. This could be a result of resistance in the wire/breadboard, or even tolerances on the resistors themselves. In either case, the error was very small and had no significant impact on the overall usefulness of the device.
Wiring the LCD
To connect the LCD you need to connect and solder:
|LCD PIN||DIGITAL PIN|
|CLK / SCLK||4|
|MOSI / DIN / DN||5|
|CS / CE / SCE||8|
|LED / Light||330Ω Resistor to GND|
|GND||GND on Arduino|
The Nokia 5110 LCD was designed to work on a 3.3V system. Whilst it is generally “ok” to operate the device using the data lines at 5V, it is recommended to use limiting resistors or a voltage divider. For this project I used limiting resistors on the following pins:
|CLK / SCLK||10KΩ|
|MOSI / DIN / DN||10KΩ|
|CS / CE / SCE||1KΩ|
The image above shows the connection of the circuit to the Arduino for my circuit. Extreme care should be taken to ensure the connections are correct. I have noticed that some of the LCDs you get from Jaycar, Altronics and Core Electronics do not share the same pinout, meaning your connections may not be the same. Therefore, use the provided images as a guide and follow the pinout for your individual LCD as marked on the PCB silkscreen or accompanying datasheet, which will be provided by the distributor.
Wiring the INA219 and Boost Buck Converter
The INA219 high side current sensor is an I2C device using only 2 communication lines. As such it is connected to the Arduino as follows.
|SDA||Analog Pin 4|
|SCL||Analog Pin 5|
The positive output from the Boost Buck Converter connects to Vin+ and the negative/0V of the Boost Buck connected to GND, or ground of the entire circuit. Vin from the INA219 is connected to the positive banana jack which then goes to the breadboard rails. The black banana jack is connected to the common ground/GND connection.
Here’s an image of my very early prototype, showing the current shunt and voltage divider along with the original concept for an enclosure.
As you can see, the early draft prototype bears little resemblance to the final product. I originally designed the enclosure as an elongated triangle to minimize the amount of support material I would need when printing the item. It was however not very visually appealing and certainly wasn’t ergonomic.
It did give me a significant understanding of the volume of enclosure I needed to house the electronics for the project. It also gave me some ideas for how the overall feel of the device should be, which gave me some food for thought when I revisited the design. The final design for the enclosure adopted the same angular shape again as a way to minimise the support material, but also as a way to allow for easy viewing of the LCD. It easily fits any of the standard 830 tie point breadboards I had on hand with the removal of the locating slots.
The Main Build:
Complete Power Supply
Complete Power Supply
Whilst the breadboard is fine for prototyping, the connections are not anywhere near reliable enough to provide consistent results in real-world application. We need to build a complete unit on a PCB. I will now run you through how I went from my prototype into a full build.
|ADDITIONAL Parts Required:||Jaycar||Altronics||Core Electronics|
|2 × 50mm × 70mm PCB protoboard||HP9550^||-||FIT0099^|
|1 × Red Banana Jack||PSO406||P9238||ADA3691|
|1 × Black Banana Jack||PSO408||P9240||ADA3691|
|1 x Rocker Switch||SK0984||S3210||-|
|1 x 2.5mm DC Input Jack||PS0524||P0623||-|
|3 × Screw Terminals||HM3172||P2032B||POLOLU-2442|
|2 × 10k Potentiometer||RP8510||R2225||ADA562|
|2 × Potentiometer Knobs||HK7707||H6024||ADA2047|
|1 × Female Pin Header Strip||HM3230||P5390||PRT-00115|
|1 × Male Pin Header Strip||HM3211||P5430||POLOLU-965|
^ Protoboard will need be be cut down to suit.
Modify the Buck Boost Converter
Firstly, you need to carefully remove the LEDs from the Buck Boost Converter and extend the wiring so that they can reach the holes in the front of the case. These LEDs allow the user to know at a glance if the system is in Constant Voltage or Constant Current mode. Be sure to record/recall the polarity of the LEDs so that you can correctly reconnect them in the next steps. I used solder braid and a medium – hot iron to remove the parts. Extreme care needs to be taken as it is very easy to lift the solder pads on this device.
After removing the LEDs, I recommend soldering, in their place, the male pin headers so that you can easily reconnect them after extending the wires.
Once the LEDs have been removed and extended you need to remove the potentiometers. Again, take your time and carefully remove the solder with solder braid being sure not to overheat and lift the pads.
Like with the LEDs, I recommend soldering male pin headers, in their place, so that you can connect and disconnect the wires later if needed.
If like me you accidentally lifted a solder pad you can try to remove some solder mask from the surviving trace and reconnect it.
After removing the LEDs and the potentiometers from the PCB you are going to need to extend the wiring so that the wires can comfortably reach the new locations in the enclosure. I recommend soldering a low-value resistor (~20Ω or so) in series with the middle pin of each potentiometer. This reduces the chance of a short circuit when you turn the potentiometer all the way to either extreme. Whilst it may not be 100% necessary, it is just a precaution.
Building the PCB
While a purpose designed and etched PCB would be an elegant solution, I chose to use two 50mm × 70mm protoboard PCBs I had available. This does mean a lot of soldering is required, and thick solder traces will reduce the resistance and help improve the accuracy. The following image shows the main PCB for the device. This side connects the Buck Boost converter, sensor and 5V supply regulator together and is the high current side.
Note: Make the solder traces thick in this section to improve the current handling, but ensure you don’t cause any short circuits.
3D Printed Enclosure
I always like to design and print my own enclosures for a complete project. You will be able to download the file in the digital resources so you can print your own.
The internal support material for the bottom edge of the LCD window collapsed while I was printing, however, the print was able to rectify itself enough for the print to survive. That support material and the top lip of the breadboard slot is all that is needed when printing in this orientation.
Note the enclosure has since been modified to rectify a few design flaws. I have thickened the sides of the breadboard holder as it was quite fragile when removing the support material. I also added a bit more internal rounding in this area to again strengthen it. The holes for the LEDs have been changed to accept the 3mm LED’s which come with the board so that purchasing a holder and 5mm varieties are no longer necessary.
Installing the PCB
Once all of the connections have been made it’s just a matter of squeezing it all into the case. As can be seen in the image below this device was a bit of a spaghetti soup at this point, Care will be taken in the final product to make this a little less chaotic and significantly tidier. The number one priority here is to make sure all connections are good and all joints are insulated with heatshrink to ensure no accidental shorts.
In this case, the Arduino is only used to essentially read the data from the sensor and display it on the Nokia LCD. The code is fairly simple and lightweight. A copy of the sketch will be included for anyone wishing to create this project themselves.
Two libraries need to be installed for the device to function. The first is the LCD5110_Graph.h. This library can be downloaded at Rinky Dink Electronics: http://www.rinkydinkelectronics.com/library.php?id=48
This is by far my favourite Nokia 5110 LCD library. It has a very simple look and is remarkably easy to use.
The second Library is the Adafruit_INA219.h. You can download this library from: https://github.com/adafruit/Adafruit_INA219/blob/master/Adafruit_INA219.h
Like the LCD library, this is a very simple to use library and is highly recommended.
Initialising the Arduino
We first include the libraries, define the hardware connections and then create the software variables.
LCD5110 myGLCD(4, 5, 6, 7, 8);// SCLK / clk =d4, MOSI / din =d5, DC =d6, RST =d7, CS / CE =d8,
extern uint8_t SmallFont;
extern uint8_t MediumNumbers;
int count = 0;
float shuntvoltage = 0;
float busvoltage = 0;
int current_mA = 0;
float loadvoltage = 0;
Here we simply display a “splash screen” or title screen before setting the specific requirements of the INA219. i.e. setting the calibration to 32V max input, 1A output etc.
By default, the sensor is calibrated to 32V max input and 2A output. Setting it to the 1A range gives us significantly higher precision on the current display.
The main loop is just as simple and compact as the rest of the code.
On every loop of the program we call a class provided by the Adafruit library to do the following:
- Measure the voltage drop across the Shunt resistor
- Measure the voltage at the high side of the load
- Calculate the Current in mA
- Calculate the voltage at the load
From there we increment a counter and check to see if the counter value is greater than 100. If the counter is higher than 100 the program will display the measured values from the sensor.
This prevents the display from constantly updating and producing a flicker or jumping numbers. This refresh rate can be changed to suit your specific needs.
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
loadvoltage = busvoltage +
(shuntvoltage / 1000);
if (count > 100) // This value reduces the
// flicker on the LCD by changing the refresh rate // a lower number = faster refresh
myGLCD.drawLine(0, 9, 84, 9);
myGLCD.drawLine(0, 47, 84, 47);
count = 0;
To test the performance of the device I opted to verify its accuracy against a standard multimeter with a 0.1% accuracy, and to measure the output ripple of the device at varying loads. Both will give a clear idea of how useful the device is as a tool.
To test for the accuracy of the device I will set the device to output a voltage from 2V to 15V incrementing every 1V, recording the displayed voltage. I will then use a multimeter to record the “actual” voltage and then calculate the percentage of error for each range. This will provide an idea of how accurate the device is in voltage measurements. Of course, the accuracy of this test relies on the accuracy of the multimeter. In this case, I used a UNI-T UT120C digital multimeter. Note that these tests will be conducted under load with a 200mA current draw, and be powered by a 12V input.
As can be seen in the following table, the device performs reasonably well with a slightly higher error percentage in the lower voltage output.
|Displayed Voltage||MEASURED VOLTAGE||MARGIN OF ERROR|
This test will comprise of recording the displayed value and comparing against a value found using the multimeter. This will give a rough example of accuracy. Again, as previously this calculation also depends on the error % from the multimeter used. In this case, I used a UNI-T UT804 Benchtop Digital Multimeter, as the previous meter was only fused for 400mA.
|DISPLAYED CURRENT||MEASURED CURRENT||ERROR %|
I was quite surprised by this level of inaccuracy, which could suggest something was faulty as all devices have a significantly higher rated accuracy. The Adafruit sensor has a reported accuracy of 1% and the multimeters used have +/-0.1% for the UT804, and +/-0.8% for the UT120C. I will have to test with another sensor when time permits.
Output ripple is an undesired result of switchmode voltage regulators which rapidly switch on and off a voltage supply. This results in a pulsating DC square wave signal which is smoothed with capacitors and inductors to create a stable DC (ish) supply.
Once you apply a load to the circuit this switching ripple becomes obvious once more. To test this, I will use an oscilloscope to measure the ripple as I increase the load on the circuit with an electronic/simulated load this will be done in both buck and boost configuration. I will then record the input voltage and current, the output voltage and current and the ripple and graph the results.
To test the ripple in buck mode I will supply the device with 12V and have it provide a stepped down 5V output to the electronic load, which I will increase from 200mA to 1A in 100mA increments.
The graph shows the results of this testing. It indicates at half an amp of current draw on the device the output ripple can be as much as 400mV. Whilst this isn’t ideal for sensitive electronics, it is sufficient for this device.
Below is a recorded waveform showing the ripple from the device when a 500mA load was applied.
This time I will repeat the same experiment with the only difference being that the input voltage to the device will be 7V and the output will be a stepped-up 14V. I will still increase the load current by 100mA from 200mA to 1A and record the results in a graph.
The scope output showing the ripple in Boost mode with 500mA of current applied. This level of ripple would render the supply useless without added filtering.
Like with the previous test it became clear that the device had a significant ripple, albeit significantly worse in boost mode than in buck mode. In boost mode at 500mA current, the device has 800mV of output ripple.
Whilst the results of these tests have shown less than remarkable performance, most notably in regard to the output ripple, the device is still more than sufficient for hobbyists and students involved with basic electronics. Moreover, it is still a very useful device for people involved with sensitive electronics provided they are aware of the ripple and take steps to mitigate it.
By placing a large capacitor across the supply much of the ripple can be reduced. For example, in Boost mode with a 500mA load and with a 1000uF capacitor across the output the ripple drops to about 60mV which is perfectly acceptable as seen in the image below.
The scope output showing the ripple in Boost mode with 500mA of current applied and with a 1000uF capacitor across the output.
So, it is highly recommended that you add filter/tank capacitors to your project when building a prototype using this supply to mitigate the increasing ripple with increased loads.
Optimum Input Voltages
After conducting the previous tests, it has become apparent that the optimum input to this supply would be around 12V to 20VDC with a maximum capacity of 2 amps. This is a very standard range which would include the wall power packs for many things from old routers to laptop chargers. Meaning the means to power the device should be easy and inexpensive to obtain.
Where to from here?
There are a few modifications to this project that could be considered. You could remove the Arduino development board and simply use the ATmega328P in its place reducing greatly the cost of the project.
That would of course then require a 3.3V regulator to be added so that the Nokia 5110 LCD could be powered, however, that is of no significant issue.
The case has been designed to allow for wires to be run under the protoboard so that they could be soldered directly to the protoboard rails for a neater appearance. However, you will need to have a protoboard that you can solder directly to.
The two 10K potentiometers I used are single turn, which makes it quite a bit more difficult to make small adjustments to the values. You could consider swapping them for 10-turn pots to give the device a much more precise way to set the desired voltage.
Another potential upgrade would be to design the switchmode regulator circuit itself, the Texas Instruments range of switchmode regulators called “simple Switchers” are fairly easy to use devices.
It would, however, require to also design the accompanying PCB which would certainly be a nice way to fully encapsulate all of the required possible future upgrades.
When you’re purchasing the module make sure it is similar to this one. It is easily identifiable by the 2 potentiometers.