Arduino Smart power supply, dual output, safety features

 

A smart power supply built from a computer power supply. Uses a microcontroller to control the output voltage. Consist of dual output and dual measurement metres. Just with 3 button turn on the power supply, switch the output power, hold and release the output power. With its safety features that allow you to hold the power so you can adjust the output power makes this power supply a better option between other DIY power supplies. Measure current, and volt for two different output. Two USB output for USB charging and USB power usage.

Circuit diagram:

 

Parts list:

#DescriptionsQuantityCost/unitLink
15V 4-Channel Relay Board Module 3$8
2Computer ATX power suply130
3Banana Female connectors46
4LEDs31
5Resistor 470 ohms11
6Dual LED Digital DC 100V 10A Voltmeter Ammeter Voltage Amps Power Meter212
7Push buttons33
8Arduino nano board18
9Pot Potentiometer 10K43
10DC-DC 9A Step Down Buck Converter Module Power Supply 300W210
11USB Type A Female Socket Breakout Board 2.54mm25
12Wires multiple lengths and strength. 1
13Enclosure box
14screw, nut and bolts

 

Arduino code:

//Attach OneButton.h library for one button performs 3 functions
#include "OneButton.h"

OneButton button1(A2, false);// Set A2 pin to SW0 power supply on and off, holding and relasing power of power supplies.
const int switchPin = A1; // Set A1 pin to SW1, switch the powers on right hand power supply, or power supply #1
const int tactailPin = A0; //Set A0 pin to SW2, switch the powers on left hand power supply, or power supply #2
//Setting output on power supply #1
const int VpSupply = 4; // Pin 4 set to Variable output 1V to 12V
const int threeVsupply = 5; // Set pin 5 to 3V output
const int fiveVsupply = 6; // Set pin 6 to 5V output
const int twelveVsupply = 7; // Set pin 7 to 12V output

//Setting output on power supply #2
const int VpSupplyL = 8; // Pin 4 set to Variable output 1V to 12V @ Power supply#2
const int threeVsupplyL = 9; // Set pin 5 to 3V output @ Power supply#2
const int fiveVsupplyL = 10; // Set pin 6 to 5V output @ Power supply#2
const int twelveVsupplyL = 11; // Set pin 7 to 12V output @ Power supply#2

bool j = true;
bool s = true;
bool d = true;
bool flag1 = false;
bool flag2 = false;
bool flag3 = false;
int pressed = 0;
int pushed = 0;
// setup that run once:
void setup() {
Serial.begin(9600);
// Setting up pin mode for button1 for pin A2
pinMode(12, OUTPUT); // Set pin 12 as output
pinMode(2, OUTPUT); // Set pin 2 as output
pinMode(3, OUTPUT); // Set pin 3 as output

//Setting up digitalWrite mode for button1 for pin A2 SW0 button
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(12, HIGH);

//Setting up switchPin/SW1 as input in power supply #1
pinMode(switchPin, INPUT);

//Setting up pin mode for power supply #1 pins
pinMode(VpSupply, OUTPUT); //Set VpSupply as output as linked to pin 4
pinMode(threeVsupply, OUTPUT);//Set 3vSupply as output as linked to pin 5
pinMode(fiveVsupply, OUTPUT);//Set 5vSupply as output as linked to pin 6
pinMode(twelveVsupply, OUTPUT);//Set 12vSupply as output as linked to pin 7

//Setting up digitalWrite mode for power supply #1 pins
digitalWrite(VpSupply, HIGH);
digitalWrite(threeVsupply, HIGH);
digitalWrite(fiveVsupply, HIGH);
digitalWrite(twelveVsupply, HIGH);

//Setting up tactailPin/SW2 as input in power supply #2
pinMode(tactailPin, INPUT);

//Setting up pin mode for power supply #2 pins
pinMode(VpSupplyL, OUTPUT);
pinMode(threeVsupplyL, OUTPUT);
pinMode(fiveVsupplyL, OUTPUT);
pinMode(twelveVsupplyL, OUTPUT);

//Setting up digitalWrite mode for power supply #2 pins
digitalWrite(VpSupplyL, HIGH);
digitalWrite(threeVsupplyL, HIGH);
digitalWrite(fiveVsupplyL, HIGH);
digitalWrite(twelveVsupplyL, HIGH);

while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Starting Buttons...");

// link the button 1 functions.
button1.attachClick(click1);
button1.attachDoubleClick(doubleclick1);
button1.attachLongPressStart(longPressStart1);


} // setup

// ----- button 1 callback functions

// This function will be called when the button1 was pressed 1 time (and no 2. button press followed).To hold and release the power
void click1() {
if (flag3 == true) { //flag3 only true when long pressed active
Serial.println("Button1 SW0 clicked to release and hold the power.");
// reverse the button status
d = !d;
digitalWrite(3, d); // Release and hold the output power, on each click the status revers
}
} // click1


// This function will be called when the button1 was pressed 2 times in a short timeframe. To hold and release the power
void doubleclick1() {
if (flag3 == true) { //flag3 only true when long pressed active
Serial.println("Button1 SW0 clicked to release and hold the power.");
// reverse button status each time button pressed 
s = !s;
digitalWrite(12, s); // Release and hold the output power, on each click the status revers
}
} // doubleclick1


