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.

 Materials Required

For this project they used the following sensors, but the ADC Expansion is flexible and supports many analog sensors:

Physical Setup

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.

Physical_Setup_Demo


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:

Demo_Setup_In_Plant

Install Python

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 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:

IoT_Sensor_Output

The sensor readings will update twice a second, providing sensor real-time data!

Previous article Controlling an LED using proximity sensing and the Touch Board
Next article Introducing the Makyu FormBox

Check out our latest products...

Sparkfun Triad Spectroscopy Sensor - As7265X (Qwiic) (Sen-15050) - Infra Red
Tfmini - Micro Lidar Module (Qwiic) (Sen-14786) - Infra Red
Qwiic To Grove Cable (Spx-14739) - Cables And Adapters

Qwiic To Grove Cable (SPX-14739)

£1.99 inc VAT
£1.66 ex VAT
Grove - 6-Axis Accelerometer & Gyroscope (Bmi088) - Acceleration
Grove - Step Counter (Bma456) - Acceleration

Grove - Step Counter (BMA456)

£7.00 inc VAT
£5.83 ex VAT
Conductive Nylon Fabric Tape - 8Mm Wide X 10 Meters Long (Id:3960) - Conductive Ink
Conductive Nylon Fabric Tape - 5Mm Wide X 10 Meters Long (Id:3961) - Conductive Ink