Powerup
Published

Smart plant watering system using esp8266

Esp8266 smart plant watering system which can water plants through blynk platform and through voice assistant for ex google, alexa etc

IntermediateFull instructions provided24 hours716
Smart plant watering system using esp8266

Things used in this project

Story

Read more

Schematics

Smart plant watering system

Code

Smart plant watering system

Arduino
#define BLYNK_TEMPLATE_ID "ENTER_YOUR_BLYNK_TEMPLATE_ID"
#define BLYNK_TEMPLATE_NAME "smart irrigation system"
#define BLYNK_AUTH_TOKEN "ENTER_YOUR_BLYNK_AUTH_TOKEN"

#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal_I2C.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#include <SinricPro.h>
#include <SinricProSwitch.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

char auth[] = "ENTER_YOUR_BLYNK_AUTH_TOKEN";
char ssid[] = "ENTER_YOUR_WIFI_SSID";          // enter your WiFi / hotspot name
char pass[] = "ENTER_YOUR_WIFI_PASSWORD";      // enter your WiFi password

BlynkTimer timer;
bool Relay = 0;

#define sensor A0
#define waterPump 3
#define LED_BUILTIN 2

bool ledState = LOW;

#define WIFI_SSID         "ENTER_YOUR_WIFI_SSID"
#define WIFI_PASS         "ENTER_YOUR_WIFI_PASSWORD"
#define APP_KEY           "ENTER_YOUR_SINRIC_APP_KEY"
#define APP_SECRET        "ENTER_YOUR_SINRIC_APP_SECRET"
#define SWITCH_ID         "ENTER_YOUR_SINRIC_SWITCH_ID"
#define BAUD_RATE         115200
#define RELAY_PIN         3

bool onPowerState(const String &deviceId, bool &state) {
  digitalWrite(RELAY_PIN, state);
  lcd.setCursor(0, 1);
  if (state) {
    lcd.print("Motor is ON ");
  } else {
    lcd.print("Motor is OFF");
  }
  return true;
}

void setup() {
  pinMode(RELAY_PIN, OUTPUT);

  #if defined(ESP8266)
    WiFi.setSleepMode(WIFI_NONE_SLEEP); 
    WiFi.setAutoReconnect(true);
  #elif defined(ESP32)
    WiFi.setSleep(false); 
    WiFi.setAutoReconnect(true);
  #endif
  
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(250);
  }
  
  SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];
  mySwitch.onPowerState(onPowerState);
  SinricPro.begin(APP_KEY, APP_SECRET);

  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(waterPump, OUTPUT);
  digitalWrite(waterPump, HIGH);
  lcd.init();
  lcd.backlight();

  Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);

  lcd.setCursor(1, 0);
  lcd.print("System Loading");
  for (int a = 0; a <= 15; a++) {
    lcd.setCursor(a, 1);
    lcd.print(".");
    delay(500);
  }
  lcd.clear();

  timer.setInterval(100L, soilMoistureSensor);
  timer.setInterval(5000L, blinkLED);
}

BLYNK_WRITE(V1) {
  Relay = param.asInt();

  if (Relay == 1) {
    digitalWrite(waterPump, LOW);
    lcd.setCursor(0, 1);
    lcd.print("Motor is ON ");
  } else {
    digitalWrite(waterPump, HIGH);
    lcd.setCursor(0, 1);
    lcd.print("Motor is OFF");
  }
}

void soilMoistureSensor() {
  int value = analogRead(sensor);
  value = map(value, 0, 1024, 0, 100);
  value = (value - 100) * -1;

  Blynk.virtualWrite(V0, value);
  lcd.setCursor(0, 0);
  lcd.print("Moisture :");
  lcd.print(value);
  lcd.print("% ");
  
  lcd.setCursor(0, 1);
  if (Relay == 1) {
    lcd.print("Motor is ON ");
  } else {
    lcd.print("Motor is OFF");
  }
}

void blinkLED() {
  digitalWrite(LED_BUILTIN, LOW);
  delay(100);
  digitalWrite(LED_BUILTIN, HIGH);
}

void loop() {
  Blynk.run();
  timer.run();
  SinricPro.handle();
}

Credits

Powerup
2 projects • 0 followers

Comments