Experiment 2
Experiment 2
Date of Submission-25/04/2024
Name-SHIVPRIYA GUPTA
PRN-22070123111
E&TC-B2 EXPERIMENT-2
TITLE:
(a)-Simple Digital Input Sensor Control.
AIM:
(a)- The aim of the experiment is to detect and respond to the infrared (IR) sensor input by turning
on an LED (connected to pin 13) when the IR sensor detects an object.
Hardware Required: Infrared (IR) sensor, Breadboards, LED, Resistors, Jumper wires
THEORY:
Functions Used:
pinMode(13,OUTPUT): Configures digital pin 13 as an output to which an LED is typically connected.
pinMode(2,INPUT): Configures digital pin 2 as an input, suggesting that this pin is connected to a
sensor.
: Reads the digital state of pin 2 and stores it in the variable
if (SensorValue == LOW): Checks if the sensor value is LOW, indicating some condition (e.g., an
obstacle) is detected.
If true, it turns on the LED connected to pin 13 by executing digitalWrite(13, HIGH).
else: If the sensor value is not LOW, it turns off the LED by executing digitalWrite(13, LOW).
Sensor Information:
The code assumes the use of an infrared (IR) sensor connected to digital pin 2. IR sensors are
commonly used for obstacle detection. These sensors typically consist of an infrared transmitter (IR
LED) and an infrared receiver. When an obstacle is detected, the infrared light emitted by the
transmitter is reflected back to the receiver, causing the sensor to output a LOW signal.
The IR sensor has three pins: VCC, GND, and OUT. Connect
VCC to a 5V power source on the Arduino. Connect GND
to the ground (GND) on the Arduino. Connect OUT to
digital pin 2 on the Arduino.
The IR sensor emits infrared light, and when it hits an obstacle, the reflected light is
detected by the sensor.
If an obstacle is present, the sensor outputs a LOW signal; otherwise, it outputs a HIGH
signal.
CONCLUSION: This code uses an IR sensor to detect obstacles. When the sensor detects an
obstacle, it outputs a LOW signal, turning on the LED connected to pin 13. If no obstacle is
detected, the LED remains off. The practical implementation involves connecting the IR sensor to
the specified pins on the Arduino and connecting an LED to pin 13 for visual feedback.