
Connected objects have applications in many sectors, and agriculture is one of the most benefiting from the benefits of the Internet of Things.
This project describes the application of IoT (Internet of Things) in agriculture. In this environment we take measurements of the humidity of the soil of a plant.
Monitoring of the parameter around this process (information provided by the soil sensor) is done using open source tools and resources such as ESP32 and ThingSpeak. We read the sensor data in real time on the internet through a web page and also on the graphs in ThingSpeak.
This work is done using an ESP32 microcontroller which will send all information via WIFI concerning the environment of our plant, to ThingSpeak.
Soil moisture sensor
Connecting wires
Test plate
Wifi network
To perform the assembly, you can connect:
for the soil sensor:
pin S to pin D34 of the ESP32 board
pin (+) to pin 3.3V of the ESP32 board
pin (-) to the GND pin of the ESP32 board
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
from simple import MQTTClient import network import time from time import sleep from machine import Pin,ADC import dht WiFi_SSID = "username" WiFi_PASS = "password" SERVER = "mqtt.thingspeak.com" client = MQTTClient("umqtt_client", SERVER) CHANNEL_ID = "*************" WRITE_API_KEY = "*************" pin_sol = ADC(Pin(34)) pin_sol.atten(ADC.ATTN_11DB) def do_connect(): wlan = network.WLAN(network.STA_IF) wlan.active(True) if not wlan.isconnected(): print('connecting to network...') wlan.connect(WiFi_SSID, WiFi_PASS) while not wlan.isconnected(): pass print('network config:', wlan.ifconfig()) do_connect() time.sleep(3) topic = "channels/" + CHANNEL_ID + "/publish/" + WRITE_API_KEY while True: humidite_value = pin_sol.read() payload = "field1="+str(humidite_value) client.connect() client.publish(topic, payload) #send temperature and humidity values to thingspeak.com client.disconnect() time.sleep(60) |
Remarque: il faut importer la bibliothèque suivante: simple.py