Go Down

Topic: Arduino Uno board only works with digital pins (Read 874 times) previous topic - next topic

roguer15

  Recently I got the basic Uno kit from sparkfun and have been doing some of the sample sketches.  The sketches that involve LEDs, turning them on and off, all seem to work fine.  However any time I try a sketch that involves reading analog off of the analog 0 pin they don't work.  I used Serial.println to see what values it was reading of the analog sensor and it's always just zeros.  I don't understand why I can't seem to get the analog sketches to function properly.  I don't have an issue uploading to the board in that the LED sketches upload fine and work.  Also I'm hooking up the circuit correctly on the breadboard.  I have double checked to make sure so many times and tried different examples to ensure it's not me botching the circuit.  Is there anything I can do to test my board?  The thing is brand new so I just don't understand.

Thanks

retrolefty

Quote
Is there anything I can do to test my board?  The thing is brand new so I just don't understand.

yes, First post your code in a code window here (# button) to show us the code that doesn't work. Second either supply a drawing or decribe in detail how you are wiring the something you are trying to read on a analog input pin. I would bet dollars to donuts that the problem is somewhere there rather then on the board.

Lefty

roguer15

Sure.  Basically any of the analog examples from ardx.org, I'm using a SparkFun kit.  The example I have wired and coded right now is as follows.  I commented out some of the code just trying to get a reading off of the photo resistor.  Currently the serial output from this, and other examples, always reads 0.

Code: [Select]

int lightPin = 0;

int ledPin = 9;   

void setup()
{
  pinMode(ledPin, OUTPUT); //sets the led pin to output
  Serial.begin(9600);
}

void loop()
{
int lightLevel = analogRead(lightPin); //Read the lightlevel
Serial.println(lightLevel);
delay(500);

/*lightLevel = map(lightLevel, 0, 900, 0, 255);
         //adjust the value 0 to 900 to
         //span 0 to 255

lightLevel = constrain(lightLevel, 0, 255);//make sure the
                                           //value is betwween
                                           //0 and 255
analogWrite(ledPin, lightLevel);*/  //write the value
}


It is wired as follows in the diagram, http://ardx.org/circ09

Grumpy_Mike

It could be your photo resistor is not working or it is not making a good connection to +5V, or you have wired the analogue input down to ground not through a 10K resistor.
Remove the photo resistor and the 10K pull down and just read the pin raw. It should float and give you random readings.
The connect the photo resistor to +5V and the input, you should get a reading of 1023.
Finally connect the 10K from input to ground, then you will get a reading proportional to light.

roguer15

When I read the pin raw it does read fluctuating values.  However, when I hook it up in the circuit http://www.oomlout.com/a/products/ardx/circ-09 it reads all zeros.  This is true for all their examples involving analog input.  For instance I tried an example using a potentiometer and got the same result on the analog reading.

James C4S

If you aren't going to post your own schematic, it might help to post a photo of your setup.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Grumpy_Mike

Quote
When I read the pin raw it does read fluctuating values.

Good so that means your analogue inputs are working.

Quote
However, when I hook it up in the circuit http://www.oomlout.com/a/products/ardx/circ-09 it reads all zeros.  This is true for all their examples involving analog input.

So that means you are making a mistake, you have not wired it up like the circuit schematic is telling you to wire it.

roguer15

Quote
So that means you are making a mistake, you have not wired it up like the circuit schematic is telling you to wire it.


Believe me this is the first thing I figured also.  I took it all apart and set it back up multiple times to see if I did something wrong.  I tried the other analog examples too thinking maybe I was missing something from the previous examples.  I also had a friend wire it up and he did it the same way.  There really isn't a whole lot going on in that circuit to mess up and I seem to be able to do all the digital examples just fine so I know I can wire up these basic examples as specified.  The code is a straight cut and paste from the ardx.org website so no manual entry errors there.  I don't know what is going on but I can't get a reading of anything but 0's on those analog pins.

justone

Some breadboards do not have the power strips continuous so be aware of that in your setup on it. The color stripe is a good indication of how the power is routed.

James C4S

The code and the arduino's I/O pins have already been shown to work correctly from your troubleshooting steps.  What are you measuring on the Analog Pin with a multimeter?

Also, can you post a (clear) picture of your setup?
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Go Up