78Views4Replies

Author Options:

Im repurposing my atx power supply to be a bench Psu. I need help with code please? Answered

In this project. I want to use an arduino mega, 2 lcds, and 6 acs712 current sensing modules and 2 Lm2596 dc step up/down module

The set up I have in mind is like so; arduino is powered by ATX stand by power (IF possible)
there is a push button which turns on the programing to start the monitoring and also grounds the ATX and GReen wire to supply power to all the rails.
This set up will calculate Voltage and current printting them on the lcd's.
The constant voltages will be printed on on lcd and the variable voltages on the other lcd.
Ive written most of the code. I just want it to make sense.


I've added a picture, which my project is based on.. the difference are, im not using I2c bus for lcd, im measuring current, and im printing info on two different lcds.

thanks for the help.

here is the code

#include <LiquidCrystal.h>
#define PWROK_PIN 4 // change to w.e pin i end up using connected to green? investigate
#define PWRBTN 2 // closing push buttom connection makes it high
#define PWRTRANS 6

/*-----( Declare objects )-----*/

// Variables will change:
int PWRSTATE = HIGH;         // the current state of the output pin
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers


// initialize the libr with the number of the intface pins

double sensePinVthree = A0;
double sensePinVfive = A1;
double sensePinVfivesb = A2;
double sensePinVtw = A3;
double sensePinVrone = A4;
double sensePinvrtwo = A5;
//The current
double sensePinIthree   = A6;
double sensePinIfive   = A7;
double sensePinIfivesb = A8;
double sensePinItw  = A9;
double sensePinIVrone = A10;
double sensePinIVrtwo = A11;
//setting up default or naming variables.
double Voltsthree;
double Voltsfive;
double Voltsfivesb;
double Voltstw;
double VoltsVrone;
double VoltsVrtwo;
double Currentthree;
double Currentfive;
double Currentfivesb;
double Currenttw;
double CurrentVrone;
double CurrentVrtwo;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LiquidCrystal lcd2(12, 10, 5, 4, 3, 2);


//remove this if not working or glitchy
void checkPowerOK(){   // when green is grounded
  if (digitalRead(PWROK_PIN) == HIGH) {
    lcd.setCursor(4, 1);
    lcd.print("ON ");
    lcd.setCursor(9, 3);
    lcd.print("hello");
  }
  else if (digitalRead(PWROK_PIN) == LOW) {
    lcd.setCursor(8,1);
    lcd.print("OFF");
  }
}
void togglePower(){
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
// If interrupts come faster than 200ms, assume it's a bounce and ignore
if (interrupt_time - last_interrupt_time > 500)
{
   // set the power:
  digitalWrite(PWRTRANS, PWRSTATE); //trans is pin 6
}
PWRSTATE = !PWRSTATE;
last_interrupt_time = interrupt_time; 
}


