Lab_2
Lab_2
Environment
• A computer running Python
• An Arduino
1
Acquiring Sensor Data
2
An Arduino Program
//reads a potentiometer and sends value over serialint sensor
4
Acquiring Sensor Data
# serial read using the Python
5
Acquiring Sensor Data
# a Python script to read the sensor
import serial
import time
6
Acquiring Sensor Data
# a Python script to read the sensor
time.sleep(2)
7
Acquiring Sensor Data
# Read and record the data
for i in range(50):
ser.close()
8
Displaying Sensor Data
# a Python script to display the collected data
for i in data:
print(i)
9
Displaying Sensor Data
# a Python script to display the collected data
for i in data:
print(i)
10
Visualizing Sensor Data
# a Python script to plot the collected data
plt.plot(data)
plt.xlabel('Time (seconds)’)
plt.ylabel('Potentiometer Reading’)
plt.show()
11
Visualizing Sensor Data
12
Assignment
# Write a Python script to
13