£12.49 ex VAT
How To Build IoT Sensors Using Python
Our partners over at Onion have released a tutorial we though we would share with you where you will learn how to build an IoT sensor using Python and the Omega2 ADC Expansion! They built their sensor to be able to track the baby tea tree they have in their office, but this IoT sensor setup is a great template for building your own IoT sensor and tracking data that’s important to you.
For this project they used the following sensors, but the ADC Expansion is flexible and supports many analog sensors:
- Temperature Sensor
- Soil Moisture 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 the light sensor is based on a photoresistor, you’ll need to make a voltage divider to sample the light intensity.
Position your IoT sensors so you can track the data you’re interested in. In this project they wanted to be able to keep an eye on the office tea tree:
Access your Omega’s command line, make sure you’re connected to the internet, and run the following:
opkg install python-light python-adc-exp
The Python Program
The 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 this code:
Running the Program
Let’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!