Why does volt not print to LCD?

Hello all, I’m having a bit of a problem with the following code. At the beginning it all was working nicely with voltage printing out. Then voltage just displays “Voltage=0.00” on the first line of the LCD. The PinVolt displays the correct value on the 2nd line just as it should: “PinVolt=4.25”

With the voltage divider I’ve got that should equal about 13.8 which is correct voltage.

Please take a look at my code and tell me what I’m doing wrong - why can I not get the voltage to display? I can swap the values (type Pvolt in the first line and it displays the PinVolt on first line with 2nd line then displaying “Voltage=0.00”

I’m sure there is something stupid I’m not seeing… HELP!!!

// variables for input pin and control LED
#include <LiquidCrystal.h>

int volt_pin = 5;  //pin 28 on the m168

float volt = 0.0;
float voltraw = 0.0;
float Pinvolt = 0.0;

//This is resistors used on voltage divider

int R1 = 6695.0;    // resistance of R1 
int R2 = 2974.0;     //resistance of R2

LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // (RS, Enable, data lines)this meets the include LiquidCrystal.h above

void setup()
{
  // declaration of pin modes

  pinMode(volt_pin, INPUT); 

  // setup to send to LCD with 16 columns and 2 lines.
  lcd.begin(16,2);
}

void loop(){

  for (int i = 0; i < 20; i++)
    voltraw = voltraw+analogRead(volt_pin);
  voltraw = voltraw / 20;
  Pinvolt = ((voltraw * 4.58) / 1024.0);
  volt = (Pinvolt/(R2/(R1+R2)));

  lcd.setCursor(0,0); //start print first line
  lcd.print("Voltage=");
  lcd.print(volt);

  lcd.setCursor(0,1);  //start print 2nd line
  lcd.print("PinVolt=");
  lcd.print(Pinvolt);

  delay(500);
}

float voltraw = 0.0; I had the voltraw as “int voltraw = 0.0;” but changed to float trying to see if that would help.

Thank ya’ll for looking the code over and any suggestions you might make.

Ken H>

I think your problem is in volt = (Pinvolt/(R2/(R1+R2))); R1 and R2 are declared as int’s so the stuff in the brackets evaluates to 0. Declaring them as floats - or just netting out the ratio will probably work.

Awww Shucks - it was that simple. The Voltage display was working, but I was playing around in the code and must have changed the "float" to "int" while at the same time I made some other changes and forgot those the floats to int.

Darn it - well, at least it's something simple.

Thank you so much for your quick response.

Ken H>