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

Arduino and ESP32-Based Solar-Powered IoT Roof Water Sprinkler System

View and Edit Project In Cirkit DesignerImage of Arduino and ESP32-Based Solar-Powered IoT Roof Water Sprinkler System

IoT-Based Solar Powered Roof Water Sprinkler

Summary

This project is an IoT-based solar-powered roof water sprinkler system. It utilizes an Arduino UNO and an ESP32 microcontroller to monitor temperature, humidity, and water levels. The system is powered by a solar panel and a 12V battery, managed by a solar charge controller. The ESP32 communicates with a Blynk app to provide real-time updates and control. The system automatically controls a water pump based on the sensor data.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. 12V 7Ah Battery

    • Description: Rechargeable battery for power storage.
    • Pins: 12v +, 12v -
  3. Solar Charge Controller

    • Description: Manages the charging of the battery from the solar panel.
    • Pins: Solar Cell +, Solar Cell -, Battery +, Battery -, Load +, Load -
  4. Solar Panel

    • Description: Converts sunlight into electrical energy.
    • Pins: +, -
  5. ESP32 (30 pin)

    • Description: Microcontroller with Wi-Fi and Bluetooth capabilities.
    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
  6. Water Level Sensor

    • Description: Measures the water level in the tank.
    • Pins: SIG, VCC, GND
  7. Mini Diaphragm Water Pump

    • Description: Pumps water for the sprinkler system.
    • Pins: Positive (+), Negative (-)
  8. KY-015 DHT11 Temperature-Humidity Sensor Module

    • Description: Measures temperature and humidity.
    • Pins: VCC, GND, DOUT
  9. 2 Channel Relay Module

    • Description: Controls the water pump and other high-power devices.
    • Pins: N.O. 2, COM 2, N.C. 2, N.O. 1, COM 1, N.C. 1, pin 7, pin 8, pin 9, pin 10, pin 11, pin 12, VCC+, VCC- (GND), IN 1, IN 2

Wiring Details

Arduino UNO

12V 7Ah Battery

Solar Charge Controller

Solar Panel

ESP32 (30 pin)

Water Level Sensor

Mini Diaphragm Water Pump

KY-015 DHT11 Temperature-Humidity Sensor Module

2 Channel Relay Module

Documented Code

Arduino UNO Code

/*
 * IoT-Based Solar Powered Roof Water Sprinkler
 * This Arduino sketch reads data from a DHT11 temperature-humidity sensor and a
 * water level sensor. It sends the data to an ESP32 via Serial communication.
 * The ESP32 controls a water pump based on the received data and sends updates
 * to a Blynk app.
 */

#include <DHT.h>

// Define the DHT11 pin and type
#define DHTPIN A1       // Pin connected to the DHT11
#define DHTTYPE DHT11   // DHT11 sensor

// Define the water level sensor pin
const int waterLevelSensorPin = A0; // Analog pin for water level sensor

// Initialize the DHT sensor
DHT dht(DHTPIN, DHTTYPE);

// Variables for non-blocking timing
unsigned long previousMillis = 0;
const unsigned long dhtInterval = 2000; // DHT11 sampling period (2 seconds)

void setup() {
  // Start the DHT sensor
  dht.begin();

  // Start Serial communication with ESP32
  Serial.begin(115200);
}

void loop() {
  unsigned long currentMillis = millis();

  // Read DHT11 sensor data every 2 seconds
  if (currentMillis - previousMillis >= dhtInterval) {
    previousMillis = currentMillis;

    float temperature = dht.readTemperature();
    float humidity = dht.readHumidity();

    // Check if readings are valid
    if (!isnan(temperature) && !isnan(humidity)) {
      // Send temperature to ESP32
      Serial.print("T:");
      Serial.println(temperature);
    } else {
      Serial.println("Error reading DHT11 sensor!");
    }
  }

  // Simulate water level sensor
  int waterLevel = analogRead(waterLevelSensorPin);
  int waterLevelPercentage = map(waterLevel, 0, 1023, 0, 100);

  // Send water level data to ESP32
  Serial.print("W:");
  Serial.println(waterLevelPercentage);

  delay(500); // Small delay for stability
}

ESP32 Code

/*
 * IoT-Based Solar Powered Roof Water Sprinkler
 * This Arduino sketch controls a water pump based on temperature and water
 * level data received from an Arduino UNO. It also sends updates to a Blynk
 * app and handles notifications for low water levels and sensor errors.
 */

#define BLYNK_TEMPLATE_ID "TMPL6Peoo1Mnk"
#define BLYNK_TEMPLATE_NAME "Rooftop water Sprinkler solar powered"
#define BLYNK_AUTH_TOKEN "ygmW7VZVNytrWJ3yvIihC8EX56Ejja7J"

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

// WiFi credentials
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "RumahKami";
char pass[] = "Selamat000";

// Define motor and relay pins
const int motorPin = 16;
const int relayPin = 15;

// Variables to store data from Arduino Uno
float temperature = 0;
int waterLevel = 0;
bool motorState = false;

// Define thresholds
const int lowWaterLevelThreshold = 10; // Water level threshold for low level
const unsigned long sensorTimeout = 10000; // 10 seconds for sensor detection

// Timing variables
unsigned long lastTemperatureUpdate = 0;
unsigned long lastWaterLevelUpdate = 0;

// Create a timer instance
BlynkTimer timer;

// Function to turn off the motor after 5 minutes
void turnOff