Make an automatic clothesline control system using an ESP32 board

Make an automatic clothesline control system using an ESP32 board

In this project, we will learn how to make an automatic clothesline control system using an ESP32 board. This smart system can automatically protect your clothes from unexpected rain. When the raindrop sensor detects rain, the clothesline will automatically move to a safe position using the SG90 servo motor. For this project, I used an ESP32 development board, an SG90 servo motor, and a raindrop sensor module. I also connected the system to the Blynk app, which allows you to monitor and control the clothesline from anywhere in the world using your smartphone. You can check the sensor status and manually control the clothesline using the Blynk dashboard.

This is a very simple, useful, and effective home automation project. It is also a great project for beginners who want to learn about ESP32 programming and IoT applications. For testing this project, I designed a basic clothesline structure using a 5 mm foam board. This simple model helps demonstrate how the system works. However, you can change them as you like. If you would like to learn more about the ESP32 board, Blynk Cloud, and other ESP32-based projects, please visit our ESP32 project category.

Ok, let’s do this project step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, let’s create the mini home structure. For this, I used a 5 mm foam board sheet. You can also use cardboard or any other suitable materials based on what you have available.

  • First, cut out two triangle shapes and the holding parts. These pieces will form the main structure of the mini house.
  • Then, cut out the two roof parts for the mini house.
  • Now, glue all the parts together carefully. Then you will have a complete mini house structure ready for the project.

Step 3

Thirdly, connect the wooden or iron stick to the servo horn. Next, cut out the clothes shapes using colored A4 sheets. After that, glue them onto the stick evenly.

Step 4

Next, install the servo motor inside the mini house structure. After that, install the raindrop sensor on the top of the roof.

Step 5

Now, place the ESP32 board on the breadboard and connect all the components to the ESP32 board carefully. Make sure each connection is correct according to the circuit diagram below.

Make an automatic clothesline control system using an ESP32 board

Step 6

Afterward, connect the ESP32 board to the computer using a USB cable. Then, let’s set up the Blynk web dashboard step by step. This will allow us to monitor and control the system remotely in real time.

  • First, go to the Blynk website and log in to your account. Then, click the Developer Zone button and create a new template. You can name it as you like, based on your project. Also, choose ESP32 as the board type.
  • Next, click the Datastreams tab in your template. After that, create three virtual pins using the information provided below.
  • Virtual PIN Name –> Switch / PIN –> V0 / MIN –> 0 / MAX –> 1
  • Virtual PIN Name –> Rainfall / PIN –> V1 / MIN –> 0 / MAX –> 100
  • Virtual PIN Name –> LED / PIN –> V2 / MIN –> 0 / MAX –> 1
  • Now, click the Dashboard tab and add a Button widget, a Gauge widget, and an LED widget to the dashboard. These widgets will help you control and monitor your system in real time.
  • Next, click the settings icon on each widget and select the datastreams we created earlier. This step is important to correctly link the widgets with your ESP32 board. Finally, click the Save button to apply all the changes and complete the dashboard setup.
  • Now, click the Devices tab and create a new device using the “From Template” button. For this, select the template name you created earlier. After that, your device will be created, and you will be able to see the Blynk Auth Token.

Step 7

Afterward, copy and paste the following program into your Arduino IDE. Also, make sure to include all the required library files in the Arduino IDE before uploading the code.

#define BLYNK_PRINT Serial

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

#define SERVO_PIN       13
#define RAIN_SENSOR_AO  34

char auth[] = "*********************";
char ssid[] = "**************";
char pass[] = "************";

Servo clothServo;
BlynkTimer timer;

WidgetLED rainLED(V2);

int currentPos = 0;
bool manualMode = false;

//--------------------------------------------------
void moveServoSlowly(int targetPos)
{
  if (currentPos < targetPos)
  {
    for (int pos = currentPos; pos <= targetPos; pos++)
    {
      clothServo.write(pos);
      delay(15);
    }
  }
  else if (currentPos > targetPos)
  {
    for (int pos = currentPos; pos >= targetPos; pos--)
    {
      clothServo.write(pos);
      delay(15);
    }
  }
  currentPos = targetPos;
}

//--------------------------------------------------
BLYNK_WRITE(V0)
{
  manualMode = param.asInt();

  if (manualMode)
  {
    Serial.println("Manual Mode ON");
    moveServoSlowly(80);
  }
  else
  {
    Serial.println("Auto Mode ON");
  }
}

//--------------------------------------------------
void checkRain()
{
  int rawValue = analogRead(RAIN_SENSOR_AO);

  // Convert to 0–100%
  int rainPercent = map(rawValue, 4095, 0, 0, 100);
  rainPercent = constrain(rainPercent, 0, 100);

  Serial.print("Rain %: ");
  Serial.println(rainPercent);

  // Send to Blynk gauge
  Blynk.virtualWrite(V1, rainPercent);

  // LED logic
  if (rainPercent > 40)   // adjust threshold
  {
    rainLED.on();

    if (!manualMode)
    {
      moveServoSlowly(80);
    }
  }
  else
  {
    rainLED.off();

    if (!manualMode)
    {
      moveServoSlowly(180);
    }
  }
}

//--------------------------------------------------
void setup()
{
  Serial.begin(115200);

  clothServo.setPeriodHertz(50);
  clothServo.attach(SERVO_PIN, 500, 2400);

  clothServo.write(0);
  currentPos = 0;

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

  timer.setInterval(1000L, checkRain);
}

//--------------------------------------------------
void loop()
{
  Blynk.run();
  timer.run();
}
  • Now, copy and paste the Blynk Auth Token into the program. Also, include your WiFi SSID and password in the code.
  • Afterward, select the correct board and port in the Arduino IDE. Make sure you choose the ESP32 board from the board manager and the correct COM port that your device is connected to.

Step 8

Now, let’s set up the Blynk mobile dashboard. For that, download and install the Blynk app from the Play Store or App Store. Afterward, log in to your account, and you will be able to see the template you created earlier in the app.

  • Now, click on the template and add widgets to the dashboard, just like you did in the web dashboard. These widgets will allow you to control and monitor your system directly from your mobile device.
  • Next, click each widget one by one and select the datastreams we created in the web dashboard. This will properly link your mobile dashboard with the ESP32 system. Now everything is done, and your Blynk mobile setup is fully configured and ready to use for monitoring and controlling your project in real time.

Step 9

Finally, remove the USB cable and provide an external power supply to the system. However, you can also test the project using USB power if needed. Now, test your system using a water spray to simulate rain and observe how it responds.

Okay, enjoy this project! The full video guide is provided below. We hope to see you in the next project.

Make an automatic clothesline control system using an ESP32 board

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *