We built our sensor to be able to track the baby tea tree we have in our office, but this IoT sensor setup is a great template for building your own IoT sensor and tracking data that’s important to you.
The IoT Computer components:
For our project we used the following sensors, but the ADC Expansion is flexible and supports many analog sensors:
- Temperature Sensor
- Light Intensity Sensor
- 1kΩ resistor, a small breadboard, and some jumper wires
The wiring with the ADC Expansion is very straight-forward: connect each sensor’s signal, power, and ground to the ADC Expansion. Each sensor should be connected to a different input channel on the ADC Expansion.
Since our light sensor is based on a photoresistor, we’ll need to make a voltage divider to sample the light intensity. See our guide on using a photoresistor for details.
Position your IoT sensors so you can track the data you’re interested in. We wanted to be able to keep an eye on our office tea tree:
Access your Omega’s command line, make sure you’re connected to the internet, and run the following:
opkg update
opkg install python-light python-adc-exp
The Python ProgramThe program will first instantiate an object to interact with the ADC Expansion, and then it will run an infinite loop that will read the voltage from each sensor, convert it to meaningful measurements for each sensor, and display the measurements.
Create a file iotSensor.py
on your Omega and populate it with the code provided below.
import time
import os
# Import the ADC Expansion module.
from OmegaExpansion import AdcExp
# create ADC Expansion object
adc = AdcExp.AdcExp()
#infinite loop to read sensors and display data
while 1:
# read ADC channels
a0 = adc.read_voltage(0)
a1 = adc.read_voltage(1)
# a2 = adc.read_voltage(2)
a3 = adc.read_voltage(3)
# convert temperature sensor voltage to temperature
temp = (a0 - 0.5) * 100
# convert soil sensor voltage to percentage
soil = (a1 / 5) * 100
# convert light sensor voltage to lux
rPhoto = 5.0 / a3 * 1000 - 1000
lux = 500/(rPhoto/1000)
# clear screen
os.system('cls' if os.name == 'nt' else 'clear')
# write sensor readings to screen
print('''
Temperature\t| %.02f C
Soil Moisture\t| %.02f %%
Light Intensity\t| %d lux
'''%(temp, soil, lux))
#wait half a second
time.sleep (0.5)
Running the ProgramLet’s run the Python program by entering python iotSensor.py
into the command line. You will see something like this:
The sensor readings will update twice a second, providing sensor real-time data! Once your data is in the cloud, you create dashboards to visualize the measurements or take actions based on the readings.
Comments