V-tech world.

V-tech world.

Share

31/10/2024

Good evening, everybody! How’s your day going? It’s time for learning. Now we will learn about the LDR. It's a kind of resistor that changes its resistance based on the amount of light it receives.
How does this happen?
The LDR consists of a layer of cadmium sulfide (CdS) or cadmium selenide (CdSe), both of which are sensitive to light in the same spectrum range as the human eye or photographic film can see.

For example, we can use the LDR in a project to turn on the light when night comes. We need:

Relay module x1

10KΩ resistor x1

LDR x1

Test board x1

Arduino UNO x1

Connected wires x6

First Step: Connect the Pins with Arduino
LDR leg --> 5V

LDR leg --> Pin A0 (any pin with analog inputs)

Resistor leg --> GND

Resistor leg --> Between A0 and LDR leg

Relay + --> 5V

Relay - --> GND

Relay S --> Pin 4 in Arduino

Second Step: The Code for Programming
Open the Arduino IDE and write this code:

res A0
relay 4
int value = 0;

void setup() {
pinMode(res, INPUT);
pinMode(relay, OUTPUT);
}

void loop() {
value = analogRead(res);
delay(10);
if (value > 9) {
digitalWrite(relay, HIGH);
} else {
digitalWrite(relay, LOW);
}
}





..By Eng. Wajed

Want your business to be the top-listed Engineering Company in Lagos?
Click here to claim your Sponsored Listing.

Website

Address


Lagos