# Problem with lcd display

Status
Not open for further replies.

#### Enzy

I'm using an arduino to read battery voltage I added an lcd display, when I plug it in it comes up and shows battery voltage and then in a second or 2 it flashes off and shows some weird writing.

Does anyone know what could cause that.

- - - Updated - - -

#### Attachments

• IMG_20161211_145939815.jpg
414.5 KB · Views: 34

#### Aussie Susan

If you are getting anything on the display then the 'setup' step is working correctly.
Therefore I'd look at your 'loop' code.
However without seeing it, I can only guess.
Susan

#### Enzy

If you are getting anything on the display then the 'setup' step is working correctly.
Therefore I'd look at your 'loop' code.
However without seeing it, I can only guess.
Susan

well im no pro for sure
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0; // resistance of R1 (100K) -see text!
float R2 = 10000.0; // resistance of R2 (10K) - see text!
int value = 0;
int battery = 8; // pin controlling relayA
int buzzer =7;
void setup(){
pinMode(battery, OUTPUT);
pinMode(buzzer, OUTPUT);
lcd.begin(16, 2);
lcd.print("Battery Voltage");
}
void loop(){
vout = (value * 5.0) / 1024.0; // see text
vin = vout / (R2/(R1+R2));
if (vin<0.09){
vin=0.0;//statement to quash undesired reading !
}
if (vin<10.6) {
digitalWrite(battery, LOW);
}
else {
digitalWrite(battery, HIGH);
}
if (vin>14.4) {
digitalWrite(battery, LOW);
}
else {
digitalWrite(battery, HIGH);
}
if (vin<10.9) {
digitalWrite(buzzer, HIGH);
}
else {
digitalWrite(buzzer, LOW);}
lcd.setCursor(0, 1);
lcd.print("INPUT V= ");
lcd.print(vin);
delay(500);}

Last edited by a moderator:

#### andre_luis

##### Super Moderator
Staff member
Does it make sense ?

if (vin<10.6) {
digitalWrite(battery, LOW);
}
else {
digitalWrite(battery, HIGH);
}
if (vin>14.4) {
digitalWrite(battery, LOW);
}
else {
digitalWrite(battery, HIGH);
}

The assignments in highlight are both conflicting.

#### Enzy

Yup it makes sense, even if it didn't make sense would that stop the screen from displaying correctly?

- - - Updated - - -

I made it up not saying it's correct, but if that battery is low 10.6 or lower it low send a low signal to the specific pin and if it's higher than normal operating voltage it will also send a long signal to that same pin, once voltages are in between both thresholds then the pin will be high.

Check the Arduino library help for the lcd.print function.

Printing of float values does not seem to be a valid option as far as I can tell

#### c_mitra

well im no pro for sure

1, remove everything and just try to get lcd.print("INPUT V= ") correctly.

2, Check you definition of int battery and also int buzzer (I guess your buzzer is also not working)

3, Which pins are set for input and which one is set for output?

#### Enzy

I removed everything to just print battery voltage and it worked just fine and as soon as I added the rest the same thing happened again so I guess something is wrong with the coding, I'm teaching myself as I go so based on my wording it looks good to me.

- - - Updated - - -

Actually the 14.4v battery voltage else statement was the problem I guess it conflicts with the previous else statement for the low battery voltage.

I take back the statement that I made in post 6.... lcd.print of a float does seem to work OK despite no mention in the library help

I have tried your sketch above on an Arduino Uno R3 and the LCD seems to display steady characters for me. The only change I made was to change LCD connections to suite my LCD shield.

Because your sketch seems to work OK for me, then the next thing I might suspect is the mess of wiring on your breadboard. Perhaps your wiring is picking up interference or dropping too much power somewhere? Can only guess....

EDIT: Seems that you have solved the issue... Great stuff

Last edited:

#### Enzy

I take back the statement that I made in post 6.... lcd.print of a float does seem to work OK despite no mention in the library help

I have tried your sketch above on an Arduino Uno R3 and the LCD seems to display steady characters for me. The only change I made was to change LCD connections to suite my LCD shield.

Because your sketch seems to work OK for me, then the next thing I might suspect is the mess of wiring on your breadboard. Perhaps your wiring is picking up interference or dropping too much power somewhere? Can only guess....

- - - Updated - - -

Also I made a big error, the lcd pins are connected to pin 8 and pin 7 and that's what I set my outputs to be also, so I switched them to pins 2 and 3 and is now testing the circuit, I am not getting accurate enough vtage reading I am guessing that's because of the resistors not being exact.

Status
Not open for further replies.