Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Tarantula3DIYables
Published

Using An LDR Sensor With Arduino

Wouldn’t it be really cool if whenever a room gets dark, a light bulb automatically turns ON and eliminates the darkness?

BeginnerFull instructions provided1 hour175,308
Using An LDR Sensor With Arduino

Things used in this project

Story

Read more

Schematics

Assembly

Code

The Code

Arduino
const int ledPin = 13;

const int ldrPin = A0;

void setup() {

Serial.begin(9600);

pinMode(ledPin, OUTPUT);

pinMode(ldrPin, INPUT);

}

void loop() {

int ldrStatus = analogRead(ldrPin);

if (ldrStatus <= 200) {

digitalWrite(ledPin, HIGH);

Serial.print("Its DARK, Turn on the LED : ");

Serial.println(ldrStatus);

} else {

digitalWrite(ledPin, LOW);

Serial.print("Its BRIGHT, Turn off the LED : ");

Serial.println(ldrStatus);

}

}

Credits

Tarantula3
69 projects • 87 followers
There were 1000+ sperms but I was the fastest one..
Contact
DIYables
0 projects • 88 followers
I would like to invite you to join and add your projects to DIYables platform https://www.hackster.io/diyables
Contact

Comments

Please log in or sign up to comment.