void setup() {
analogReference (DEFAULT);
pinMode(PWRBTN, INPUT);
pinMode(PWRTRANS, OUTPUT);
attachInterrupt(0, togglePower, RISING);
digitalWrite(PWRTRANS, PWRSTATE);

  lcd.begin(16, 4);
  lcd2.begin(16, 2);

// Print a message to the LCD.
lcd.setCursor(0,0); //take this out if monitor buggy
lcd.print("Bench PSU");// this code be fine
lcd.setCursor(0,1);
lcd.print("Monitor  V1.0");
lcd.setCursor(0,2);
lcd.print("ICE");
lcd.setCursor(4,3);
lcd.print("ROBOTICS");

lcd2.begin(16, 2); // replace with the date_time function
lcd2.setCursor(0,0);
lcd2.print("Hope 4 the best");
lcd2.setCursor(0, 1);
lcd2.print("prep 4 the worst");

delay(3000);


lcd.clear(); // wipes old message
lcd.setCursor(5,0); 
lcd.print("Building the Future");
lcd.setCursor(0,1);
lcd.print("since   2014");
//Inset the time function somewhere in here
lcd.clear();
lcd2.clear();
//lcd.createChar(0, blockChar);

  Voltsthree=0; //setting my variables to Zero
  Voltsfive=0;
  Voltsfivesb=0;
  Voltstw=0;

  Currentthree=0; //Setting current to Zero on this Lcd
  Currentfive=0;
  Currentfivesb=0;
  Currenttw=0;


  VoltsVrone=0; // doing the same but for second lcd
  VoltsVrtwo=0;

  CurrentVrone=0;// same for current
  CurrentVrtwo=0;
}
void loop ()
{checkPowerOK(); // check to see if power ok
  Voltsthree = ((analogRead(sensePinVthree)) /218.0) *5; // or 7 aalso the 218.0 value will chaange to mine specific
  if(Voltsthree <0){
    Voltsthree=0;
  }
  Currentthree =(((analogRead(sensePinIthree)) / 212.0) -2.55) / 0.6666667;// why 0.667
  if(Currentthree <0) {
    Currentthree=0;
  }
  Voltsfive = ((analogRead(sensePinVfive)) /218.0) *5;
  if(Voltsfive <0){
    Voltsfive=0);
  }
  Currentfive =(((analogRead(sensePinIfive)) / 212.0) -2.55) / 0.6666667;// why 0.667
  if(Currentfive <0) {
    Currentfive=0;
  }
  Voltsfivesb =((analogRead(sensePinVfivesb)) /218.0) *5;
  if(Voltsfivesb <0){
    Voltsfivesb=0;
  }
  Currentfivesb =(((analogRead(sensePinIfivesb)) / 212.0) -2.55) / 0.6666667;// why 0.667
  if(Currentfivesb <0) {
    Currentfivesb=0;
  }
  Voltstw =((analogRead(sensePinVtw)) /218.0) *5;
  if(Voltstw <0){
    Voltstw= 0;
  }
  Currenttw =((analogRead(sensePinItw)) / 212.0) -2.55) / 0.6666667;// why 0.667
  if(Currenttw <0){
    Currenttw=0;
  }

  VoltsVrone =((analogRead(sensePinVrone)) /218.0) *5;
  if(VoltsVrone <0){
    VoltsVrone=0;
  }
  CurrentVrone =(((analogRead(sensePinIVrone)) / 212.0) -2.55) / 0.6666667;// why 0.667
  if(CurrentVrone <0) {
    CurrentVrone=0;
  }

  VoltsVrtwo =((analogRead(sensePinVrtwo)) /218.0) *5;
  if(VoltsVrtwo <0){
    VoltsVrtwo = 0;
  }
  CurrentVrtwo =(((analogRead(sensePinIVrtwo)) / 212.0) -2.55) / 0.6666667;// why 0.667
  if(CurrentVrtwo <0) {
    CurrentVrtwo=0;
  }
  //1st line
  lcd.setCursor(0,0);
  lcd.print("                "); //clear the line 1st line
  lcd.setCursor(0,0);
  lcd.print(Voltsthree);
  lcd.setCursor(5,0):
  lcd.print("V");
  lcd.setCursor(7,0);
  lcd.print(Currentthree);
  lcd.setCursor(14,0);
  lcd.print("A");

  //2nd line
  lcd.setCursor(0,1);                  // clear and print second line
  lcd.print("                ");
  lcd.setCursor(0,1);
  lcd.print(Voltsfive);

  lcd.setCursor(5,1);
  lcd.print("V");
  lcd.setCursor(7,1);
  lcd.print(Currentfive);
  lcd.setCursor(14,1);
  lcd.print("A");

  //3rd line
  lcd.setCursor(0,2);           // clear line 3
  lcd.print("                ");
  lcd.setCursor(0,2);
  lcd.print(Voltsfivesb);

  lcd.setCursor(5,2);
  lcd.print("V");
  lcd.setCursor(7,2);
  lcd.print(Currentfivesb);
  lcd.setCursor(14,2);
  lcd.print("A");

  //4th line
  lcd.setCursor(0,3);           // clear line 4
  lcd.print("                ");
  lcd.setCursor(0,3);
  lcd.print(Voltstw);

  lcd.setCursor(5,3);
  lcd.print("V");
  lcd.setCursor(7,3);
  lcd.print(Currenttw);
  lcd.setCursor(14,3);
  lcd.print("A");

  //1st line
  lcd.setCursor(0,0);
  lcd.print("                "); //clear the line 1st line
  lcd.setCursor(0,0);
  lcd.print(VoltsVrone.);
  lcd.setCursor(5,0);
  lcd.print("V");
  lcd.setCursor(7,0);
  lcd.print(CurrentVrone);
  lcd.setCursor(14,0);
  lcd.print("A");

  //2nd line
  lcd2.setCursor(0,1);                   // clear and print second line
  lcd.print("                ");
  lcd.setCursor(0,1);
  lcd.print(VoltsVrtwo);

  lcd.setCursor(5,1);
  lcd.print("V");
  lcd.setCursor(7,1);
  lcd.print(CurrentVrtwo);
  lcd.setCursor(14,1);
  lcd.print("A");

}

Discussions

0
Downunder35m
Downunder35m

4 years ago

I might be a bit too old school but why is it that everyone needs to go overboard these day with Arduino and micro processors?
From what I understand all you want is to display voltage and current plus make some outputs adjustable using the modules !?
I would simply use two digital voltage LCD, one with a suitable shunt for the amp measurements as you display the voltage drop of the shunt.
No real need for fancy electronics unless you want to use the Arduino and PWM signals to regulate the step up/down modules.
So please correct me or provide more info if I got it wrong.

0
icey.hood
icey.hood

Answer 4 years ago

Now you're right everyone is going overboard. Not long ago i made a fume extractor thats powered by arduino nano. Its just i have plenty laying around.

And i could get the LCD with voltage and amp measuring capability however i already have the regular lcd 16,4. I'm a hobbyist, i like making complex things

0
steveastrouk
steveastrouk

Answer 4 years ago

Which is fine, if you can handle all the steps to make your project, but if you have to go out and ask for help, it gets kind of frustrating.

0
icey.hood
icey.hood

Answer 4 years ago

Doing things i know, isnt learning. I like picking projects that i can do with a degree of difficulty. I'm over complicating the program i believe.