i need to read a voltage with an arduino pro mini using the analog pins.

I created this simple test code:

int sensorValue;
float voltage;

void setup() {

void loop() {
  sensorValue = analogRead(A0);
  voltage= sensorValue * (5.0 / 1023.0);

my setup looks like this: hardware setup

everything works so far. I get about 4,5v as a result. Now i want to port everything to an arduino pro mini. After i did that i only got 2,5v as a result. I also tried it with different pins and with an other arduino pro mini.

So what did i do wrong? Do i need an other pull-up resistor?

  • 1
    2.5 V is what you expect. Why would you read 4.5 V? Oct 10, 2016 at 14:33
  • so you think my arduino nano is not working properly?
    – betion
    Oct 10, 2016 at 14:38
  • Or you used different resistors, or you used different code. Oct 10, 2016 at 14:49

1 Answer 1


I made a circuit bellow for you. Note that the top resistor is 100 ohm and the bottom one is only 10 ohm. What I did is called a voltage divider. This way you can read voltages up to 50V. Simply connect the positive of your power source that you want to measure to the red wire and the ground of that same source to the black wire.

I also included a code that you could use:

Please notify me if any mistakes were spotted.

#define sensor A0 //defining sensor pin

float resistor1 = 100; //you can change it if you want, just make sure you also do it on the circuit
float resistor2 = 10;

float Vmax = (5*resistor1 + 5* resistor2)/resistor2;

void setup() {
  pinMode(sensor, INPUT); //declaring sensor as an output

  Serial.print("Do not input more then (V) : "); // print max input voltage

  Serial.println(); //skip line

void loop() {
  float V = analogRead(sensor); //measuring analog values

  V = analogRead(sensor) * Vmax / 1024

  Serial.println(V); //printing voltage

enter image description here

  • Don't see mistakes, but here are a few suggestions: 1) Use higher valued resistors (but no more than 10 kΩ for R2) to avoid excessive current draw. Otherwise a 50 V source would blow up your 1/4 W resistors. 2) Declare the resistor values as float. 3) Write V = analogRead(sensor) * Vmax / 1024 instead of using map(). 4) Why divide the voltage by 100? Oct 10, 2016 at 15:21
  • thats what i mean by mistakes! thanks though :)
    – Dat Ha
    Oct 10, 2016 at 15:26
  • That float int resistor1 and float int resistor2 works? If yes, what type is it in the end? float or int?
    – KIIV
    Oct 10, 2016 at 17:10
  • opps, its just float, my bad!
    – Dat Ha
    Oct 10, 2016 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.