Skip to content

Soil Moisture Sensor Wireling Python Tutorial

TinyCircuits Soil Moisture Sensor Wireling product photo

This tutorial will show you how to acquire moisture readings from the Soil Moisture Sensor Wireling.


Technical Details

This Wireling features the ATtiny25, a high performance, low-power AVR 8-bit controller. Moisture is detected using capacitance to measure dielectric permittivity of the surrounding medium.

Technical Details

ATtiny25 specs

  • High performance, low-power AVR 8-bit microcontroller
  • Advanced RISC Architecture
  • Non-volatile program and data memories

TinyDuino Power Requirements

  • Voltage: 3.0V - 5.5V 
  • Current:
    • 300µA (Active Mode)
    • 0.1µA  (Power-down Mode)

Pins Used

  • A5/SCL - I2C Serial Clock line
  • A4/SDA - I2C Serial Data line

Dimensions

  • 10mm x 10mm (.394 inches x .394 inches)
  • Max Height (from the lower bottom of Wireling to upper top Wireling Connector): 3.70mm (0.15 inches)
  • Weight: 1 gram (.04 ounces)

Notes

  • You can also use this board without the TinyDuino – modifying the connecting cable by removing the opposite connector and stripping/tinning the wires, you can solder the connector cable to any other microcontroller board of your choice!

Materials

Hardware

Required Software


Hardware Assembly

Plug your Wireling into the port you plan on using! The default in the included program is port 0.

If you want to use a different port, you just need to change the port value in the program mentioned later.


Programming

Install the necessary Python package:

pip3 install tinycircuits-attiny25

Then you can download (above under Software) the Soil Moisture Sensor Wireling example:

moisture-example.py
# Soil Moisture Sensor Wireling Example
# This example will read the print out the moisture and temperature
# Written by: Laverena Wienclaw for TinyCircuits

import tinycircuits_wireling
import time
import tinycircuits_attiny25

wireling = tinycircuits_wireling.Wireling()
wireling.selectPort(0)

attiny25 = tinycircuits_attiny25.ATtiny25()

while True:
     attiny25.readMoisture()
     attiny25.readTemp()
     print("Moisture: %.2f" % attiny25.moisture)
     print("Temp DegC: %.2f" % attiny25.temp)
     time.sleep(0.5)


Run Program

Navigate in the terminal to the directory with the file parent to the examples folder and run:

python3 moisture-example.py

The program will print the moisture levels on a scale of 0-100%, and the temperature in degrees Celsius:

Moisture: 87.92
Temp DegC: 28.00
Moisture: 92.83
Temp DegC: 29.32

Downloads


Contact Us

If you have any questions or feedback, feel free to email us or make a post on our forum. Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it.

Thanks for making with us!