Avatar of Dier Eluom
Dier Eluom
 asked on

Arduino

I want a LED to light up if a LDR detects that the light level has dropped.  I have another LEd running at the same time that shines on the LDR at 540 nanometres.  I want it to detect if the light level drops below 500 nanometres and if so turn on a REd led and if it is above 500 nanometres to turn on a green LED.

int LDRValue = 0; //result of analog pin
int ledPin = 13;

void setup(){
  Serial.begin(9600);//sets a serial port for communication
 pinMode(ledPin,OUTPUT);
}
void loop(){

  LDRValue = analogRead(LDRpin);//read the value from LDR
  
  Serial.println(LDRValue*12.5); //print to serial port
   digitalWrite(ledPin,HIGH);
  delay(200);
  
}

Open in new window

Embedded Hardware

Avatar of undefined
Last Comment
Gerwin Jansen

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Gerwin Jansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dier Eluom

ASKER
Thanks. All good
Gerwin Jansen

Ok. since my comment technically doesn't answer your question it's best if we delete this question ok?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy