ag2maxsadcat8266
Published

Arduino flower watering system with oled display

A simple design to irrigate plants with information displayed on the oled display.

IntermediateFull instructions provided1,382
Arduino flower watering system with oled display

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
oled display ssd1306 128x32 with i2c(blue)
×1
soil moisture sensor fc-28
×1
Relay Module (Generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
USB-A to B Cable
USB-A to B Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Tape, Electrical
Tape, Electrical

Story

Read more

Schematics

Plant Watering System With Oled Display

Code

Plant Watering System With Oled isplay script

C/C++
// needed libraries
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width,  in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// declare an SSD1306 display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

const int dry = 500; //the value at which the plant is dry

const int pumpPin = 10; //pump connected to pin 10
const int soilSensor = A0; //the soil moisture sensor reads the value from the analog pin A0

void setup() {
   Serial.begin(9600);

  // initialize OLED display with address 0x3C for 128x64
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    while (true);
  }

  delay(2000);         // wait for initializing
  oled.clearDisplay(); // clear display

  oled.setTextSize(4);          // text size
  oled.setTextColor(WHITE);     // text color
  oled.setCursor(0, 0);        // position to display
  oled.println("Hello");      //inscription when switching on
  oled.display();             //activating the screen
  delay(3000);

  //oled Loading script
  oled.clearDisplay();
  oled.setCursor(0, 0);
  oled.setTextSize(3);  
  oled.println("Loading");
  oled.setCursor(80, 12);
  oled.setTextSize(3);

   //loading animation(dots)
  oled.println(".");
  oled.display();
  delay(1000);
  oled.setCursor(95, 12);
  oled.setTextSize(3); 
  oled.println(".");
  oled.display();  
  delay(1000);
  oled.setCursor(110, 12);
  oled.setTextSize(3); 
  oled.println(".");
  oled.display(); 
  
  //water intake by a pump
  pinMode(pumpPin, OUTPUT);
  pinMode(soilSensor, INPUT);
  Serial.begin(9600);
  digitalWrite(pumpPin, HIGH);
  delay(500);
}

void loop() {
  delay(1000);
  oled.clearDisplay();

  oled.setTextSize(2);
  oled.setTextColor(WHITE);
  oled.setCursor(0, 0);
  oled.println("Fern :) "); //the name of your plant that will be visible all the time
  oled.display();
  
  // read current moisture
  int moisture = analogRead(soilSensor);
  Serial.println(moisture);
  oled.setTextSize(1);
  oled.println("value: " + String(moisture));
  oled.display();
  delay(5000);
  
  if (moisture >= dry) {
    // the soil is too dry, water!
    Serial.println("Watering starts now..moisture is " + String(moisture));
    oled.println("watering required");
    oled.display();
    digitalWrite(pumpPin, LOW);
   

    // keep watering for 5 sec
    delay(2000);

    // turn off water
    digitalWrite(pumpPin, HIGH);
    Serial.println("Done watering.");
    oled.setTextSize(2);
    oled.setCursor(0, 0);
    oled.clearDisplay();
    oled.println("Done ");
    oled.println("Watering");
    oled.display();
  } else {
    Serial.println("Moisture is adequate. No watering needed " + String(moisture));
    oled.println("watering not required");
    oled.display();
  }
}

Credits

ag2max
2 projects • 1 follower
Contact
sadcat8266
2 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.