0
0
Raspberry Piprogramming~10 mins

Home automation with relay modules in Raspberry Pi - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the GPIO library for Raspberry Pi.

Raspberry Pi
import [1]
Drag options to blanks, or click blank then click option'
ARPi.GPIO
Bgpiozero
Cwiringpi
Dserial
Attempts:
3 left
💡 Hint
Common Mistakes
Using gpiozero instead of RPi.GPIO for low-level pin control.
2fill in blank
medium

Complete the code to set GPIO pin 17 as an output.

Raspberry Pi
GPIO.setup([1], GPIO.OUT)
Drag options to blanks, or click blank then click option'
A18
B22
C27
D17
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing input pins instead of output pins.
3fill in blank
hard

Fix the error in the code to turn the relay ON by setting the pin LOW.

Raspberry Pi
GPIO.output(17, [1])
Drag options to blanks, or click blank then click option'
AGPIO.HIGH
BTrue
CGPIO.LOW
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.HIGH to turn the relay ON, which actually turns it OFF.
4fill in blank
hard

Complete the code to create a dictionary mapping relay names to their GPIO pins.

Raspberry Pi
relays = {[1]: pin for {{BLANK_3}} in ['relay1', 'relay2', 'relay3']}
Drag options to blanks, or click blank then click option'
A{
Bpin
Crelay
D}
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect dictionary syntax or variable names.
5fill in blank
hard

Fill all three blanks to turn all relays OFF by setting their pins HIGH.

Raspberry Pi
for pin in relays.values():
    GPIO.output([1], [2])
print([3])
Drag options to blanks, or click blank then click option'
Apin
BGPIO.HIGH
C"All relays are OFF"
DGPIO.LOW
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.LOW to turn relays OFF, which actually turns them ON.