Magicbit
Published

Water Pump Control with Blynk App - ESP32

This tutorial shows how to ON/OFF Water pump with Magicbit(ESP32) and Blynk App.

IntermediateProtip2 hours253
Water Pump Control with Blynk App - ESP32

Things used in this project

Hardware components

Magicbit
×1
Relay
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Story

Read more

Code

Untitled file

Arduino
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define relayPin 26  //D26
#define OLED_RESET 4

Adafruit_SSD1306 display(128,64);

int relayState = 1; // RELAY OFF 

char auth[] = "YcwWFZ09lNlVi1V8PbmX_Q4d1rzY6AyQ";

char ssid[] = "Jazz-LTE-EB8E";
char pass[] = "40758892";

BLYNK_WRITE(V1) {
  relayState = param.asInt();
  digitalWrite(relayPin, relayState);
  }


BLYNK_CONNECTED() {
  // Request the latest state from the server
  Blynk.syncVirtual(V1);
}
void setup()
{
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.display();
  
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
   
  pinMode(relayPin, OUTPUT);

 //On power ON rely in OFF state
  digitalWrite(relayPin, relayState);


  
}
void loop()
{
  Blynk.run();
  if(relayState==1){
    display.clearDisplay();
    display.setTextSize(4);
    display.setTextColor(WHITE);
    display.setCursor(10, 0);
    display.println("Pump ON");//Pump On
    Serial.println("Water pump ON");
    display.display();
    display.clearDisplay();
    delay(1000);
  }
  else{
    
    display.clearDisplay();
    display.setTextSize(4);
    display.setTextColor(WHITE);
    display.setCursor(10, 0);
    display.println("Pump OFF");//Pump Off
    Serial.println("Water pump OFF");
    display.display();
    display.clearDisplay();
    delay(1000);
  }

}

Credits

Magicbit

Magicbit

4 projects • 25 followers
Magicbit is an integrated development platform based on ESP32 for learning, prototyping, coding, electronics, robotics, IoT and more.

Comments

Add projectSign up / Login