DesignSpark Electrical Logolinkedin
Menu Search
Ask a Question

Cypress Design Challenge - Electronics for Agriculture

Argo-Electronics: Field data collection. By: Srimanth Tenneti


When we are trying to build electronics for agriculture the most important parameters are robustness and efficiency.  This data collection board is a general-purpose board ready for agro-based projects. It uses an ATMEGA164PU an AVR 8 bit microcontroller. Having two serial interfaces this can be used for the Bluetooth mesh and also for long-range communication (e.g. LoRa).

Basic Idea

Field parameters like temperature, humidity, soil humidity, soil temperature, and barometric pressure are collected by hooking up these sensors to the board above.


Soil humidity sensor: DS1307 - RTC


BMP180 (Barometric Pressure)


DHT22 - (Humidity and Temperature)               LM35 - (Soil temperature) 


SPDT Relay for AC motor (irrigation)                                   LORA module


This device will have two modes:

  1. Standard mode: This will use the RTC to do activities like watering the field. When the device reaches a specified time, the relay switches on and the motors connected to it turn on irrigating the field. 
  2. Smart mode: This will use the sensors feed to water the field. 


The system will have 4 devices. Three of them will be called nodes (CYBT-213043 + data collection card) and will be placed at different ends of the field and the BLE mesh devices (CYBT-213043) will be placed along with the data collection cards. The devices would send data to each other via Bluetooth. As the card supports two serial ports, all the devices will also be connected to a central core (CYBT-213043 + LORA). Another LORA module will be connected to a Raspberry Pi 4 and the serial data will be collected. Then this data will be sent to Things speak cloud. The data collected will be read by Python via pyserial and will be sent to an SQLITE3 database for storage. 

The code for the data collection is below:

import sqlite3

import serial


def connect_db():

    conn = sqlite3.connect("Datalog_14.db")

    cur = conn.cursor()

    cur.execute("CREATE TABLE IF NOT EXISTS dht_data(temp REAL,humidity REAL,soil_temp REAL)")






def insert_dt(temp , humidity , soil_temp):

    conn = sqlite3.connect("Datalog_14.db")

    cur = conn.cursor()

    cur.execute("INSERT INTO dht_data VALUES (?,?,?)",(temp,humidity,soil_temp))




def view_dt():

    conn = sqlite3.connect("Datalog_14.db")

    cur = conn.cursor()

    cur.execute("SELECT * FROM dht_data")

    rows = cur.fetchall()


    return rows

serial_data = serial.Serial("SerialPORT",9600) # Enter the serial port being used. 


temp_log = []

humd_log = []

soil_temp_log = []

time_log = []

date_log = []


epochs = 5


for i in range(epochs):

    stch = str((serial_data.readline().strip()))

    temp = (serial_data.readline().strip())

    humd = (serial_data.readline().strip())

    soil_temp = (dht_data.readline().strip())

    endc = str((serial_data.readline().strip()))

    if(stch == "b'#'" and endc == "b'@'"):






        epochs = epochs + 1

Once the data is in the database it will be safe. It can be sent to cloud and it can be processed into graphs using the Bokeh library to get an HTML file. 

Data in the database

Every time we run system turns on the data is time-stamped and also we can identify the new incoming data cycle by a (0.0, 0.0, 0.0).

Graphs in ThingSpeak

Graphs using Bokeh library in Python

To find out about the climatic conditions I have built a small rest API project that uses online weather API and gets the data of a particular place. 

Weather API code :

#### Written by : Srimanth Tenneti  ####

from flask import Flask , jsonify   # Medium from web architecture

import requests # For talking to the web 

import re

import json

app = Flask(__name__)    # Creating an instance

# API   

response = requests.get( ""+ 'Pincode', 

                        headers={ "X-RapidAPI-Host": "", 

                                 "X-RapidAPI-Key": "Rapid API API key for weather API" }, )


print(response.status_code)   // To see status of HTTP request

js = json.loads(response.content) // Loading the JSON response

x = js['list'][0]['dt_txt']

y = js['list'][0]['main']['temp'] - 273

a = js['list'][0]['wind']

b = js['list'][0]['weather']

c = js['list'][0] ['main'] ['pressure']

weather_1 = [


          'Time'        : x ,

          'Temperature' :  y ,

          'Wind'        : a ,

          'Weather'     : b ,

          'Pressure'    : c    



@app.route('/weather_data',methods = ['GET'])   

def get_tasks():

    return jsonify({'weather':weather_1})

if __name__ == '__main__': = True,port = 1081)  #Deploy on



Raspberry Pi will be programmed with a special program that will take the data from the weather API and system data and it will compute the standard deviation and will also give some important parameters to the nodes like rain prediction and wind speed. 

So the nodes can intercommunicate and decide if they have to irrigate the field or not.

Optional Additions:

  1. Heavy wind warning system:
    A small addition to this system is a small warning system. If the wind speeds are high they may destroy the crops. So the data from the API will be used to set off buzzers set in the field connected to the node devices PWM pins. This will alert the farmers of some danger. Using Twilio or Snitch library in python multiple warning SMS will be sent warning the farmers of the coming danger. 
  2. Birds and Rodents driving system: Rodents and birds keep eating away farm produce. So using PIR motion sensors and the buzzers on the nodes we can drive away rodents and birds. Adding this feature in normal mode will enable the farmer to set the period of operation of this function using the RTC (DS1307). 


N.B. All the electronics will be enclosed in IP65 boxes to make the system waterproof. The batteries running the system (nodes -> coil cell for (CYBT-213043), 18650 for data collection card). These batteries can be recharged by adding a solar panel to the system.


In this way, I have built a robust system that connects to the cloud, uses BLE mesh technology and also transmits data for long distances in case of internet issues near the farm. 

My system uses weather APIs to get information like rain, wind speed and has provision for heavy wind, rodents and birds driving system. This system will help save time and energy of a farmer. 


I am an electronics and communication engineering student interested in IOT , AI , computer vision & VLSI. I also have knowledge of PCB design and bear metal programming of AVR and ARM devices.

22 Sep 2019, 11:10