Arduino nano analogread problem

Sorry guys for this stupid question!!!

but i can t make work the analog read of arduino nano

i made a simple voltemeter but it always gives me the result of 54,9 volt thata is the maximum
and also the simple analogread command gives 1023 but from my multimeter i read just 1,3 volt maximum

so the sketch works well on arduino mega but the problem heppens when i compile the sketch on Arduino Nano

could you please help me?

Hi,

Can you please post a copy of your sketch, using code tags.

Tom..... :slight_smile:

the code is the simplest possible, thank you

#include <LiquidCrystal.h> // include the library code:

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //initialize the library with the numbers of interface pins

// variables for input pin and control LED
int analogInput = 0;
float vout = 0.0;
float vin = 00.0;
float R1 = 100000.0;    //  resistance of R1 (100k)
float R2 = 10000.0;     //  resistance of R2  (10k)

int value = 0; // variable to store the value

void setup(){

pinMode(analogInput, INPUT); // declaration of pin modes

lcd.begin(16, 2);   // set up the LCD’s number of columns and rows:
lcd.print(“Vin=”);
}

void loop(){

value = analogRead(analogInput);   // read the value on analog input

vout = (value * 5.0) / 1024.0;
vin = vout / (R2/(R1+R2));

// print result to lcd display
lcd.setCursor(4, 0);

lcd.print(vin);
lcd.print(“V”);

delay(500); // sleep…
}

I see references to R1 and R2 in your code, which makes me think you are using a voltage divider. Please post a schematic of how you have things hooked up.

You don't need pinMode() with analog inputs - I'm not sure if it will cause a problem.

It is better to refer to analog pins as A0 to avoid confusion with digital pin 0

To start with just print the raw values produced by analaogRead() - worry about unit conversion later.

...R

If the same code works with MEGA but not nano, then it's connection problem, not code. Post your setup picture. I use plenty of nano boards. It's not the board.