You are on page 1of 11

NAME:K.

SAI PRARDHANA DATE : 07-12-23


ROLL NO : 21EG104A45 PAGE NO :
EXPERIMENT – 2
To Interface Push button/Dgital sensor(IR/LDR) with Arduino Raspberry
pi and write a program to turn ON LED when push button is pressed or
at sensor detection.

Aim : To Interface Push button/Dgital sensor(IR/LDR) with Arduino Raspberry pi and write a program to
t turn ON LED when push button is pressed or at sensor detection.

Requirements : Raspberry pi 4,LED,switch,IR sensor,personal computer.


Procedure :

1 Connect the Raspberry pi 4 to the Monitor display along with the keyboard, mouse and the ethernet
cable.

2. For the function of the switch connect the 3v3 power supply (pin 1) of the Raspberry pi to the positive
terminal of the LED display board and the negative terminal of the display board to the ground (pin 9)
and connect one of the switch pins to GPIO 17 (pin 11) and from GPIO 18 (pin 12) connect a jumper
cable to one of the LED pin and run the program.

3. Whenever we press the switch we observe that the LED glows.

4. For LDR and IR sensor connect the VCC(pin 1) to 3v3 power supply (pin1) of the Raspberry pi then
connect the ground terminal of the sensor to ground terminal (pin 6) of the Raspberry Pi and the output
terminal to GPIO 17 (pin 11) and from GPIO 18 (pin 12) connect a jumper cable to one of the LED pin
and run the program.

5. Run the program and observe the output.

Program :

import RPi.GPIO as GPIO // Importing RPi GPIO as GPIO //


import time // Importing or setting time //
GPIO.setwarnings(False) // To get only errors but not warnings //
GPIO.setmode(GPIO.BCM) // Setting the GPIO pin in BCM //
GPIO.setup(17,GPIO.IN) // Taking input from GPIO17 pin
// GPIO.setup(18,GPIO.OUT) // Showing output in GPIO18 pin //
while(True): // while loop //
if ( GPIO.input(17)==0): // If GPIO 17 is 0
// GPIO.output(18,GPIO.HIGH) // Output is high //
time.sleep(1) // Output high only for 1 second //
ANURAG UNIVERSITY EMBEDDED SYSTEMS & IOT LAB ECE DEPARTMENT
NAME: K.SAI PRARDHANA DATE : 07-12-23
ROLL NO: 21EG104A45 PAGE NO :

FLOW CHART
ANURAG UNIVERSITY EMBEDDED SYSTEMS & IOT LAB ECE DEPARTMENT
NAME: K.SAI PRARDHANA DATE : 07-12-23
ROLL NO : 21EG104A45 PAGE NO :
else:
GPIO.output(18,GPIO.LOW) // Output is low //
time.sleep(2) // Output is low for 2 seconds //

Result

LED glows when switch is


connected

LED glows when LDR is


covered

ANURAG UNIVERSITY EMBEDDED SYSTEMS & IOT LAB ECE DEPARTMENT


NAME: K.SAI PRARDHANA DATE : 07-12-23
ROLL NO : 21EG104A45 PAGE NO :

INTERFACING DIAGRAM

ANURAG UNIVERSITY EMBEDDED SYSTEMS & IOT ECE DEPARTMENT


LAB
NAME: K.SAI PRARDHANA DATE : 07-12-23
ROLL NO : 21EG104A45 PAGE NO :

LED if off when LDR is


uncoverd

LED glows when sender and receiver emitters of IR are uncovered

ANURAG UNIVERSITY EMBEDDED SYSTEMS & IOT ECE DEPARTMENT


LAB
NAME: K.SAI PRARDHANA DATE : 07-12-23
ROLL NO : 21EG104A45 PAGE NO :

ANURAG UNIVERSITY EMBEDDED SYSTEMS & IOT ECE DEPARTMENT


LAB
NAME: K.SAI PRARDHANA DATE : 07-12-23
ROLL NO: 21EG104A45 PAGE NO :

LED is off when sender and receiver emitters of IR are covered

Conclusion:
We have performed the experiment to interface Push button/Digital sensor (IR/LDR) with Arduino/Raspberry
Pi and write a program to turn ON LED when push button is pressed or at sensordetection.

ANURAG UNIVERSITY EMBEDDED SYSTEMS & IOT LAB ECE DEPARTMENT

You might also like