Professional Documents
Culture Documents
Activity Handbook - Introduction To Electronics & Basic IoT Principles
Activity Handbook - Introduction To Electronics & Basic IoT Principles
Activity Handbook - Introduction To Electronics & Basic IoT Principles
Activity Handbook
Activity: Programming PIR module
from time import sleep
from pymata_aio.pymata3 import PyMata3
from pymata_aio.constants import Constants
board = PyMata3(arduino_wait =2)
# declare a variable to hold the PIR pin number that you will connect to.
# declare the mode of the pin ‘PIR’ that we declared in the previous step.
board.set_pin_mode(___,_____)
try:
while True:
# declare a variable to hold the readings and read the input value
value = _______________(__)
print ("reading is: ", value)
#introduce delay of 1 second
except KeyboardInterrupt:
print("\nDone")
board.shutdown()
try:
while True:
board.digital_write(LED,1)
#introduce delay of 0.5 second
#turn the LED OFF
#introduce delay of 0.5 second
except KeyboardInterrupt:
board.shutdown()
print("\n done")
#declare a variable to hold the Pushbutton pin number that you will connect to.
#declare a variable to hold the LED pin number that you will connect to.
# declare the mode of the pin ‘LED’ that we declared in the previous step
board.set_pin_mode(___,___________)
# declare the mode of the pin ‘Pushbutton’ that we declared in the previous step
board.set_pin_mode(___,___________)
try:
while True:
# declare a variable to hold the readings and read the input value
value = _______________(__)
if value == 1:
#turn the LED ON
else:
#turn the LED OFF
except KeyboardInterrupt:
print("\nDone")
board.shutdown()
#declare a variable to hold the LDR pin number that you will connect to.
#declare a variable to hold the LED pin number that you will connect to.
# declare the mode of the pin ‘LED’ that we declared in the previous step
board.set_pin_mode(___,___________)
# declare the mode of the pin ‘LDR’ that we declared in the previous step
board.set_pin_mode(___,___________)
try:
while True:
# declare a variable to hold the readings and read the input value
value = _______________(__)
if value < 200:
#turn the LED ON
else:
#turn the LED OFF
except KeyboardInterrupt:
print("\nDone")
board.shutdown()
Lsensor = 4
#Initialise the pin connection for the following devices using the given variable names:
board.set_pin_mode(Lsensor, Constants.INPUT)
# Initialize the connection mode for the following pins:
board.set_pin_mode(Msensor, Constants.INPUT)
board.set_pin_mode(Rsensor, Constants.INPUT)
board.set_pin_mode(MOTORLEN, Constants,PWM)
board.set_pin_mode(MotorL1, Constants.OUTPUT)
board.set_pin_mode(MotorL2, Constants.OUTPUT)
board.set_pin_mode(MotorR1, Constants.OUTPUT)
board.set_pin_mode(MotorR2, Constants.OUTPUT)
board.set_pin_mode(MOTORREN, Constants,PWM)
try:
while True:
Rvalue = board.digital_read(Rsensor)
Mvalue = board.digital_read(Msensor)
Lvalue = board.digital_read(Lsensor)
# read the value from the IR sensors given in the table below.
def forward():
board.digital_write(MotorR1, 1)
board.digital_write(MotorR2, 0)
board.analog_write(MotorRen, 255)
board.digital_write(MotorL1, 1)
board.digital_write(MotorL2, 0)
board.analog_write(MotorLen, 255)
def STOP:
board.digital_write(MotorR1, 0)
board.digital_write(MotorR2, 0)
board.analog_write(MotorRen, 0)
board.digital_write(MotorL1, 0)
board.digital_write(MotorL2, 0)
board.analog_write(MotorLen, 0)
Complete the following table for the IR sensors readings in the different scenarios. The first
scenario is done for you:
IR sensor state
except KeyboardInterrupt:
print(“\nDone”)
board.shutdown()