I am a newbie in arduino and I am trying to control a LED brightness with photoresistors. Basically, what I am trying to achieve is that each photoresistor will correspond to different brightness level.
For some reason I am not able to achieve that, and only one of the photoresistor is actually working.
Here is the code:
int lightPin = 0; //define a pin for Photo resistor
int lightPin2 = 1; //define a pin for Photo resistor
I am doing this with the help of different tutorials, and I am just stuck right now. Possibly I am making some really stupid mistakes, but just can't figure it out.
If someone could just help or give some piece of advice I would be very thankful.
BTW, there were some mistakes in the code that I corrected. I thought it could be misleading... The code is correct now and basically only the pin connected to the analog 1 is actually working. I wonder if the problem is in the circuit?
basically only the pin connected to the analog 1 is actually working. I wonder if the problem is in the circuit?
If you are getting readings from it then there is no problem with the circuit.
However, the fact it is not working like you expect shows that you are not getting the code right.
Post what you have now. However code will always do what it is written to do so there is no way from just looking at it that you can normally spot what is wrong. You need to also say what you expect it to do and what you see it doing.
From the Fritzing diagram, it appears that your LED is not connected correctly. The LED should be in series with it. If you leave it connected as shown in the diagram, you are likely to damage the Arduino and possibly the LED.
Maybe the light from the LED is affecting the resistance of the photoresistor connected to pin A0?