Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Pablo Zuloaga Betancourt
Published

POWAR Smart Garden Using WIO Terminal

A gardening system that uses Seeed Studio WIO Terminal and Grove Sensors to automate various aspects of plant care.

BeginnerFull instructions provided1 hour1,611
POWAR Smart Garden Using WIO Terminal

Things used in this project

Hardware components

Wio Terminal
Seeed Studio Wio Terminal
×1
Grove - Soil Moisture Sensor
Seeed Studio Grove - Soil Moisture Sensor
×1
Seeed Studio Grove - Temperature & Humidity Sensor (DHT11)
×1
Seeed Studio Wio-Terminal-Smart-Garden-Kit
This kit includes all the necessary components to carry out this project, so you can buy them separately or all together in this kit.
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Casing for puttign the WIO terminal on a plant

Soil Moisture Case UP (Modifyed)

Case Grove moisture sensor v1.0 by ChinoCamposg on Thingiverse: https://www.thingiverse.com/thing:4163229

Soil Moisture Sensor Down

Case Grove moisture sensor v1.0 by ChinoCamposg on Thingiverse: https://www.thingiverse.com/thing:4163229

Code

1 - WIO Internal Light sensor

Arduino
This code will let you read the WIO Terminal Integrated Light Sensor.
void setup() {
  // put your setup code here, to run once:
  
  // declare PinMode
  pinMode(WIO_LIGHT, INPUT);
  
  //Start serial communication
  Serial.begin(9600);
  
}

void loop() {
  // put your main code here, to run repeatedly:

  // declare a variable to store the read values
  int light = analogRead(WIO_LIGHT);
  
  // print in the serial monitor the sensor values 
  Serial.print("Light Value: ");
  Serial.println(light);

  // wait 1 second to read again
  delay(1000);

}

2 - WIO Terminal Integrated Buzzer

Arduino
This code will let you actuate the WIO Terminal Integrated Buzzer
    void setup() {
        pinMode(WIO_BUZZER, OUTPUT);
    }
 
    void loop() {
        analogWrite(WIO_BUZZER, 128);
        delay(1000);
        analogWrite(WIO_BUZZER, 0);
        delay(1000);
    }

3 - WIO Light to Buzz

Arduino
We are going to use the light sensor to activate the buzzer depending on the amount of light it gets.
void setup() {
  // put your setup code here, to run once:
  
  // declare PinMode
  pinMode(WIO_LIGHT, INPUT);
  pinMode(WIO_BUZZER, OUTPUT);
  
  //Start serial communication
  Serial.begin(9600);
  
}

void loop() {
  // put your main code here, to run repeatedly:

  // declare a variable to store the read values
  int light = analogRead(WIO_LIGHT);
  
  // print in the serial monitor the sensor values 
  Serial.print("Light Value: ");
  Serial.println(light);
  
  if (light > 200) {
  analogWrite(WIO_BUZZER, 100);
  Serial.println("SUNNY");
  }

  else
  {
  analogWrite(WIO_BUZZER, 0);
  Serial.println("DARK");  
  }
  // wait 1 second to read again
  delay(500);

}

4 - Grove DHT11 read

Arduino
This code will let you read the Grove DHT11 with the WIO Terminal and show the results in the serial port of your computer.
#include "DHT.h"          //DHT library

#define DHTPIN D0         // define the digital pin 0

#define DHTTYPE DHT11     //Define the DHT sensor type

DHT dht(DHTPIN, DHTTYPE); // initialize DHT sensor


void setup() {
  // put your setup code here, to run once:
  
  //Start serial communication
  Serial.begin(9600);
  
  //Start DHT sensor
  dht.begin();

}

void loop() {
  // put your main code here, to run repeatedly:

//create an integer T to store the Temperature value
  int t = dht.readTemperature();
  
//create an integer H to store the Humidity value
  int h = dht.readHumidity();

// Print Temperature and Humidity Values
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println("ºC");
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.println("%");

  delay(2000);
}

5 - Grove Soil Moisture read

Arduino
This code will let you read the Grove Soil Moisture Sensor with the WIO Terminal and show the results in the serial port of your computer.
// declare to which Pin the sensor is connected
int sensorPin = A0;

// declare the initial value of the sensor
int sensorValue = 0;
 
void setup() {
    // open the serial port (the communication with the computer to show values)
    Serial.begin(9600);
}

void loop() {
    // read the value from the sensor:
    sensorValue = analogRead(sensorPin);

    // print the value in the serial monitor
    Serial.print("Moisture = " );
    Serial.println(sensorValue);

    // wait one second to start again
    delay(1000);
}

