awwanaggisch
Published

IoT Growbox Controler

Send the sensor values ​​to the Arduino IoT cloud and conveniently control the irrigation remotely

IntermediateFull instructions provided2 hours599
IoT Growbox Controler

Things used in this project

Hardware components

Arduino MKR WiFi 1010
Arduino MKR WiFi 1010
×1
Arduino MKR Connector Carrier
×1
Capacitive Soil Moisture Sensor V 1.2
×4
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
5V Relay Module KY-019
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Seeed Studio GROVE Oled Display 0,96 inch I2C
×1
Unbuckled Grove Cable 1m/2m/50cm/20cm/10cm
M5Stack Unbuckled Grove Cable 1m/2m/50cm/20cm/10cm
×8
Jumper wires (generic)
Jumper wires (generic)
×1
Isolation Spray
×1

Software apps and online services

Arduino IoT Cloud
Arduino IoT Cloud

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Mini Side Cutter, 120mm Length with 25mm Jaw Capacity
Mini Side Cutter, 120mm Length with 25mm Jaw Capacity

Story

Read more

Schematics

GrowboxControler (shematic)

Structure and connection of the components

Variables

Define variables for the IoT dashboard

IoT Dashboard

Set up charts and displays in the cloud

Code

GrowboxControler (Sketch)

Arduino
With this code snippet the magic happens...
#include "thingProperties.h"
#include <EduIntro.h>
#include <NewPing.h>
#include <Wire.h>
#include <SeeedOLED.h>

#define LEVELFULL 32
#define LEVELEMPTY 32
#define VOLUME 25

#define trigPin  6
#define echoPin  7
#define MAX_DISTANCE 100

float duration;
NewPing sonar(trigPin, echoPin, MAX_DISTANCE);

int moist1Pin = A1;
int moist2Pin = A2;
int moist3Pin = A3;
int moist4Pin = A4;

int taster = 4;
int tasterstatus = 0;

float M1;
float M2;
float M3;
float M4;
float HUM;
float TMP;

DHT11 dht11(D1);
 
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); 
  
//Start I2C Communication for OLED Display
Wire.begin();
SeeedOled.init(); //initialze SEEED OLED display
SeeedOled.clearDisplay(); //clear the screen and set start position to top left corner
SeeedOled.setNormalDisplay(); //Set display to normal mode
SeeedOled.setPageMode(); //Set addressing mode to Page Mode

//Set digital pin D2 as an output
pinMode(2, OUTPUT);
  
//Set digital pin D4 as an input
pinMode(taster, INPUT);
  
// Defined in thingProperties.h
initProperties();
 
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
//Get Cloud Info/errors , 0 (only errors) up to 4
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();

//Wait to get cloud connection
while (ArduinoCloud.connected() != 1) {
  ArduinoCloud.update();
  delay(500);
  }
}
 
void loop() {
  //Update the Cloud
  ArduinoCloud.update();
  
 
  //read raw moisture1 value
  float raw_moisture1 = analogRead(moist1Pin);
  
 
  //map raw moisture1 to a scale of 0 - 100
  moisture1 = map(raw_moisture1, 205, 471, 100, 0);
  
  
   //read raw moisture2 value
  float raw_moisture2 = analogRead(moist2Pin);
  
 
  //map raw moisture2 to a scale of 0 - 100
  moisture2 = map(raw_moisture2, 215, 480, 100, 0);


  //read raw moisture3 value
  float raw_moisture3 = analogRead(moist3Pin);
  
 
  //map raw moisture3 to a scale of 0 - 100
  moisture3 = map(raw_moisture3, 220, 505, 100, 0);


  //read raw moisture4 value
  float raw_moisture4 = analogRead(moist4Pin);
  
  //map raw moisture4 to a scale of 0 - 100
  moisture4 = map(raw_moisture4, 200, 456, 100, 0);
  
  //read temperature and humidity
  dht11.update();
  temperature = dht11.readCelsius();
  humidity = dht11.readHumidity();
  
  // Level monitoring with ultrasonic sensor
  // Waiting time between pings (about 20 pings/sec). not less than 29ms!
  delay(50);
  //Measurement with averaging
  int iterations = 5;
  //duration = sonar.ping() without averaging
  duration = sonar.ping_median(iterations);
  //Distance in cm
  int distance = int((duration / 2) * 0.0343);
  //Calculate level
  int levelact = (LEVELEMPTY - distance);
  //Calculate level in Percent
  levelpercent = (levelact * 100 / LEVELFULL);
  
  //Button configuration to switch on the Oled display
  tasterstatus = digitalRead(taster);

  M1 = map(raw_moisture1, 205, 471, 100, 0);
  M2 = map(raw_moisture2, 215, 480, 100, 0);
  M3 = map(raw_moisture3, 220, 505, 100, 0);
  M4 = map(raw_moisture4, 200, 456, 100, 0);
  HUM = dht11.readHumidity();
  TMP = dht11.readCelsius();
  
  if (tasterstatus == HIGH)//Button is activated - Oled outputs sensor values
  { 
  SeeedOled.setTextXY(0,11); //Set the cursor to Xth Page, Yth Column
  SeeedOled.putString("Box1"); //Print the string
  SeeedOled.setTextXY(1,0); //Set the cursor to Xth Page, Yth Column
  SeeedOled.putString("TMP "); //Print the string
  SeeedOled.putFloat(TMP); //Print the value
  SeeedOled.putString(" C"); //Print the string
  SeeedOled.setTextXY(2,0); //Set the cursor to Xth Page, Yth Column
  SeeedOled.putString("RLH "); //Print the string
  SeeedOled.putFloat(HUM); //Print the value
  SeeedOled.putString(" % "); //Print the string
  SeeedOled.setTextXY(4,0); //Set the cursor to Xth Page, Yth Column
  SeeedOled.putString("M_1 "); //Print the string
  SeeedOled.putFloat(M1); //Print the value
  SeeedOled.putString(" % "); //Print the string  
  SeeedOled.setTextXY(5,0); //Set the cursor to Xth Page, Yth Column
  SeeedOled.putString("M_2 "); //Print the string
  SeeedOled.putFloat(M2); //Print the value
  SeeedOled.putString(" % "); //Print the string  
  SeeedOled.setTextXY(6,0); //Set the cursor to Xth Page, Yth Column
  SeeedOled.putString("M_3 "); //Print the string
  SeeedOled.putFloat(M3); //Print the value
  SeeedOled.putString(" % "); //Print the string
  SeeedOled.setTextXY(7,0); //Set the cursor to Xth Page, Yth Column  
  SeeedOled.putString("M_4 "); //Print the string
  SeeedOled.putFloat(M4); //Print the value
  SeeedOled.putString(" % "); //Print the string
  
  delay(30000); //Oled stays activated for 30 seconds
  
  SeeedOled.clearDisplay(); //Oled at rest
 
  } 
  else
  {
  SeeedOled.clearDisplay();//Oled at rest
  } 

}
/*
  Since Pumpe is READ_WRITE variable, onPumpeChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onPumpeChange()  {
  //Turn pump on or off
  if(pumpe){
    digitalWrite(2, HIGH);
  }
  else{
    digitalWrite(2, LOW);
    }
  }

Credits

awwanaggisch

awwanaggisch

0 projects • 1 follower

Comments