Elmin Delibašić
Published © GPL3+

SORACOM: Smart Agriculture

Smart agriculture is very topical these days, so I will give you a conceptual solution for Smart Agriculture with SORACOM and devices.

AdvancedFull instructions providedOver 2 days1,058

Things used in this project

Hardware components

SORACOM Air Global IoT SIM
SORACOM Air Global IoT SIM
×1
Raspberry Pi Zero Wireless
Raspberry Pi Zero Wireless
×1
Huawei E303
Huawei E303
×1
Grove - Barometer Sensor (BMP280)
Seeed Grove - Barometer Sensor (BMP280)
×1
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
SparkFun Soil Moisture Sensor (with Screw Terminals)
SparkFun Soil Moisture Sensor (with Screw Terminals)
×1
Ceramic Capacitive Rain Sensor
Telecontrolli Ceramic Capacitive Rain Sensor
×1
Relay Module (Generic)
×1
Water Valve
×1
Battery Holder, 18650 x 1
Battery Holder, 18650 x 1
×1
TP4056
×1
Solar Panel 6V
×1
Diode 1n4148
×1

Software apps and online services

Raspbian
Raspberry Pi Raspbian
SORACOM Air IoT Connectivity Platform
SORACOM Air IoT Connectivity Platform
SORACOM Harvest
SORACOM Harvest
SORACOM Lagoon
SORACOM Lagoon

Story

Read more

Schematics

Full scheme

Solar Power System

Code

soracom_smart_agriculture.py

Python
import RPi.GPIO as GPIO
import time
import Adafruit_DHT
import json
import sys, requests

import board
import busio
import digitalio
import adafruit_bmp280

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
bmp_cs = digitalio.DigitalInOut(board.D5)
bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs)
bmp280.sea_level_pressure = 1013.25

pin_dht = 14
pin_soil = 15
pin_rain = 18
pin_pump = 21
n = 1

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(pin_dht, GPIO.IN)
GPIO.setup(pin_soil, GPIO.IN)
GPIO.setup(pin_rain, GPIO.IN)
GPIO.setup(pin_pump, GPIO.OUT)

while 1:
		h, t = Adafruit_DHT.read_retry(11, pin_dht)
		soil_data = GPIO.input(pin_soil)
		rain_data = GPIO.input(pin_rain)

		t_bmp = round(bmp280.temperature, 2)
		p = round(bmp280.pressure, 2)
		a = round(bmp280.altitude, 2)


		if (soil_data == 0):
				GPIO.output(pin_pump, GPIO.HIGH)
				pump_data = 0
		else:
				if (rain_data == 1):
						GPIO.output(pin_pump, GPIO.LOW)
						pump_data = 1
				else:
						GPIO.output(pin_pump, GPIO.HIGH)
						pump_data = 0



		if (rain_data == 1):
				rain = 0
		else:
				rain = 1


		print (str(n) + ". Temperature: " + str(t_bmp) +"C, Humidity: "+ str(h) + "%, Pressure: "+ str(p) + "hPa, Soil Moisute: " + str(soil_data)+ ", Rain: " + str(rain)  + ", Altitude: " + str(a) + " meters, (Pump ON=1/OFF=0): " + str(pump_data))

		headers = {'Content-Type': 'application/json'}
		payload = {'temperature': t_bmp, 'humidity': h, 'soil_moisture': soil_data, 'rain_data': rain, 'pressure': p, 'altitude': a, 'pump_on_off': pump_data }
		try:
				r = requests.post('http://harvest.soracom.io', data=json.dumps(payload), headers=headers, timeout=5)
		except requests.exceptions.ConnectTimeout:
				print ("ERROR: connection timeout. Is 3G connection online?")
				sys.exit(1)
		if r.status_code == 400:
				print ("ERROR: failed to submit data. Did you enable Harvest for your SIM?")
				sys.exit(1)
		print
		n=n+1
		time.sleep(2)

Credits

Elmin Delibašić

Elmin Delibašić

2 projects • 34 followers
Elmin Delibašić - Electrical Engineering Student (Department of Telecommunications)

Comments