guardian

Public

@thatsbhaskar

Share guardian

Check access before sharing the link.

Who can open this board

Anyone can open this board. No sign-in is required.

This link opens the latest version. Copying it does not grant additional access.

Loading…

README

AHS logo

Guardian

Guardian is an advanced, fully automated hydroponics system designed to optimize plant growth and maximize yield. Utilizing micro-controllers and pH fuzzy logic control, it ensures precise nutrient delivery, enables remote monitoring, and achieves remarkable water savings while increasing crop productivity.


Open in Visual Studio Code

Table of contents

Render of Guardian

Parameters Measured

  • Temperature (DHT)
  • Humidity (DHT)
  • Tank Water Level
  • Reservoir Water Level
  • Plant Motor
  • Reservoir Motor
  • Mist Motor
  • Lighting

DataBase

  • Any DataBase can used to store the Data and control the System Remotely
  • For this project I have used FireBase - A Realtime DataBase

A Few Pictures of FireBase

Controllable Parameters

Motors and Light

There are two Modes for Controlling the Motors and lighting

DigitsStatusMode
0OffManual Override Mode ON
1OnManual Override Mode ON
2-Manual Override Mode OFF

Humidity and Temperature

We can Manually Control/ Automate the Threshold Values of Humidity and Temperature as per the crop

Light Interval

We can Manually control/ Automate the Intervals of Lighting to control the Temperature as per the requirements of the crop

Motor Running Duration

We can Manually control/ Automate the Intervals of running Plant Motor for regular watering as per the requirements of the crop

The Schematic diagram

The Schematic and PCB designs are made using KiCAD. Find the files here: KiCad_PCB_design

The Schematic Diagram of Master board

  • The Master board has an ESP32, DS1307 RTC clock, AT24C512 EEPROM and an I2C LCD display.
  • The Master board has a JST connecter port to connect to slave board.

The Schematic of Slave Board

  • The slave board has an Arduino Nano, DHT11 sensor, 4 relays.
  • The master board and slave board are connected with I2C bus.

PCB Layout

The PCB Layout of Master board

The PCB Layout of Slave board

Building the Hardware

Master board

Total Setup Overview

Find more pictures in Images folder

Using I2CSB library

This Arduino compatible library is made to simplify the communication paradigm that happens between master ESP32 and slave Arduino Nano.

I2CSB stands for I2C Slave board

The slave arduino nano does the following:

  • controls 4 relays named as
  1. Bucket Motor connected to pin 10
  2. Plant Motor connected to pin 9
  3. Mist Motor connected to pin 7
  4. Light Pin connected to pin 6
  • Is connected to a DHT11 Temperature and Humidity sensor on pin 4.
  • Has two set of water level sensors and each water level sensor can detect 3 distinct points in the used buckets.

You can fetch the slave code here Arduino_slave.ino

The Master ESP32 can access these function using the I2CSB Library. As the name suggests the communication happens in I2C protocol.

How to add the library

To use the library just navigate to I2CSB and download it as zip file. Later in arduino IDE add this library using library manager and get started with the library using examples.

How to use the functions in the library

  1. First instantiate the class I2CSB with a slave address
#define Slave_address 0x2F
I2CSB DB1(Slave_address);
  1. Initialize the I2C communication by calling Wire.begin()

  2. The library has following functions

Function nameWhat is returnedreturn typeArguments
1. isConnected()true if slave is connectedboolno arguments
2. getLevel()Level encoded in single bytebyteno arguments
3. getTemperature()Temperatureintno arguments
4. getHumidity()Humidityintno arguments
5. setOutputs()True if the outputs are set correctly False if fails to setbool4 bool variables

Handling the Errors and Miscommunication

