Go Down

Topic: Arduino Uno board only works with digital pins (Read 854 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.

Go Up