Hello friends. I bought a new arduino 5 days ago. I also apologize for my bad English.
When I use the '' IF '' command, I want the army to turn on the LED light.
For example, if your LDR value is greater than 500 denier, open the arduino light.
I try to work for it, but I have not been successful somehow. I apologize again for bad english. Have a good evening.
Also Im soo new about use Arduino.
int LDR=A0;
int LED=10;
void setup() {
Serial.begin(9600);
pinMode(10,OUTPUT);
// put your setup code here, to run once:
}
void loop() {
int LDRRead=analogRead(LDR);
Serial.println(LDRRead);
delay(200);
if (LDR<500) {digitalWrite(LED,HIGH);}
// put your main code here, to run repeatedly:
}
Here's what I recommend to do for the led. One check and mixture your positive and negative leads are correct to the led the longer one being positive and the shorter one being negative. In addition do digitalWrite(10, HIGH); This will set the led as off(high is off, low, is on). To turn led on do the opposite digitalWrite(10, LOW); I hope this helps.
Actually, you test the value of the PIN (LDR = "A0") and not the measured value (LDRRead).
Try
if (LDRRead<500)
Moreover, if the IF condition is not respected, for the time behing, your code ask to "not change anything", so to stay HIGH. You have to ask to the pin to change by adding an "ELSE" condition to turn off the led (LED,LOW)