Voltmeter

Hi
I want to print letter A when voltage is between 2 and 4 volts.
Thanks for help

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() {
   pinMode(PA7, INPUT_ANALOG);
   lcd.begin(16, 2);
}

void loop() {
  float volt = analogRead(PA7);
  volt = (volt * 3.3) / 4095.0;
  lcd.setCursor(0,0);
  lcd.print(volt);
lcd.setCursor(10,0); 
lcd.print( ???); 


  delay(100);
}

   if(volt <= 4 && volt >= 2)
{

lcd.print (A); //print letter A
}

else

{
    ???            // print nothing
}
lcd.print ('A');

Put it in quotes to let the compiler know that it is a literal and not the name of a variable.

I did, but there is more to do, I marked that by - ?

I don't understand. Are you talking about the else statement? If you don't want anything to happen there then just remove the else entirely.

If that's not what you're getting at then please take a little time to try to be clear about what you actually want.

Hi, What model Arduino?

Tom.. :)

Uno

I have a error
simple_DC_voltmeter:22: error: expected unqualified-id before ‘{’ token

{

void loop() {
  float volt = analogRead(PA7);
  volt = (volt * 3.3) / 4095.0;
  lcd.setCursor(0,0);
  lcd.print(volt);
lcd.setCursor(10,0); 
lcd.print( "A"); 


  delay(100);
}

   if(volt <= 4 && volt >= 2);
{

lcd.print ("A"); //print letter A

}

PA7 ? What is PA7 ?

The letter - A - stays all the time

void loop() {

float volt = analogRead(A0);
volt = (volt * 3.3) / 4095.0;
lcd.setCursor(0,0);
lcd.print(volt);
lcd.setCursor(10,0);
//lcd.print( “A”);

delay(100);

if(volt <= 4 && volt >= 2);

lcd.print (“A”); //print letter A

}

ted:
I have a error
simple_DC_voltmeter:22: error: expected unqualified-id before ‘{’ token

{

void loop() {       //////<<<<<<  OPENING BRACE
  float volt = analogRead(PA7);
  volt = (volt * 3.3) / 4095.0;
  lcd.setCursor(0,0);
  lcd.print(volt);
lcd.setCursor(10,0); 
lcd.print( "A"); 


  delay(100);
}   ////////////  <<<<<<<<<<CLOSING BRACE

   if(volt <= 4 && volt >= 2);
{

lcd.print ("A"); //print letter A

}

Check your braces. Your loop function ends right after the delay(100) line. After that the if statement isn’t inside any function and that’s illegal code. That’s the source of your error.

Koepel: PA7 ? What is PA7 ?

Correction - A0

  if(volt <= 4 && volt >= 2);


lcd.print ("A"); //print letter A

Is equivalent to:

  if(volt <= 4 && volt >= 2){
;   ///  DO NOTHING
}


lcd.print ("A"); //print letter A

Semicolons don’t belong on if statements.

if(volt <= 4 && volt >= 2);

Remove the semicolon from the end of this line.

Delta_G:

void loop() {       //////<<<<<<  OPENING BRACE

float volt = analogRead(PA7);
 volt = (volt * 3.3) / 4095.0;
 lcd.setCursor(0,0);
 lcd.print(volt);
lcd.setCursor(10,0);
lcd.print( “A”);

delay(100);
}   ////////////  <<<<<<<<<<CLOSING BRACE

if(volt <= 4 && volt >= 2);
{

lcd.print (“A”); //print letter A

}





Check your braces. Your loop function ends right after the delay(100) line. After that the if statement isn't inside any function and that's illegal code. That's the source of your error.

for this the error is

simple_DC_voltmeter:21: error: expected unqualified-id before ‘if’

if(volt <= 4 && volt >= 2);

^

simple_DC_voltmeter:22: error: expected unqualified-id before ‘{’ token

{

Yes. You still haven’t fixed the brace error I pointed out. The problem is literally commented with big

///////////<<<<<<<<<<<<<

in the code you posted. Are you not even trying?

void loop() {       //////<<<<<<  OPENING BRACE
  float volt = analogRead(PA7);
  volt = (volt * 3.3) / 4095.0;
  lcd.setCursor(0,0);
  lcd.print(volt);
lcd.setCursor(10,0); 
lcd.print( "A"); 


  delay(100);
}   ////////////  <<<<<<<<<<CLOSING BRACE

   if(volt <= 4 && volt >= 2)
{

lcd.print ("A"); //print letter A

}

error
simple_DC_voltmeter:21: error: expected unqualified-id before ‘if’

if(volt <= 4 && volt >= 2)

Delta_G:
Yes. You still haven’t fixed the brace error I pointed out. The problem is literally commented with big

///////////<<<<<<<<<<<<<

in the code you posted. Are you not even trying?

The problem is STILL clearly commented in that code you posted. Just freaking look at it dude. Come on man.

All of your code needs to be inside of a function.

volt = (volt * 3.3) / 4095.0; An Uno is a 5volt Arduino, and has a 10-bit A/D.

float volt = analogRead(A0) * 5.0 / 1024; Leo..

No errors, on LCD two " AA", all the time, below 2V and above 2V

void loop() {       //////<<<<<<  OPENING BRACE
  float volt = analogRead(PA7);
  volt = (volt * 3.3) / 4095.0;
  lcd.setCursor(0,0);
  lcd.print(volt);
lcd.setCursor(10,0); 
lcd.print( "A"); 


  delay(100);
   ////////////  <<<<<<<<<<CLOSING BRACE

   if(volt <= 3  && volt >= 2)
{

lcd.print ("A"); //print letter A

}
}

You're printing volt. What values do you see?