Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Based Automated Water Pump System with RTC and Wi-Fi Control

View and Edit Project In Cirkit DesignerImage of ESP32-Based Automated Water Pump System with RTC and Wi-Fi Control

Circuit Documentation

Summary

This circuit is designed to control a water pump using an ESP32 microcontroller, an RTC DS1307 for timekeeping, and a 12V single-channel relay. The water pump is activated every 3 hours based on the RTC time. The system is integrated with Blynk for remote monitoring and control via WiFi.

Component List

Water Pump

12V Single Channel Relay

RTC DS1307

ESP32

Power 220V

Wiring Details

Water Pump

12V Single Channel Relay

RTC DS1307

ESP32

Code Documentation

/* 
 * This Arduino Sketch is designed to control a water pump using an ESP32, RTC DS1307,
 * and a 12V single channel relay. The pump is turned on every 3 hours based on the
 * RTC time. The system is also integrated with Blynk for remote monitoring and
 * control via WiFi.
 */

#define BLYNK_TEMPLATE_ID "TMPL6ijEa7EZW"
#define BLYNK_TEMPLATE_NAME "Penyiraman Otomatis"
#define BLYNK_AUTH_TOKEN "Lf9ZwWDPa6ZOWFbzGO_kKnllRtM4HUwg"

#include <Wire.h>
#include <RTClib.h>
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>

// Blynk Auth Token
char auth[] = "YourAuthToken";

// Your WiFi credentials.
char ssid[] = "Kost Pink";
char pass[] = "Rumahkami12345678";

RTC_DS1307 rtc;

// Relay pin
const int relayPin = 2;

// Time interval for pump activation (3 hours in seconds)
const unsigned long interval = 3 * 60 * 60;
unsigned long previousMillis = 0;

void setup() {
  // Initialize serial communication
  Serial.begin(115200);

  // Initialize Blynk
  Blynk.begin(auth, ssid, pass);

  // Initialize RTC
  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (!rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // Set the RTC to the current date and time
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

  // Initialize relay pin
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW);
}

void loop() {
  // Run Blynk
  Blynk.run();

  // Get current time
  DateTime now = rtc.now();

  // Calculate elapsed time
  unsigned long currentMillis = now.unixtime();
  if (currentMillis - previousMillis >= interval) {
    // Save the last time the pump was turned on
    previousMillis = currentMillis;

    // Turn on the pump
    digitalWrite(relayPin, HIGH);
    delay(10000); // Pump runs for 10 seconds
    digitalWrite(relayPin, LOW);
  }
}

This code initializes the ESP32, connects to WiFi using Blynk, and sets up the RTC DS1307. The main loop checks the current time and activates the water pump every 3 hours for 10 seconds.