Dhrumil Makadia
Published © CC BY-NC

Smart Water Motor Switch

It will start your water motor automatically and stop automatically. Also showing how much fill with water in cm.

IntermediateProtip1 hour1,334
Smart Water Motor Switch

Things used in this project

Hardware components

Wemos D1
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Temperature Sensor
Temperature Sensor
×1
2 channel relay
×1
Power Supply
×1
Emergency Switch
×1
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×1
adapter power 5v
×1

Software apps and online services

Blynk
Blynk

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

If Any query then ask me anything.

email id : dhrumilmakadia161999@gmail.com

Schematics

Screenshot of application (Blynk Application)

Smart Water Switch Diagram

Code

code

Arduino
As per your convenience take your own micro controller and own pins.
#include <NewPing.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SPI.h>
#include <SimpleTimer.h>
#define TRIGGERPIN D6 // as per your Willingly
#define ECHOPIN    D7 // as per your Willingly
#define MAX_DISTANCE 5000 // as per your Willingly
#define Relay D3 // as per your Willingly
float temp;
int tempPin = A0; //analog pin A0 // as per your Willingly
SimpleTimer timer;

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; //your blynk project auth
char ssid[] = "xxxxxxxxxx"; // as per your wifi setup
char pass[] = "xxxxxxxxxxxxxx"; // as per your wifi setup
WidgetLCD lcd(V1); //on blynk application you have to select virtual pin 1 for lcd

int distance=0;
NewPing sonar(TRIGGERPIN, ECHOPIN, MAX_DISTANCE);
void setup() 
{
  Serial.begin(9600);
  pinMode(TRIGGERPIN, OUTPUT);
  pinMode(ECHOPIN, INPUT);
  pinMode(Relay,OUTPUT); 
  Blynk.begin(auth, ssid, pass);
  lcd.clear(); 
  lcd.print(1, 0, "Distance in cm");
  timer.setInterval(1000L, sendUptime);   // Setup a function to be called every second
}

void sendUptime()
{
  // shows the value temp on virtual pin 10
  Blynk.virtualWrite(2, temp); //on blynk application you have to select virtual pin 2 for temp
}

void loop()
{
  Blynk.run(); 
  timer.run(); // Initiates SimpleTimer 
  lcd.clear();
  lcd.print(1, 0, "Distance in cm");
  
  temp = analogRead(tempPin);
  temp = temp * 0.48828125;  

  WidgetLED led1(V0); //on blynk application you have to select virtual pin 0 for led1
  WidgetLED led2(V3); //on blynk application you have to select virtual pin 3 for led2
  distance=sonar.ping_cm();
  delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  
  Serial.print("Distance: ");
  Serial.println(distance);
  lcd.print(0, 1, distance); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  
  if(distance<=10) //as per your water tank
  {
    delay(50);
    lcd.print(5,1,"Relay : ");
    delay(50);
    lcd.print(13,1,"OFF"); 
    delay(50);
    Serial.println("LOW");
    delay(50);
    digitalWrite(Relay,LOW); //Pump OFF
    led1.off();
    led2.on();
  }
  else if(distance>=100) //as per your water tank
  {
    delay(50);
    lcd.print(5,1,"Relay : ");
    delay(50);
    lcd.print(14,1,"ON");  
    delay(50);
    Serial.println("HIGH");
    delay(50);
    digitalWrite(Relay,HIGH); // Pump ON
    led1.on();
    led2.off();
  }      
  else
  {
    delay(50);
    lcd.print(5,1,"Relay : ");
    delay(50);
    lcd.print(14,1,"OFF");  
    delay(50);
    Serial.println("LOW");
    delay(50);
    digitalWrite(Relay,LOW); // Pump OFF
    led1.off();
    led2.on();
  }
  delay(1500);
}

Credits

Dhrumil Makadia

Dhrumil Makadia

38 projects • 40 followers

Comments