Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the GPIO library for Raspberry Pi.
Raspberry Pi
import [1] as GPIO
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated libraries like 'time' or 'os'.
Using 'gpiozero' which is a different GPIO library.
✗ Incorrect
The RPi.GPIO library is used to control GPIO pins on Raspberry Pi.
2fill in blank
mediumComplete the code to set GPIO pin 18 as an output pin.
Raspberry Pi
GPIO.setmode(GPIO.BCM)
GPIO.setup([1], GPIO.OUT) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong pin numbers like 17 or 22.
Not setting the pin as output.
✗ Incorrect
Pin 18 is set as output to control the water pump.
3fill in blank
hardFix the error in the code to read moisture sensor value from pin 23.
Raspberry Pi
GPIO.setup(23, GPIO.IN) moisture = GPIO.[1](23)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'output' instead of 'input'.
Using non-existent methods like 'read' or 'input_read'.
✗ Incorrect
Use GPIO.input(pin) to read digital input from a pin.
4fill in blank
hardFill both blanks to turn on the water pump when soil is dry.
Raspberry Pi
if moisture [1] 0: GPIO.output([2], GPIO.HIGH)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '=='.
Using wrong pin number for pump.
✗ Incorrect
If moisture sensor reads 0 (dry), turn on pump at pin 18.
5fill in blank
hardFill both blanks to create a dictionary of sensor readings with pin as key and value as moisture.
Raspberry Pi
sensor_data = {[2]: [1] for [3] in [23, 24, 25]} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using list brackets instead of dictionary braces.
Using wrong variable names.
✗ Incorrect
This dictionary comprehension reads moisture from pins 23, 24, and 25.