The library also can monitor communication error or Miscommunication took place. This is how:

  1. For isConnected() function the master sends a request to get water level. If there is no error in the received information then the function returns True. In the event of death of slave or the slave is not connected or there is a communication error the function returns False.
  2. For getLevel() function the return type is byte and the encoded level information in the byte is as follows x LA2 LA1 LA0 0 LB2 LB2 LB0 Here LA2,1,0 are points in sensor A and LB2,1,0 are points in Level B sensor. The x bit carries the error information. If there is no error in the communication then x = 1 else x = 0.
  3. For getTemperature() function then return type is integer. And the DHT11 sensor can measure the temperatures between 0 to 60degC with a resolution of 1degC. So the information we get out of the sensor can never hit negative temperature. So the function returns -10 if there is any error and returns value between 0 and 60 if there is no error.
  4. Similarly for getHumidity() function, the return type is int and has values between 20 to 80. so if there is any error then the returned value will be -10.
  5. For setOutputs() the return value is True if there is no error in communication as well as the outputs are set as expected. The arguments in setOutputs() function is in this order setOutputs(BucketMotor, PlantMotor, MistMotor, LightPin)

The communication definition

  • The communication is built on I2C protocol.
  • The master sends a byte contains the function the slave has to performs along with the arguments encoded in the single byte.
  • The master requests the slave 200 milliseconds later to send the fetched data/ performed action feedback encoded in 3 bytes as follows.
Function nameSent ByteReceived bytes
2. getLevel()0xAA0xAA 0xYY 0xYY
3. getTemperature()0xCA0xCA 0xYY 0xYY
4. getHumidity()0x5c0x5C 0xYY 0xYY
5. setOutputs()0x600x60 0xYY 0xYY
1. isConnected()0xAA0xAA 0xYY 0xYY
  • The first byte is the data that is sent by master to slave so that the master can verify that slave performed correct action. and there was no miscommunication happened.
  • The second two bytes are identical. If they match then the master decides that the information received is correct and and proceeds to decode the bytes.
  • The isConnected() function is same as getLevel() function with a different data type. Because I was lazy to write a new function for that purpose.
  • The example code can be found here Example_code.ino.

This library can be used as a base to make any type of simple arduino I2C slave device.

Using EEPROM Database

Find the database library here DataBase.

The data structure:

  • The following data is stored in EEPROM Every minute.
DataBytes takenRange
Day, Hour, Minute in the month2 bytes44640
Temperature1 byte0 to 60 degC
Humidity1 byte20 to 80%
Level Array1 byte0x00 to 0x77
  • In a nutshell each data set consumes 5 bytes so the EEPROM can log the data for complete 9 days.
  • The pointer of next address to be written locally on EEPROM because if arduino restarts the local pointer on arduino will be lost and the new data is re-written on EEPROM.
  • The EEPROM used here is AT24C512 which can store 512 Kbits or 64 KBytes which are byte addressable. So the address value range is from 0x0000 to 0xFFFF which is exactly same size that an integer(2 bytes) takes in an Arduino.
  • Therefore the first two bytes in the EEPROM is reserved to write the address pointer.
  • The following table represents the data structure employed.
AddressData
0 , 1Address pointer
2 - 6Data set 1
7 - 11Data set 2
12 - 16Data set 3
(5n-3) - (5n+1)Data set n

Functions

The library offers following functions:

Function nameargumentsreturn value
storeAtEEPROM Object, Address, Day, Hour, Minute, Temperature, Humidity, Waterlevel arrayvoid type
resetAddressEEPROM Objectvoid
getDataAtEEPROM Object, Address, Data-literalData
getNextAddressEEPROM ObjectAddress of next Dataset to be written
resetAddressEEPROM Objectresets the address pointer to initial value

Usage

  • Include the library DataBase and I2C_EEPROM on arduino IDE.
  • create an I2C_eeprom object
I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC512);
  • Create a DataBase object
DataBase DB;
  • Begin the EEPROM object ee using ee.begin().

Control System

Sample of Guardian

License

Code released under the MIT License. Docs released under Creative Commons.

Comments

No comments yet. Be the first to ask about this board.

Ask about this board

Sign in to BoardRepo

New here? Signing in creates your account; there is no separate sign-up.