// This function will be called once, when the button1 is pressed for a long time. turns on the power supply and turns off the power supply.
void longPressStart1() {
Serial.println("Button 1 longPress to on/off power supply");
flag3 = !flag3; //made flag 3 true so all buttons work properly
j = !j;
digitalWrite(2, j); // Long press will turns on and turns off the power supply, it will hold the pin 3 and pin 12 unless pin 2 is high. 
if (j == true) {
s = true;
d = true;
digitalWrite(3, s);
digitalWrite(12, d);
}
} // longPressStart1

// main code here, to run repeatedly:
void loop() {
// keep watching the push buttons:
button1.tick();
////////////////////////////////////////////////////
if (digitalRead(switchPin) == HIGH && flag3 == true) { //check switch button and flag3 condition, flag3 only true when long pressed active
Serial.println("switching power supply");
flag1 = true;
pressed++; //increament in pressed with every time Switch button pressed
delay(200);
}
if (pressed == 1 && flag1 == true) //flag1 only true when switch button is pressed
{
flag1 = false; //it made flag1 false so it runs only one time
//First click/press will make VpSupply on/low and the rest of the pins are high/off
digitalWrite(VpSupplyL, LOW);
digitalWrite(threeVsupplyL, HIGH);
digitalWrite(fiveVsupplyL, HIGH);
digitalWrite(twelveVsupplyL, HIGH);
}
if (pressed == 2 && flag1 == true) //flag1 only true when switch button is pressed
{
flag1 = false; //it made flag1 false so it runs only one time
//Second click/press on switch will make 3vSupplyL on/low after a second and the rest of the pins are high/off
digitalWrite(VpSupplyL, HIGH);
delay(1000);
digitalWrite(threeVsupplyL, LOW);
digitalWrite(fiveVsupplyL, HIGH);
digitalWrite(twelveVsupplyL, HIGH);
}
if (pressed == 3 && flag1 == true)
{
flag1 = false; //it made flag1 false so it runs only one time
//Third click/press on switch will make 5vSupplyL on/low after a second and the rest of the pins are high/off
digitalWrite(VpSupply, HIGH);
digitalWrite(threeVsupplyL, HIGH);
delay(1000);
digitalWrite(fiveVsupplyL, LOW);
digitalWrite(twelveVsupplyL, HIGH);
}
if (pressed == 4 && flag1 == true) //flag1 only true when switch button is pressed
{
flag1 = false; //it made flag1 false so it runs only one time
//Forth click/press on switch will make 12vSupplyL on/low after a second and the rest of the pins are high/off
digitalWrite(VpSupplyL, HIGH);
digitalWrite(threeVsupplyL, HIGH);
digitalWrite(fiveVsupplyL, HIGH);
delay(1000);
digitalWrite(twelveVsupplyL, LOW);
}
if (pressed == 5 && flag1 == true) //flag1 only true when switch button is pressed
{
flag1 = false; //it made flag1 false so it runs only one time
//Fifth click/press on switch will turn off/High all pins on power supply#2
digitalWrite(VpSupplyL, HIGH);
digitalWrite(threeVsupplyL, HIGH);
digitalWrite(fiveVsupplyL, HIGH);
digitalWrite(twelveVsupplyL, HIGH);
pressed = 0;
}
/////////////////////////////////////////////////////
if (digitalRead(tactailPin) == HIGH && flag3 == true) { //check tactail button and flag3 condition, flag3 only true when long pressed active
Serial.println("Tactail Button pressed for switching output power");
flag2 = true;
pushed++; //increament in pushed with every time tactail button pressed
delay(200);
}
if (pushed == 1 && flag2 == true) //flag2 only true when switch button is pressed
{
flag2 = false;
digitalWrite(VpSupply, LOW);
digitalWrite(threeVsupply, HIGH);
digitalWrite(fiveVsupply, HIGH);
digitalWrite(twelveVsupply, HIGH);
}
if (pushed == 2 && flag2 == true) //flag2 only true when switch button is pressed
{
flag2 = false; //it made flag2 false so it runs only one time
digitalWrite(VpSupply, HIGH);
delay(1000);
digitalWrite(threeVsupply, LOW);
digitalWrite(fiveVsupply, HIGH);
digitalWrite(twelveVsupply, HIGH);
}
if (pushed == 3 && flag2 == true) //flag2 only true when switch button is pressed
{
flag2 = false; //it made flag2 false so it runs only one time
digitalWrite(VpSupply, HIGH);
digitalWrite(threeVsupply, HIGH);
delay(1000);
digitalWrite(fiveVsupply, LOW);
digitalWrite(twelveVsupply, HIGH);
}
if (pushed == 4 && flag2 == true) //flag2 only true when switch button is pressed
{
flag2 = false; //it made flag2 false so it runs only one time
digitalWrite(VpSupply, HIGH);
digitalWrite(threeVsupply, HIGH);
digitalWrite(fiveVsupply, HIGH);
delay(1000);
digitalWrite(twelveVsupply, LOW);
}
if (pushed == 5 && flag2 == true) //flag2 only true when switch button is pressed
{
flag2 = false; //it made flag2 false so it runs only one time
digitalWrite(VpSupply, HIGH);
digitalWrite(threeVsupply, HIGH);
digitalWrite(fiveVsupply, HIGH);
digitalWrite(twelveVsupply, HIGH);
pushed = 0;
}

delay(10);
} // loop

 

 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.