Sensor Technology Task3.1 3.2
Sensor Technology Task3.1 3.2
Task-3
Interfacing LDR and IR Sensor using
Arduino Uno
LDR
• This is a resistor whose resistance depends on the amount of light falling
on it.
2
LDR
Working Principle of LDR
3
LDR
• When light falls on an LDR its resistance
falls rapidly.
• In low light or the dark – they act as high
Resistance of an LDR resistors.
• In bright light they offer very little
resistance
• LDRs are made from semiconductor
materials to enable them to have their
light sensitive properties. Many materials
can be used, but one popular material for
these photoresistors is cadmium sulphide,
CdS.
4
Program:
// Define pin numbers
const int ledPin = 2; // LED connected to digital pin 8
const int ldrPin = A0; // LDR connected to analog pin A0
void setup()
{
pinMode(ledPin, OUTPUT); // Set the LED pin as output
Serial.begin(9600); // Start serial communication at 9600 bps
}
void loop()
{
int ldrValue = analogRead(ldrPin); // Read the value from the LDR
Serial.println(ldrValue); // Print the value to the serial monitor
// Assuming a lower value means more light
if (ldrValue > 600)
{
digitalWrite(ledPin, HIGH); // Turn the LED on
}
else
{
digitalWrite(ledPin, LOW); // Turn the LED off
}
delay(500); // Wait for half a second
Program:
• int SensorPin = 2;
• int OutputPin = 13;
• void setup() {
• pinMode(OutputPin, OUTPUT);
• pinMode(SensorPin, INPUT);
• Serial.begin(9600);
• }
• void loop() {
• int SensorValue = digitalRead(SensorPin);
•
• Serial.print("SensorPin Value: ");
• Serial.println(SensorValue);
• delay(100);
• if (SensorValue==LOW){ // LOW MEANS Object Detected
• digitalWrite(OutputPin, HIGH);
• }
• else
• {
• digitalWrite(OutputPin, LOW);
• }