0% found this document useful (0 votes)
39 views9 pages

IoT Lab 4 + 5

This document contains instructions for a lab assignment involving an Internet of Things project. Students are asked to work in groups of 5 and submit a report in PDF format that answers the questions and includes code snippets. The report must be submitted by the group leader before the deadline. The document provides details on 3 activities involving controlling LEDs and reading sensor data using an Arduino board connected to a Raspberry Pi.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views9 pages

IoT Lab 4 + 5

This document contains instructions for a lab assignment involving an Internet of Things project. Students are asked to work in groups of 5 and submit a report in PDF format that answers the questions and includes code snippets. The report must be submitted by the group leader before the deadline. The document provides details on 3 activities involving controlling LEDs and reading sensor data using an Arduino board connected to a Raspberry Pi.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

INTERNET OF THINGS – IT134IU

LAB 4 + 5
Instructions: Please follow the steps:
1 – Students work in groups. Please answer the questions clearly. Remember to include
your name and your student ID.
2 - Each group leader (ONLY the group leader, please!) submits the report in Pdf
format and videos before the deadline.

Group Name:
No ID Name No Contribution
1 ITITIU19055 Vo Huynh Huy Thinh
2 ITITIU20311 Trần Huỳnh Nhật Thi
3 ITITIU19056 Pham Ha Minh Thy
4 TITIU19023 Nguyen Hoang Linh
5 ITITIU19041 Nguyen Gia Phuc

1 /2
LAB 4
1. Activity 1
Paste the source code here!

2 /2
2. Activity 2
Paste the source code here!

3 /2
3. Activity 3
Paste the source code here!
import Tkinter # add Tkinter library
import pyfirmata # add py"rmata library
import time as wait # add time library

board = pyfirmata.Arduino('COM6')
wait.sleep(5) # delay of 5 Sec
led_Pin = board.get_pin('d:7:o') # connect led to pin 7 and used as output

def call_led_blink_pwm():
time_Period = time_Period_Entry.get()
time_Period = float(time_Period)
led_Brightness = brightness_Scale.get()

4 /2
led_Brightness = float(led_Brightness)
button.config(state=Tkinter.DISABLED)
led_Pin.write(led_Brightness/100.0)
print('LED brightness control') # print on terminal
wait.sleep(time_Period)
led_Pin.write(0) # make led_Pin to LOW
button.config(state=Tkinter.ACTIVE)

TOP = Tkinter.Tk()
time_Period_Entry = Tkinter.Entry(TOP, bd=7, width=30)
time_Period_Entry.pack()
time_Period_Entry.focus_set()
brightness_Scale = Tkinter.Scale(TOP, from_=0, to=100, orient=Tkinter.
VERTICAL)
brightness_Scale.pack()
button = Tkinter.Button(TOP, text="Start", command = call_led_blink_pwm)
button.pack()
TOP.mainloop()

import Tkinter # add Tkinter library


import pyfirmata # add py"rmata library
import time as wait # add time library

board = pyfirmata.Arduino('COM6')
wait.sleep(5) # delay of 5 Sec
led_Pin = board.get_pin('d:7:o') # connect led to pin 7 and used as output

def call_led_blink_pwm():
time_Period = time_Period_Entry.get()
time_Period = float(time_Period)
led_Brightness = brightness_Scale.get()

5 /2
led_Brightness = float(led_Brightness)
button.config(state=Tkinter.DISABLED)
led_Pin.write(led_Brightness/100.0)
print('LED brightness control') # print on terminal
wait.sleep(time_Period)
led_Pin.write(0) # make led_Pin to LOW
button.config(state=Tkinter.ACTIVE)

TOP = Tkinter.Tk()
time_Period_Entry = Tkinter.Entry(TOP, bd=7, width=30)
time_Period_Entry.pack()
time_Period_Entry.focus_set()
brightness_Scale = Tkinter.Scale(TOP, from_=0, to=100, orient=Tkinter.
VERTICAL)
brightness_Scale.pack()
button = Tkinter.Button(TOP, text="Start", command =
call_led_blink_pwm)
button.pack()
TOP.mainloop()

import tkinter as Tkinter # add Tkinter library


import pyfirmata # add pyfirmata library
import time as wait # add time library

board = pyfirmata.Arduino('COM6')
wait.sleep(5) # delay of 5 Sec
red_led_pin = board.get_pin('d:7:o') # connect led to pin 7 and used as
output
green_led_pin = board.get_pin('d:6:o') # connect led to pin 6 and used as
output

def start_button_press():
red_led_pin.write(red_led_Var.get())
green_led_pin.write(green_led_Var.get())
print('start...') # print on terminal

def stop_button_press():

6 /2
red_led_pin.write(0) # make pin 7 to HIGH
green_led_pin.write(0) # make pin 6 to HIGH
print('stop....') # print on terminal

TOP = Tkinter.Tk()
red_led_Var = Tkinter.IntVar()
red_CheckBox = Tkinter.Checkbutton(TOP, text="Red_LED_status",
variable=red_led_Var)
red_CheckBox.grid(column=1, row=1)
green_led_Var = Tkinter.IntVar()
green_CheckBox = Tkinter.Checkbutton(TOP,
text="Green_LED_status", variable=green_led_Var)
green_CheckBox.grid(column=2, row=1)
start_Button = Tkinter.Button(TOP, text="Start_button", command =
start_button_press)
start_Button.grid(column=1, row=2)
stop_Button = Tkinter.Button(TOP, text="Stop_button", command =
stop_button_press)
stop_Button.grid(column=2, row=2)
exit_Button = Tkinter.Button(TOP, text="Exit_button",
command=TOP.quit)
exit_Button.grid(column=3, row=2)
TOP.mainloop()

7 /2
8 /2
LAB 5
1. Activity 2

9 /2

You might also like