* led will glow according to the intensity of light
components required- arduino uno
- ldr
- led
- 10k resistor
- wires
code
int sensorPin = A0;
int ledPin = 13;
int ledPin2 = 12;
int ledPin3= 11;
int ledPin4= 10;
int p = 0;
void setup() {
// declare the ledPin as an OUTPUT:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3,OUTPUT);
pinMode(ledPin4,OUTPUT);
}
void loop() {
// read the value from the sensor:
p = analogRead(sensorPin);
// turn the ledPin on
Serial.println(p);
if(p<820)
{
digitalWrite(ledPin,p);
digitalWrite(ledPin3,HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin4,HIGH);
}
else
{
digitalWrite(ledPin, LOW);
digitalWrite(ledPin3,HIGH);
digitalWrite(ledPin4,HIGH);}
if(p<850) //
{ }
else
{ digitalWrite(ledPin3,LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin4,HIGH);
}
if(p>870)
{digitalWrite(ledPin4,LOW);
digitalWrite(ledPin,LOW);
}
}
connections
- connect the led to the arduino board pins(13,12,11,10)
- connect a 10 k resistor in series with the ldr,
- connect the free end of resistor to the +5v pin of arduino
- connect the free end of ldr to ground
- connect the a0 pin to the ldr
- connect all the -ve terminal of led to ground
- connect arduin to pc
- run the code
:- open serial monitor for viewing the ldr values.( tools->serial monitor)
No comments:
Post a Comment