Three voltage measurements + output to a LCD screen

Hi, here is some data on the screens that I have http://www.mostron.de/de/cob-character-type-module/nordrheinwestfalen/bueren/admin/files/pictures/610/610_1020_1221202107.pdf

I have the Arduino now :)... where shall I start?

Thanks :grin:

That screen doesn't speak rs232. Do you mean you have a serial pack for it?

Hi, I planned to use it in parallel mode if possible?

I am following this tutorial, I get back-light on the screen but nothing else at the moment :frowning:

dtokez:
Hi, I planned to use it in parallel mode if possible?

I am following this tutorial, I get back-light on the screen but nothing else at the moment :frowning:

Which tutorial? Show a picture of your connections. We don't have crystal balls.

Whoops.. forgot to put the link in sorry :roll_eyes:

http://tronixstuff.wordpress.com/2011/01/08/tutorial-arduino-and-monochrome-lcds/

Right, I have now followed a different tutorial... Arduino Tutorial - connecting a parallel LCD

And it works :slight_smile:

now do you think someone could advise me on the best way to get it reading voltages & displaying them?

One thing I have noticed is you have to hit the reset button to get it to run when you first power it up?

Thanks :stuck_out_tongue:

Not sure why you need to reset for it to run. Can you post your code?
Your question is two-fold: reading values and displaying them. You need to provide details of what you're reading with a spec sheet for each sensor. That is a starting point. Once reading value is good to go, then we'll talk about displaying them.

Hi Liudr,

Sure, this is the code (its from the arduino examples section)

/*
  LiquidCrystal Library - Hello World
 
 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the 
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.
 
 This sketch prints "Hello World!" to the LCD
 and shows the time.
 
  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 
 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe
 
 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */

// include the library code:
#include <LiquidCrystal.h>

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

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

I have just drawn up a quick schematic of what I hope to achieve and attached it to this post, please forgive the messy wiring I have not done many before :cold_sweat:

Basically, the connectors marked BMS & BCU are to allow connection from a wiring harness with two hall effect sensors installed (only one socket will be populated at a time). I want to measure 5 voltages. Four of which (v.ref1, v.ref2, v.out1 and v.out2) will be selected using switches, with two outputs. This will enable me to switch between each sensor on the loom.

On the LCD I would like to display the main supply voltage (5v) and either v.ref1 & v.out1, or v.ref2 & v.out2 (2.5v).

The higher the resolution the better really, but at least 0.00v.

Thanks for your time, I really appreciate it 8)

ISENSOR TESTER.pdf (17.2 KB)

Well I have just had another play, and reloaded the code. It now runs without having to reset :slight_smile:

Hi again :relaxed:

could someone help me modify this code to work without the dividers? the voltages that I plan to measure will be less than 5v.

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int analoginput = 0;
float vout = 0.0;
int value = 0;
float R1 = 1000.0;    // !! resistance of R1 !!
float R2 = 470.0;     // !! resistance of R2 !!
float vin = 0.0;

void setup(){
  
 // declaration of pin modes
 pinMode(analoginput, INPUT);
 lcd.begin(16, 2);
delay(100);
}



void loop(){
 // read the value on analog input
 value = analogRead(analoginput);
 vout= (value * 5.0)/1024.0;
 vin = vout / (R2/(R1+R2));
 
 
 lcd.setCursor(0,0);
 lcd.print("     ");
 lcd.setCursor(0,0);
 lcd.print(vin, 3);

 lcd.setCursor(11,0);
 lcd.print("Volts");
 
 
delay(1400);

}

right, I'm down to this now which is displaying OK but the readings are not sensible, any idea how I can get a true reading?

Thanks

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int analoginput = 0;
float vin = 0.0;


void setup(){
  
 // declaration of pin modes
 pinMode(analoginput, INPUT);
 lcd.begin(16, 2);
delay(100);
}



void loop(){
 // read the value on analog input
lcd.setCursor(0,0);
lcd.print ("Vin:");
vin = analogRead(analoginput)/200;
lcd.print(vin, 3);
lcd.setCursor(9,0);
lcd.print ("V");
 
delay(1400);

}

I read this thread pretty thoroughly but I might have missed an important bit.

First off there is no need to initialize an analog input unless you are going to use it as digital so this:

pinMode(analoginput, INPUT);

is unnecessary. Fortunately it doesn't do any harm. It initializes the serial Rx line to an input which it is anyway.

Then, this line:

vin = analogRead(analoginput)/200;

while giving approximately the right value should really be:

