Page 114 - TCS ICT Book 8
P. 114
The City School 2021-2022
The circuitry of LED blink is pretty simple, you just have to connect the electronic
component with raspberry pi properly as shown in the picture above.
1. Connect resistor through jumper wire (represented in blackcolour) with PIN 6.
2. Connect the positive leg of the LED with PIN 12 (GPIO 18).
3. After completing the circuitry, it’s time to move on to Raspberry Pi.
4. Turn on the Raspberry Pi.
5. On the desktop, go the start menu and click on python IDLE and enter the following
code:
Blinking LED code:
import RPi.GPIO as gpio
import time as t
gpio.setmode(gpio.BCM)
gpio.setwarnings(False)
gpio.setup(18, gpio.BCM)
gpio.setup(23, gpio.OUT)
while True:
if gpio.input(18):
gpio.output(23,true)
t.sleep(1)
else:
gpio.output(23,false)
We have also used the conditional statements in while loop. According to the if
condition, if the voltage is detected on the GPIO18, then the Pi will turn on the LED,
which is connected to GPIO23. The voltages will be detected on GPIO18 when the
button is pressed.
5.12. Interfacing with SONAR Sensor
In this program, we will understand the SONAR Sensor and its working. SONAR is an
acronym of Sound Navigation & Ranging. It is used for measuring distance regardless
of the shape colour and surface of the object.
114

