Hello, I'm trying to complete a project where I have to trigger 5 levels of brightness for an LED light from 0 to 255. I'm having some difficultly trying to create a counter using a photoresistor (I'm very new to Arduino). What is the proper syntax to use for creating a counter with a photoresistor and LED, how should I do it in this situation?
[code]
#define PinPWM 11
#define Photoresistor A0
int PinPWMValue = 0;
a[6] = { 0, 50, 100, 150, 200, 250 }; // 6 elements
void setup() {
// put your setup code here, to run once:
pinMode(PinPWM, OUTPUT);
pinMode(Photoresistor, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int PinPWMValue = analogRead(Photoresistor);
PinPWMValue = map(PinPWMValue,0 ,1023 ,0 ,255);
analogWrite(PinPWM, PinPWMValue); // will be between 0 and 255
}
[/code]
What other two resistors?
Please stop using that word sallad, grab a pen, paper and post a wiring!
16 replies to help You get the question right. Sorry, I dump Your question for doing something better.
Here's the image of my wiring, and sorry I'm really just looking for help on creating a counter, I look at multiple examples but I'm still having difficulty on making one for this project
Thanks! Okey. I would try an R2 somewhere in the range of 4.7 kOhm - 10 KOhm. Measure the LDR at ambient, none solar light indoors. Select an R2 near that value. Know that the readings will not be linear. Using
if(( value > 0 ) && (value <= counter1Limit) counter = 1;
if(( value > counter1Limit ) && (value <= counter2Limit) counter = 2;