Voltmeter using float displayed on lcd, help.

Hi everyone, im having a problem when i tray to display a float on lcd.
Im displaying a float number with 1 decimal.
The problem is that after the decimal it shows 2 weird symbols
like this: 2.5@@ (@ = representing the weird symbols).

This is my code

#include <LiquidCrystal.h>
LiquidCrystal lcd(4, 5, 6, 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; //voltage coming out of the voltage divider
vin = vout / (R2/(R1+R2)); //voltage to display

lcd.setCursor(0,0);
lcd.println(vin, 1); //Print float “vin” with 1 decimal

lcd.setCursor(11,0);
lcd.print(“Volts”);

delay(1400);
}

Thanks everyone in advance!! :wink:

 lcd.print[glow]ln[/glow](vin, 1);

I would guess the two strange characters are a carriage return and a linefeed character. Try lcd.print instead.

Korman

Thanks a lot Korman!!! the weird symbols are gone :smiley:

Now im struggling with a decimal staying on the lcd.
When the value is higher than 10.0 the decimal shifts one spot to the right on the lcd, and when it goes lower than 10.0 shifts to the left, but the decimal of the number higher than 10.0 stays in there.

Right now I added an lcd.clear(); but the lcd flickers everytime it clears the lcd.

Maybe i need to get some sleep :smiley:

Here is the code with the mods

if(vin < 10);
{
lcd.clear();
}
lcd.setCursor(0,0);
lcd.print(vin, 1);

lcd.setCursor(11,0);
lcd.print(“Volts”);

delay(1400);
}

struggling with a decimal staying on the lcd

Instead of testing to see if temperature value is less than 10 and executing lcd.clear(), how about something like the following:


[color=#0000ff]Set cursor to (0,0)
Print five spaces.
Set cursor to (0,0)
Print the temperature value.[/color]

lcd flickers

You could further reduce the flickering effect by saving the temperature reading into a separate variable and only writing to the lcd when the current temperature value is not equal to the old value.

Or some such thing.

Regards, Dave

Thanks a lot davekw7x! it works

now i cant see it flickering :smiley:

here is the code with mods:

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, 1);

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

delay(1400);