Go Down

Topic: Analog read isn't working (noob) (Read 53 times) previous topic - next topic

Sparkyy

Arduino Diecimila (ATmega168), IDE 1.6.1.

A real simple sketch to read the analog input from a potentiometer.

I've connected the 2 outer terminals of a pot to 5v and ground, and the center (wiper) of the pot to A0. The input pin (the solder joint on the Arduino A0 pin) measures from 0-5v with reference to ground as I turn the pot fully.

I'm not getting any variation of the timing of the LEDs. The LEDs flash at a fixed rate (as if I used a delay of 1000) no matter the position of the pot. I can put integers in place of "Speed" and vary the timing by changing this value.

What am I doing wrong?

Thanks.


Code: [Select]

  int RledPin =  11;
  int YledPin =  12;
  int analogPin = 0;
  int Speed = 0;

void setup()   {               
  pinMode(RledPin, OUTPUT);
  pinMode(YledPin, OUTPUT);
  analogReference(DEFAULT);
}
 
void loop()                     
{
  Speed = analogRead(analogPin);
  digitalWrite(RledPin, HIGH);
  delay(2);
  digitalWrite(RledPin, LOW);
  delay(Speed);
  digitalWrite(YledPin, HIGH);
  delay(2);
  digitalWrite(YledPin, LOW);
  delay(Speed);
}

mistergreen


Sparkyy

Thanks for your suggestion.

Quote
int analog pin = A0;
No change.

I tried connecting the pot to each of the 6 analog input pins and changing the int statement accordingly.

No joy.

Sparkyy

#3
Today at 08:01 am Last Edit: Today at 08:21 am by Sparkyy
Discovered the problem.

I have a Sparkfun Protoshield on my Arduino Diecimila board. The Protoshield has the analog pins labeled A0 through A5 with A0 closest to the corner of the PCB. Apparently this is incorrectly labeled. I was watching a video on YouTube about Arduino and saw a close-up of the Arduino and Eureka!, A5 is closest to the corner.

I plugged the pot into the pin labeled "A0" and changed the sketch to analogRead(5) and it works!

The Protoshield I have is many years old (4 or 5?). It's not red like the current ones are from Sparkfun but green. I checked the current Protoshields at Sparkfun and the analog pins are labeled correctly.

I'll post a close up photo below.

So I have a mislabeled board. Good to know...finally!

Cheers.


Sparkyy

#4
Today at 08:29 am Last Edit: Today at 09:04 am by Sparkyy
Here's a photo of the incorrectly labeled Protoshield (on top) and the Diecimila (below):



Note the different pin numbers on the two boards.

It pays to take NOTHING for granted. Especially in programming.

Cheers!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy