PDA

View Full Version : Arduino powered voltage display



SXRguyinMA
12-05-2010, 04:37 PM
Ok, I'm trying to make my Arduino display voltages for 12v, 5v and 3v lines. I've got a 16x2 LCD.

First, is it possible to get all 3 displayed at once? As in the top line being "3.3V 5V 12V" spaced evenly, then the bottom line being the 3 readings. I know they won't update all at the same time, but that's no big deal.

Second, if it's not possible, how do I need to set it up so when the unit is turned on it displays a welcome message, then with each button press it switches between 3v, 5v and 12v?

Here's my code so far for the second setup (with only 3v and 5v for now, still have to figure out how to read 12v without frying something):


/*Arduino Controlled Voltage Monitor
Code by Will Lyon 12/5/2010
Code for project Power House on TBCS
http://www.thebestcasescenario.com*/

#include <LiquidCrystal.h>
#include <math.h>
int counter = 0; //Add counter
int buttonPin = 2; //Attach button to pin 2

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
pinMode(buttonPin, INPUT); //Set button pin to input
lcd.begin(16, 2); //Set up the LCD's number of columns and rows
lcd.print(" POWER HOUSE");
lcd.setCursor(0, 1);
lcd.print("Desktop Pwr Unit");
}

void loop()
{
digitalRead(buttonPin); //Read the button pin
if (buttonPin = HIGH) //If the button is pressed
{
counter + 1; //Advance to next mode
if(counter == 2) //Reset count if over max mode number
{
counter = 1;
}
}
if(counter == 1)
{
lcd.print("3.3 Volt Line");
lcd.setCursor(0, 1);
lcd.print(analogRead(2));
}
else if(counter == 2)
{
lcd.print("5 Volt Line");
lcd.setCursor(0, 1);
lcd.print(analogRead(0));
}
}It displays the opening message, but when the button is pressed nothing happens.

Here is how it's wired up:
http://i92.photobucket.com/albums/l11/sportrider12584/Power%20House/powerhouse_bb.png


any ideas? Thanks!

SXRguyinMA
12-05-2010, 10:06 PM
ok with some help of the Arduino forums and references, this is the current code which works almost 100%



/*Arduino Controlled Voltage Monitor
Code by Will Lyon 12/5/2010
Code for project Power House on TBCS
http://www.thebestcasescenario.com*/

#include <LiquidCrystal.h>

//Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup()
{
lcd.begin(16, 2); //Set up the LCD's number of columns and rows
lcd.print(" POWER HOUSE"); //First line opening message
lcd.setCursor(0, 1);
lcd.print("Desktop Pwr Unit"); //Second line opening message
delay(5000);
lcd.setCursor(0, 1); //Clear bottom line
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print(" 3v 5v 12v"); //Update top line readout
}

void loop()
{
lcd.setCursor(0, 1);
float f = analogRead(0) * 4.9 / 1023; // 3.3 => 9.9
lcd.print(f, 2); // print float with one decimal

lcd.setCursor(6, 1);
f = analogRead(1) * 5.0 / 1023; // 5.0 => 9.9
lcd.print(f, 2);


lcd.setCursor(11, 1);
f = analogRead(2) * 12.0 / 1023; // 12.0 => 25.0
lcd.print(f, 2);

delay(1000);
}I need to find out why the 5v and 12v aren't reading properly. they're just sitting at 5.00 and 12.00 and don't change. if I change the coding (in the analogRead() ) sections for those two inputs, the value on the screen changes to whatever the multiplier is :?

the 3v line I had to set the multiplier to 4.9 so the display readout was the same as what my multimeter said the line has. as for the other two, my meter says 4.85b and 12.4v respectively., and the lcd says 5.00 and 12.00 :?

I'm also using a voltage divider on the 12v line so as to not fry the Arduino. Here's how that is set up:

12v---|51K|---+---|68K|---GND

The Arduino's analog pin is connected to the "+"

With this the sense pin is seeing 5.40v. Should I put a 10K to ground off the two analog pins for 5v and 12v?

SXRguyinMA
12-06-2010, 02:34 PM
Alright well I got it sorted. :banana:

here's the setup:
http://i92.photobucket.com/albums/l11/sportrider12584/Power%20House/powerhouse_bb-1.png

and the code:

/*Arduino Controlled Voltage Monitor
Code by Will Lyon 12/5/2010
Code for project Power House on TBCS
http://www.thebestcasescenario.com*/

#include <LiquidCrystal.h>

//Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup()
{
lcd.begin(16, 2); //Set up the LCD's number of columns and rows
lcd.print(" POWER HOUSE"); //First line opening message
lcd.setCursor(0, 1);
lcd.print("Desktop Pwr Unit"); //Second line opening message
delay(5000);
lcd.setCursor(0, 1); //Clear bottom line
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print(" 3v 5v 12v"); //Update top line readout
}

void loop()
{
lcd.setCursor(0, 1);
float f = analogRead(0) * 4.88 / 1023; // 3.3 => 9.9
lcd.print(f, 2); // print float with two decimals


lcd.setCursor(6, 1);
float g = analogRead(1) * 8.5 / 1023; // 5.0 => 9.9
lcd.print(g, 2);


lcd.setCursor(11, 1);
float h = analogRead(2) * 17.25 / 1023; // 12.0 => 25.0
lcd.print(h, 2);

delay(1000);
}

SXRguyinMA
12-06-2010, 02:42 PM
http://i92.photobucket.com/albums/l11/sportrider12584/Power%20House/SANY0639.jpg

http://i92.photobucket.com/albums/l11/sportrider12584/Power%20House/SANY0640.jpg

Oneslowz28
12-08-2010, 06:46 AM
How did I miss this? Nice work man! I will have to board this up one night!

SXRguyinMA
12-09-2010, 12:24 AM
here ya go CJ :devious: :D

:EDIT: had to fix the schematic for the LCD meter, will upload shortly

oh and don't forget Louverduino! (have one of these on the way already)

http://batchpcb.com/index.php/Products/47020

SXRguyinMA
12-10-2010, 09:05 PM
alright fixed it and its up :D

http://batchpcb.com/index.php/Products/48401

http://i92.photobucket.com/albums/l11/sportrider12584/Power%20House/pwrhse_board_rev1_1.png

Konrad
12-11-2010, 09:17 PM
Curious - what's the actual accuracy on this readout? Do you calibrate it with another meter? Or is extreme accuracy not really required for this application?

Also - why the arbitrary 1000(ms?) delay? What's the fastest update rate your part can support? (I don't think the Arduino board will be sucking big power or overheating, much, lol ...)

(I can see the x.xx digital resolution, and I suppose I can work out the fractional math, but higher precision does not in itself equal higher accuracy ... it all boils down to the limits for the Arduino/ADC and comparator/sensor parts ...)

SXRguyinMA
12-11-2010, 09:54 PM
I set the calibration in the coding according the my digital multimeter. it's within .01v of the multimeter's reading. The reason for the 1000ms delay is that it was originally set at 100ms, but the update on the LCD screen was way too fast, so the only reason I set it to 1000ms (1 second) was just for aesthetics mostly.

nop
01-05-2011, 11:11 AM
Alright well I got it sorted. :banana:

here's the setup:
(fritzing breadboard view)

Small request: could you post the schematic view from fritzing or other tools when posting circuit designs? The breadboard view is cool, but it's easier to see what's connected to what in the schematic than tracing connections on the breadboard or PCB. Took me a while to reverse-engineer the voltage dividers :-)

SXRguyinMA
01-05-2011, 11:40 AM
I sure can do that :up:

x88x
01-05-2011, 03:01 PM
Nice, I missed this.