SY Four Raspberry Pi
SY Four Raspberry Pi
R
GPIO4
Raspberry Pi
3B+
Theory:
LED (Light Emitting Diode): LED is a two-lead semiconductor light source. It is a p–n
junction diode, which emits light when activated. When a suitable voltage is applied to the
leads, electrons are able to recombine with electron holes within the device, releasing energy in the
form of photons. This effect is called electroluminescence, and the color of the light (corresponding to
the energy of the photon) is determined by the energy band gap of the semiconductor. The charge
carriers recombine in a forward-biased P-N junction as the electrons cross from the N-region and
recombine with the holes existing in the P-region. Free electrons are in the conduction band of energy
levels, while holes are in the valence energy band. Thus the energy level of the holes will be lesser
than the energy levels of the electrons. Some portion of the energy must be dissipated in order to
recombine the electrons and the holes. This energy is emitted in the form of heat and light. The
electrons dissipate energy in the form of heat for silicon and germanium diodes but in gallium arsenide
phosphide (GaAsP) and gallium phosphide (GaP) semiconductors, the electrons dissipate energy by
emitting photons. If the semiconductor is translucent, the junction becomes the source of light as it is
emitted, thus becoming a light-emitting diode, but when the junction is reverse biased no light will be
produced by the LED and, on the contrary, the device may also be damaged.
Procedure:
Perform basic setup by connecting monitor, keyboard and mouse to the Raspberry Pi.
Connect 5V DC power adaptor to the MGTechSolution Raspberry Pi Target board.
Connect separate DC power adaptor to the Raspberry Pi attached to the Target board.
Switch on both the power adaptor and wait until Raspberry Pi starts.
Go to Programming menu and select Thonny Python IDE.
Click on New to open new file and write the program.
After completion of writing program, save file with .py extension.
Make necessary connections to connect the LED array to GPIO pins of Raspberry Pi in the
“Raspberry Pi GPIO section”.
Click on Run button to Run the program in Thonny Python IDE.
Observe the output.
Click Stop button to stop execution of the program.
Flowchart: (Blinking LED’s)
Start
GPIO.setup(4, GPIO.OUT)
while True:
GPIO.output(4, GPIO.HIGH)
time.sleep(3)
GPIO.output(4,
GPIO.LOW)
time.sleep(3)
Teacher’s Sign.
*************
Experiment – 2
Title: Programming of Raspberry Pi to get feedback from a switch connected to
the GPIO pins.
Aim: To study and understand Interfacing switch connected to the GPIO pins of Raspberry Pi.
Objectives:
To understand the concept of switch interfacing.
To study interfacing of switch to Raspberry Pi.
Circuit Diagram:
+3.3 V
SW R
GPIO17 GPIO4
Raspberry Pi 3B+
Procedure:
Perform basic setup by connecting monitor, keyboard and mouse to the Raspberry Pi.
Connect 5V DC power adaptor to the MGTechSolution Raspberry Pi Target board.
Connect separate DC power adaptor to the Raspberry Pi attached to the Target board.
Switch on both the power adaptor and wait until Raspberry Pi starts.
Go to Programming menu and select Thonny Python IDE.
Click on New to open new file and write the program.
After completion of writing program, save file with .py extension.
Make necessary connections to connect the switch to the GPIO pins of Raspberry Pi in the
“Raspberry Pi GPIO section”.
Click on Run button to Run the program in Thonny Python IDE.
Observe the output.
Click Stop button to stop execution of the program.
Flowchart:
Start
is NO
SW == 0
(Switch Press)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN,
pull_up_down=GPIO.PUD_UP) GPIO.setup(4,
GPIO.OUT)
while True:
button_state = GPIO.input(17)
if button_state == False:
GPIO.output(4, False)
print('Button Pressed...')
while GPIO.input(17) == False:
time.sleep(0.2)
else:
GPIO.output(4, True)
Result: Interfacing and programming of Raspberry Pi to get feedback from switch is successfully
studied, tested and observe the output.
Teacher’s Sign.
*************
Experiment – 3
Title: Programming of Raspberry Pi to detect light intensity using photocell
sensor.
Aim: To study and understand interfacing photocell sensor to Raspberry Pi.
Objectives:
To understand the working principle of photocell sensor.
To study interfacing of photocell sensor (LDR) to the Raspberry Pi.
Circuit Diagram:
+5V +5V
VCC SCL
LDR SCL SDA
SDA
Raspberry Pi
3B+
Analog
A0
O/P
ADC
R1
ADS1115
Thonny Python
GND IDE
Theory:
An LDR or light dependent resistor is also known as photo resistor, photocell, and
photoconductor. It is a one type of resistor whose resistance varies depending on the amount of
light falling on its surface. When the light falls on the resistor, then the resistance changes. These
resistors are often used in many circuits where it is required to sense the presence of light. These
resistors have a variety of applications. A typical light dependent resistor has a resistance in the
darkness of 1MOhm, and in the brightness a resistance of a couple of KOhm.
This resistor works on the principle of photo conductivity. It is nothing but, when the light falls
on its surface, then the material conductivity reduces and also the electrons in the valence band of
the device are excited to the conduction band. These photons in the incident light must have energy
greater than the band gap of the semiconductor material. This makes the electrons to jump from the
valence band to conduction. These devices depend on the light, when light falls on the LDR then
the resistance decreases, and increases in the dark. When a LDR is kept in the dark place, its
resistance is high and, when the LDR is kept in the light its resistance will decrease.
Procedure:
Perform basic setup by connecting monitor, keyboard and mouse to the Raspberry Pi.
Connect 5V DC power adaptor to the MGTechSolution Raspberry Pi Target board.
Connect separate DC power adaptor to the Raspberry Pi attached to the Target board.
Switch on both the power adaptor and wait until Raspberry Pi starts.
Install “Adafruit_ADS1x15” library on the Raspberry Pi by entering following commands in
the Terminal window.
sudo apt-get update
sudo apt-get install build-essential python-dev python-smbus git
cd ~
git clone https://github.com/adafruit/Adafruit_Python_ADS1x15.git
cd Adafruit_Python_ADS1x15
sudo python3 setup.py install
Go to Programming menu and select Thonny Python IDE.
Click on New to open new file and write the program.
After completion of writing program, save file with .py extension.
Make necessary connections to connect the LDR to the ADC input pins in the “ADC Section”.
Then connect SDA & SCL pins of ADC to the SDA & SCL pins of the Raspberry Pi in
“Raspberry Pi GPIO section”.
Click on Run button to Run the program in Thonny Python IDE.
Observe the output.
Click Stop button to stop execution of the program.
Flowchart:
Start
is NO
ADC value > 300
YES
Display message as
“Illuminated Condition”
else:
print('Illuminated Condition...')
time.sleep(2)
Applications of Photocell Sensor: (Student can search & write application here)
Result: Interfacing and programming of Raspberry Pi to detect light intensity using photocell sensor
is successfully studied, tested and observe the output.
Teacher’s Sign.
*************
Experiment – 4
Title: Programming of Raspberry Pi for Motion
detection Aim: To study and understand programming of Raspberry Pi for Motion
detection.
Objectives:
To understand the working principle of PIR sensor.
To study interfacing of PIR sensor to the Raspberry Pi.
Circuit Diagram:
+3.3 V
R
+5V GPIO4
1
Raspberry Pi
PIR 3B+
2
Sensor GPIO17
Theory:
A passive infrared sensor (PIR sensor) is an electronic sensor that measures infrared (IR) light
radiating from objects in its field of view. They are most often used in PIR-based motion detectors. PIR
sensors are commonly used in security alarms and automatic lighting applications. PIR sensors detect
general movement, but do not give information on who or what moved.
A PIR sensor can detect changes in the amount of infrared radiation impinging upon it, which
varies depending on the temperature and surface characteristics of the objects in front of the sensor.
When an object, such as a person, passes in front of the background, such as a wall, the temperature at
that point in the sensor's field of view will rise from room temperature to body temperature, and then
back again. The sensor converts the resulting change in the incoming infrared radiation into a change in
the output voltage, and this triggers the detection. Objects of similar temperature but different surface
characteristics may also have a different infrared emission pattern, and thus moving them with respect
to the background may trigger the detector as well.
Procedure:
Perform basic setup by connecting monitor, keyboard and mouse to the Raspberry Pi.
Connect 5V DC power adaptor to the MGTechSolution Raspberry Pi Target board.
Connect separate DC power adaptor to the Raspberry Pi attached to the Target board.
Switch on both the power adaptor and wait until Raspberry Pi starts.
Go to Programming menu and select Thonny Python IDE.
Click on New to open new file and write the program.
After completion of writing program, save file with .py extension.
Make necessary connections to connect the PIR sensor to the GPIO pins of the Raspberry Pi in
“Raspberry Pi GPIO section”.
Click on Run button to Run the program in Thonny Python IDE.
Observe the output.
Click Stop button to stop execution of the program.
Flowchart:
Start
is NO
PIR ==
1
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN)
GPIO.setup(4, GPIO.OUT)
while True:
button_state = GPIO.input(17)
if button_state == True:
GPIO.output(4, False)
print('Motion Detected...')
while GPIO.input(17) == True:
time.sleep(0.2)
else:
GPIO.output(4, True)
Applications of PIR motion Sensor: (Student can search & write application here)
Result: Interfacing and programming of Raspberry Pi for motion detection using PIR sensor is
successfully studied, tested and observe the output.
Teacher’s Sign.
*************