Not sure if this should go under programming or in electronics, but since the weirdness starts when I changed code... okay here it goes:
I've set up a photocell with a 1K resistor to output on A0.
Initially, I initialized it like this:
#define lcell A0
void setup() {
pinMode(lcell, OUTPUT);
Later I run Serial.println(analogRead(lcell)); in a loop and it gives me values between 0-5 when I cover it with my hand and around 120 when I shine a flashlight on it.
Okay.
I looked at some other example code and saw they had their pins set up like this instead (with their wiring being identical to mine, i.e. on A0):
int lcell=0;
void setup() {
pinMode(lcell, OUTPUT);
so I changed mine as well.
But now my outputs on the Serial.println(analogRead(lcell)); range between 400-700 when I cover it with my hand and reaches around 1020 when I shine a flashlight on it!
I have done no changes to the physical setup nor has any other part of the code changed.
Can anyone explain this?
(Also, as a side question: could someone explain why using 0 instead of A0 works? There is a 0 pin on the digital side - shouldn't 0 rather refer to that? And if it doesn't, then how would you access the digital 0 pin?)
This is the entire code:
//#define lcell A0
int lcell=0;
void setup() {
pinMode(lcell, OUTPUT);
Serial.begin(9600);
}
void loop() {
Serial.println(analogRead(lcell));
delay(100);
}