I have a LED on analog pin 0 (with resistor)
I have positive to analog 0 and negative to ardunio ground
I use just analog read and get 200-250 with light levels
once I set the pin to high it works but once I read the analog pin again it returns 0
I think that to get a reading from one, the anode must be to ground and the cathode to the input(reverse-biased). So put the LED+resistor between two analog pins(or one analog and one digital), and to detect light, set the analog pin to an input and the other pin to output and LOW then do an analog read. To emit light, set the analog pin to output and LOW and the other pin HIGH. I believe this would make it work(though I don't know how you got any readings in the first place. Noise maybe?) Hope that helps
Edit: according to post below me, you don't need to (shouldn't) set it to an input.
Hi!
Sorry if my english is not the best, but I going to try answer your question.
If you try set on a led, when a specific analog value is read, this is the program that I recommend you:
void setup()
{
Serial.begin(9600);
pinMode(3, OUTPUT); //You must use the Digitals I/O (In this case pin3). Connect the led in similar form
}
void loop()
{
int sensorValue = analogRead(A0);
Serial.println(sensorValue, DEC);
if(sensorValue < 210)
{
digitalWrite(3,HIGH);//digitalWrite do not give a value in analog pins, only write a value in digital pins
delay(20);
digitalWrite(3,LOW);
// delay(20);
}
else
{
digitalWrite(3,LOW);
}
delay(10); //You can write the delay in the end of program
}
I Hope this solve your problem, if you have another question write me to vmbarragan@gmail.com