5.1 - Grove Soil Moisture Map

Arduino
This instruction turns the values of the code mapping them on a range from 0% to 100%
// declare to which Pin the sensor is connected
int sensorPin = A0;

// declare the initial value of the sensor
int sensorValue = 0;
 
void setup() {
    // open the serial port (the communication with the computer to show values)
    Serial.begin(9600);
}

void loop() {
    // read the value from the sensor:
    sensorValue = analogRead(sensorPin);
    
    // map the values (HIGHEST_reading, LOWEST_reading, 100%, 0%)
    sensorValue = map(sensorValue, 1023, 0, 100, 0);

    // print the value in the serial monitor
    Serial.print("Moisture = " );
    Serial.print(sensorValue);
    Serial.println(" %" );

    // wait one second to start again
    delay(1000);
}

5.2 - Grove Soil Moisture assigning functions to values:

Arduino
This code will assign some functions to the values, so that it acts differently depending if the soil is dry, in a good wet state or too wet.
// declare to which Pin the sensor is connected
int sensorPin = A0;

// declare the initial value of the sensor
int sensorValue = 0;

void setup() {
    // open the serial port (the communication with the computer to show values)
    Serial.begin(9600);
}

void loop() {
    // read the value from the sensor:
    sensorValue = analogRead(sensorPin);
    // map the values (HIGHEST_reading, LOWEST_reading, 100%, 0%)
    sensorValue = map(sensorValue, 1023, 0, 100, 0);

/* a conditional that tells us that the plant is DRY
if the value is LESS or equal to 300 */
if (sensorValue <= 30) {
    Serial.println("DRY SOIL...PLANT NEEDS WHATER" );
    Serial.print("Moisture = " );
    Serial.print(sensorValue);
    Serial.println(" %" );
}

/* a conditional that tells us that the plant is TOO WET 
if the value is MORE or equal to 700 */
if (sensorValue >= 70) {
    Serial.println("SUPER WET...TOO MUCH WATER" );
    Serial.print("Moisture = " );
    Serial.print(sensorValue);
    Serial.println(" %" );
}

/* a conditional that tells us that the plant is HAPPY 
if the value is LESS than 700 and MORE than 300 */
if (sensorValue < 70 && sensorValue > 30) {
    Serial.println("PERFECT MOISTURE...PLANT IS HAPPY" );
    Serial.print("Moisture = " );
    Serial.print(sensorValue);
    Serial.println(" %" );
}

    // a space between the writing of the readings
    Serial.println();

    // wait one second to start again
    delay(1000);
}

6 - Display a text on a colour background:

Arduino
This code will display one text in the middle of the WIO terminal LCD screen
#include "TFT_eSPI.h"

TFT_eSPI tft;

void setup() {
  
  tft.begin();
  tft.setRotation(3);

  tft.fillScreen(TFT_GREEN);
  tft.setTextSize(4);
  tft.setTextColor(TFT_WHITE);
  tft.drawString("POWAR GARDEN", 20, 100);
}

void loop() {
}

6.2 - Light Sensor + LCD:

Arduino
This code will read the light sensor and display its values on the LCD screen
#include "TFT_eSPI.h"

TFT_eSPI tft;

void setup() {
tft.begin();
tft.setRotation(3);
tft.fillScreen(TFT_GREEN);
}

void loop() {
int lightVal = analogRead(WIO_LIGHT);
tft.fillScreen(TFT_GREEN);
tft.setCursor(tft.width() / 2, tft.height() / 2);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(4);
tft.println(lightVal);

delay(50);
}

7 - FULL CODE

Arduino
This code will initialize by loading the libraries, then set the PinModes for the internal LIGH sensor and BUZZER as Inputs and Outputs, then start the DHT sensor, start the screen and set the initial rotation and size, and draw an initial welcome message.

Then, in the VoidLoop, it will fill the screen with White, draw a Green rectangle on top, draw some vertical and horizontal lines, and then read and map each of the sensors and display their values.

At the end of the code, we added a conditional so that if the Soil sensor reading is too low (DRY) it will display a message on the screen and start beeping.

You should also consider modifying this code with the calibration values you've got from the previous calibration exercise.
#include "TFT_eSPI.h"
#include "DHT.h"

// Set the I2C pin into a Digital/Analogue Pin
#define DHTPIN PIN_WIRE_SCL

// Define the kind of DHT sensor you use
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);
TFT_eSPI tft;
TFT_eSprite spr = TFT_eSprite(&tft);

