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 hours631
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 "TMPLy-FGCvSe"
#define BLYNK_TEMPLATE_NAME "smart irrigation system"
#define BLYNK_AUTH_TOKEN "Cv_vDzCnUkLuTHT7SXU4xqmUkOoRj5FZ"

#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[] = "Cv_vDzCnUkLuTHT7SXU4xqmUkOoRj5FZ";
char ssid[] = "Enter your ssid";//enter your mobile hotspot ssid 
char pass[] = "Enter your password";// enter your mobile hotspot password

BlynkTimer timer;
bool Relay = 0;

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

bool ledState = LOW;

#define WIFI_SSID         "manas1234"    
#define WIFI_PASS         "jhmu0767"
#define APP_KEY           "1986ea97-0e07-4982-8fe3-487684c68a44"
#define APP_SECRET        "f83b542e-2550-4bc1-8032-b99faccb74f9-cddde340-57f8-4499-9282-1660f16d373b"
#define SWITCH_ID         "65faeac838f6f4a3cdc5fee7"
#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("% "); // Added percentage sign
  
  // Print motor status below moisture level
  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