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
}

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

Hi,
What model Arduino?

Tom.. :slight_smile:

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

}

Koepel:
PA7 ? What is PA7 ?

Correction - A0

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

{

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)

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

}
}

Wawa:
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..

Actually I am using STM32 for testing, for Voltmeter only pins names are different.

1.76 volts

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Tom... :slight_smile:

This is working, but I have to use reset button, to clear last reading. A is coming up when voltage is above 2V and is says when voltage is below 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

}
}

Delta_G:
So you were lying here?

Are you just trying to aggravate people and waste people's time? Why are you lying? I'm done. You can figure this out on your own and maybe next time you can learn to tell the truth and not lead people down the wrong path trying to answer your question.

Sorry for that,I am not lying. I have explain what I'm doing.

This circuit but with STM32

Delta_G:
No, You were lying. You said it was an UNO when it clearly was not. Why?

There will be 1 page of explanations to prove that Uno and STM32 can use the same programs in 80%