Analog In and Resistors

Hi guys,

I'm moving my first steps with Arduino.. now I'm trying some reading from the Analog In. This is my circuit: yfrog.com/6ximage217qj

This is my code:

/* read the value from a potentiometer and use it as delay */

int potPin = 0;
int ledPin = 13;
int val = 0;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  
}

void loop() {
  val = analogRead(potPin);    // read the value from the sensor
  digitalWrite(ledPin, HIGH);  // turn the ledPin on
  Serial.println(val);
  delay(val);                  // stop the program for some time
  digitalWrite(ledPin, LOW);   // turn the ledPin off
  delay(val);                  // stop the program for some time
}

I don't get why I always get 1023 on serial monitor.

Given that the current flows from 5V to the two resistors I would have expected a decrease in the voltage thus reading something smaller than 1023.

What am I doing wrong? If this has something with wrong circuit stuff, would you point me so some documentation about it?

Thanks,

Fabio Varesano

The link to the image is http://yfrog.com/6ximage217qj

You have it wired up wrong. One end needs to go to 5V, the other end to ground and the middle or junction between the two resistors to your analogue input.

Given that the current flows from 5V to the two resistors I would have expected a decrease in the voltage thus reading something smaller than 1023.

No physics doesn’t work like that. voltage is developed across a resistor that has current flowing. In your set up you have no (or virtually no) current flowing through the resistors because the analogue input is very high impedance and so no current flows to ground.