Darren ShenEvelyn Shen
Published

Smart Field Care System for Schools

On top of scheduled maintenance, multiple sensors and user override button generates greenest field and optimizing water usage

BeginnerFull instructions provided5 hours247
Smart Field Care System for Schools

Things used in this project

Hardware components

Hackster EEDU Kit - Getting started with Environmental Sensing
DFRobot Hackster EEDU Kit - Getting started with Environmental Sensing
×1
Normally Closed Electric Water Shut off Valve, Brass Electric Solenoid Magnetic Valve, Water Inlet Flow Switch Valve for Water Control, 0.02mpa~0.8mpa, 3/4 Inch DC 12V
×1
5x7 Acrylic Sheet Plastic
×1
Lithium Polymer Battery 3.7V 1100mAh
×1
12V 2A Power Supply AC Adapter
×1
USB Li Ion Battery Charger
Adafruit USB Li Ion Battery Charger
×1

Software apps and online services

Arduino IoT Cloud
Arduino IoT Cloud
Arduino Web Editor
Arduino Web Editor

Hand tools and fabrication machines

YIHUA 939D+ Digital Soldering Station
kingst logic analyzer LA1010

Story

Read more

Schematics

Smart field care system

There are two layers of boards. The top one is the FireBeetle 2 ESP32-E IoT Microcontroller with header to connect the bottom Gravity: IO Shield

Code

Smart field care system

Arduino
/*
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/293551c0-7060-4c9c-8f98-3a38bf2750c4

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  String moisture;
  float temperature;
  CloudSchedule schedule;
  bool start;
  bool status;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
/*!
  @file  read_data.ino
  @brief This demo shows how to get data of the SEN0500/SEN0501 sensor and outputs data through I2C or UART.
  @n Print the data returned by SEN0500/SEN0501 in the serial port monitor.
   @n connected table
   ---------------------------------------------------------------------------------------------------------------
      board   |             MCU                | Leonardo/Mega2560/M0 |    UNO    | ESP8266 | ESP32 |  microbit  |
       VCC    |            3.3V/5V             |        VCC           |    VCC    |   VCC   |  VCC  |     X      |
       GND    |              GND               |        GND           |    GND    |   GND   |  GND  |     X      |
       RX     |              TX                |     Serial1 TX1      |     5     |   5/D6  |  D2   |     X      |
       TX     |              RX                |     Serial1 RX1      |     4     |   4/D7  |  D3   |     X      |
   ---------------------------------------------------------------------------------------------------------------

   @copyright   Copyright (c) 2021 DFRobot Co.Ltd (http://www.dfrobot.com)
   @license     The MIT License (MIT)
   @author      [TangJie](jie.tang@dfrobot.com)
   @version     V1.0
   @date        2021-08-31
   @url         https://github.com/DFRobot/DFRobot_EnvironmentalSensor
*/
#include <DFRobot_EnvironmentalSensor.h>

DFRobot_EnvironmentalSensor environment(/*addr = */SEN050X_DEFAULT_DEVICE_ADDRESS, /*pWire = */&Wire);

//analog pin received moisture data
#define ANALOG_PIN_0 A0

//sensor calibrated range
const int AirValue = 3900;
const int WaterValue = 0;

//three levels - dry, moist, and wet
int intervals = (AirValue - WaterValue) / 3;
int soilMoistureValue = 0;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);

  //change digital pin to output for controlling relay
  pinMode(0, OUTPUT);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
  */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();

  Serial.begin(115200);
  while (environment.begin() != 0) {
    Serial.println(" Sensor initialize failed!!");
    delay(1000);
  }
  Serial.println(" Sensor  initialize success!!");

}

void loop() {
  ArduinoCloud.update();
  temperature = environment.getTemperature(TEMP_F);
  //humidity = environment.getHumidity();
  soilMoistureValue = analogRead(ANALOG_PIN_0);

  //convert raw analog input to three moisture level
  if (soilMoistureValue > WaterValue && soilMoistureValue < (WaterValue + intervals))
  {
    moisture = "Wet";
  }
  else if (soilMoistureValue > (WaterValue + intervals) && soilMoistureValue < (AirValue - intervals))
  {
    moisture = "Moist";
  }
  else if (soilMoistureValue < AirValue && soilMoistureValue > (AirValue - intervals))
  {
    moisture = "Dry";
  }

  //delay 500 millisecond
  delay(500);

}


/*
  Since Moisture is READ_WRITE variable, onMoistureChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onMoistureChange()  {

  // Add your code here to act upon Moisture change and temperature within
  // recommanded range
  if (moisture == "Dry" && temperature <= 95 && temperature >= 40) {
    //turn on sprinkler for 5 mins when ground is dry
    digitalWrite(0, HIGH);
    status = true;
    delay(300000);
    digitalWrite(0, LOW);
    status = false;
    delay(1000);
  }

}

/*
  Since Schedule is READ_WRITE variable, onScheduleChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onScheduleChange()  {
  // Add your code here to act upon Schedule change
  if (schedule.isActive()) {
    //don't turn on when ground is wet or too hot or too cold
    if (moisture != "Wet" || temperature > 95 || temperature < 40) {
      digitalWrite(0, HIGH);
      status = true;
    }
  } else {
    digitalWrite(0, LOW);
    status = false;
  }
}

/*
  Since Start is READ_WRITE variable, onStartChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onStartChange()  {
  // Add your code here to act upon Start change
  //turn on system when switch is on
  if (start == true) {
    digitalWrite(0, HIGH);
    status = true;
  } else {
    digitalWrite(0, LOW);
    status = false;
  }
}

Credits

Darren Shen

Darren Shen

4 projects • 3 followers
Pro Coder
Evelyn Shen

Evelyn Shen

2 projects • 2 followers
i love coding! coding is awesome!

Comments