int moisturePin = A0;
int moistureVal = 0;



void setup() {
  // declare the pinModes of the internal LIGH sensor and BUZZER 
  pinMode(WIO_LIGHT, INPUT);
  pinMode(WIO_BUZZER, OUTPUT);

  // Begin DHT sensor and Screen
  dht.begin();
  tft.begin();
  
  // Set initial screen parameters
  tft.setRotation(3);
  spr.createSprite(TFT_HEIGHT, TFT_WIDTH);
  
  // Draw the initial Screen
  tft.fillScreen(TFT_GREEN);
  tft.setTextSize(4);
  tft.setTextColor(TFT_WHITE);
  tft.drawString("POWAR GARDEN", 20, 100);
  tft.setTextSize(2);
  tft.drawString("With Seeed Studio", 60, 180);
  
  // Beep once when it starts
  analogWrite(WIO_BUZZER, 150);
  delay(100);
  analogWrite(WIO_BUZZER, 0);
  delay(2000);
  
  // Draw the Maker Faire Screen
  tft.fillScreen(TFT_BLUE);
  tft.setTextSize(3);
  tft.setTextColor(TFT_RED);
  tft.fillRect(20, 20, 280, 200, TFT_WHITE);
  tft.drawString("Maker Faire", 65, 90);
  tft.setTextColor(TFT_BLUE);
  tft.drawString("LISBON", 110, 130);

  delay(1500);
  
}


void loop() {

  // Declare the initial Variables for the code and MAP the Values
  int t = dht.readTemperature();
  int h = dht.readHumidity();

  // This code will MAP the SOIL MOISTURE values
  mnoistureVal = analogRead(mnoisturePin);
  mnoistureVal = map(mnoistureVal, 1023, 0, 100, 0);

  // This code will MAP the LIGH SENSOR values
  int light = analogRead(WIO_LIGHT);
  light = map(light, 0, 1023, 0, 100);


  // This will set the screen to White and draw a DarkGreen rectangle on top
  spr.fillSprite(TFT_WHITE);
  spr.fillRect(0, 0, 320, 50, TFT_DARKGREEN);
  spr.setTextSize(3);
  spr.setTextColor(TFT_WHITE);
  spr.drawString("POWAR GARDEN", 55, 15);


  // This will draw vertical and horizontal lines to divide the screen
  spr.drawFastVLine(150, 50, 190, TFT_DARKGREEN);
  spr.drawFastHLine(0, 140, 320, TFT_DARKGREEN);


  // Draw TEMPERATURE Value
  spr.setTextColor(TFT_BLACK);
  spr.setTextSize(2);
  spr.drawString("Temperature", 10, 65);
  spr.setTextSize(3);
  spr.drawNumber(t, 50, 95);
  spr.drawString("C", 90, 95);


  // Draw HIMIDITY Value
  spr.setTextSize(2);
  spr.drawString("Humidity", 25, 160);
  spr.setTextSize(3);
  spr.drawNumber(h, 30, 190);
  spr.drawString("%RH", 70, 190);


  // Draw SOIL MOISTURE Value
  spr.setTextSize(2);
  spr.drawString("Soil Moisture", 160, 65);
  spr.setTextSize(3);
  spr.drawNumber(mnoistureVal, 200, 95);
  spr.drawString("%", 240, 95);


  // Draw LIGHT Value
  spr.setTextSize(2);
  spr.drawString("Light", 200, 160);
  spr.setTextSize(3);
  spr.drawNumber(light, 205, 190);
  spr.drawString("%", 245, 190);


  // This is the conditionals for the soil moisture alarm
  if (sensorVal < 40) {
    spr.fillSprite(TFT_DARKGREEN);
    spr.setTextColor(TFT_WHITE);
    spr.drawString("SAD PLANT", 80, 100);
    analogWrite(WIO_BUZZER, 0);
    spr.pushSprite(0, 0);
    delay(1000);

    spr.fillSprite(TFT_RED);
    spr.setTextColor(TFT_YELLOW);
    spr.drawString("TIME TO WATER!", 40, 100);
    analogWrite(WIO_BUZZER, 150);
    spr.pushSprite(0, 0);
    delay(1000);
    analogWrite(WIO_BUZZER, 0);
  }

  spr.pushSprite(0, 0);
  delay(50);
}

Credits

Pablo Zuloaga Betancourt
4 projects • 15 followers
Colombian Maker based in Barcelona, working on projects related to education, the decentralization of technology and climate change.
Contact
Thanks to Lakshantha .

Comments

Please log in or sign up to comment.