analogRead(analoginput)/1023*5.00;

unless you are trying to do some kind of scaling.

Would that give you sensible readings? You didn't say how they weren't sensible.

Hi,

thanks for the reply. What bits have I not made clear? Apologies, I am brand new to the arduino :slight_smile: When i was testing earlier the voltage readings didn't make sense - with an input voltage of 4v i think it was displaying 3.5v but if i dropped the voltage to 3v it would be sensible.

I have just edited the code following your advice, the display is now reading 0v and does not increase when I connect a voltage to the analog pin?

One odd thing I noticed is I pulled the usb cable and the arduino LED stayed on, this was because of the voltage I was inputting to analoge pin 0, (it was about 3v) is this normal behavior lol?

This is what I have now, am I missing something crucial?

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int analoginput = 0;
float vin = 0.0;


void setup(){
  
 // declaration of pin modes
 lcd.begin(16, 2);
delay(100);
}



void loop(){
 // read the value on analog input
lcd.setCursor(0,0);
lcd.print ("Vin:");
vin = analogRead(analoginput)/1023*5.00;
lcd.print(vin, 3);
lcd.setCursor(9,0);
lcd.print ("V");
 
delay(1400);

}

Thanks

just playing around and as soon as I divide the input by 1023 I get a static display of 0v :~

Whoops! I hate it when that happens. I haven't fetched my Arduino out of storage yet and it's been two years since I played with this stuff so I'm a little rusty. Let's pretend we're still in first grade and make sure all the data types match because I can't remember if you can mix floats and ints in an expression. If this works, then you can play with it and you'll have a working model to revert to. You'll have to tell me what happens because, as I said, I don't have anything to test the code on.

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int analoginput = A0;
int vin = 0;
float Voltage = 0.0;


void setup()
{
// declaration of pin modes
    lcd.begin(16, 2);
    delay(100);
}



void loop()
{

  vin = analogRead(analoginput);  //read the value on analog input A0
  
  lcd.setCursor(0,0);
  lcd.print("V(int): ");
  lcd.print("    ");              //clear out previous integer (4 spaces)
  lcd.setCursor(7,0);             //backspace
  lcd.print(vin);                 //print integer value of analog input
  lcd.println (" V");             //print units and advance to next line of display
  
  Voltage = float(vin);           //cast vin to float
  Voltage = Voltage/1023.0*5.0;   //scale to 5V full scale
  
  lcd.print("V(float): ");
  lcd.print("    ");             //clear out previous float
  lcd.setCursor(9,0);           //backspace
  lcd.print(Voltage,2);
  lcd.println(" V");



 
delay(1400);

}

Let me know what happens.

dtokez:
just playing around and as soon as I divide the input by 1023 I get a static display of 0v :~

Sorry I dropped the ball. I'm in a conference (arduino workshop two days from today and more on physics teaching!).

The reason you got zero was because you divided your reading by 1023. Both your analog reading and 1023 are integers so their division was handled as integer. Only quotient was reported, which is almost always 0, while the remainder is lost. Say you have 512 from analog input, you divide it by 1023. You get 0 as quotient and 512 as remainder but integer division only reports quotient, 0. Then any subsequent multiplication or division is zero.

You want to do this instead: result=analogRead(sensor)*5.00/1024;

The above way multiplies an integer (analogRead) with a float 5.00. The operation requires converting integer to float. Then the result is divided by an integer 1024, which also requires the integer be converted into floats. Dividing floats won't be as inaccurate as dividing integers so you will get the desired scaling effect you want. BTW, it should be 1024, although 1023 is almost as good. :wink:

Good catch liudr :), I knew it had something to do with mixing the data types. I couldn't remember what to do to get the compiler to cooperate, hence my suggestion to convert the input explicitly to a float.

That's right, there ARE 1024 steps.

Thanks guys :slight_smile: that worked a treat!

I have just edited it so it displays a second voltage on the second line of the screen 8)

when the inputs are not connected the float like crazy, is there a way to pull them down with software? I've just tried a 1m ohm resistor (all i found around) but I don't think that's enough resistance? For some reason it brings the voltage reading up to a shade under 5v, I can't get my head around why :~

Thanks

As far as I know you don't pull up or down an analog signal. You change the signal if you pull it to 5V.

when the inputs are not connected the float like crazy, is there a way to pull them down with software?

Sure. Just don't call analogRead().

I've just tried a 1m ohm resistor (all i found around) but I don't think that's enough resistance?

I think you mis-spelled "too much"