Sensors/Modules

Reading LDR Value Arduino

Code Section:

int sensorPin = A0; // select the input pin for LDR
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(13,OUTPUT);
Serial.begin(9600); //sets serial port for communication
}
void loop() {
sensorValue = analogRead(sensorPin); // read the value from the sensor
Serial.println(sensorValue); //prints the values coming from the sensor on the screen
if( sensorValue<300)
  {
    digitalWrite(13,HIGH);
  }
  else digitalWrite(13,LOW);

delay(100);
}

 

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button
Close