arduino / Arduino

Arduino IDE 1.x
https://www.arduino.cc/en/software
Other
14.18k stars 7.01k forks source link

water level indicator with IoT #12008

Closed khrnsyfa closed 6 days ago

khrnsyfa commented 6 days ago
#define BLYNK_PRINT Serial
#define BLYNK_AUTH_TOKEN " "
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd_i2c(0x27, 16, 2); 
//#include <ESP32_Servo.h>
//Servo myServo;
//int servoPin = 18;
//int pos=0;
//int pos1=180;

// ULN2003 Motor Driver Pins
#define IN1 15
#define IN2 13
#define IN3 12
#define IN4 14
#define LEDRED 19 //pin bebas
#define LEDGREEN 21
int value = 0;
int echo = 5;
int trigger = 17;
int duration;
int dist;
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = " "; 
char pass[] = " "; 
#include <Stepper.h>
bool notif= false;
const int stepsPerRevolution = 2048;  // change this to fit the number of steps per revolution
Stepper myStepper(stepsPerRevolution, IN1, IN3, IN2, IN4);

BlynkTimer timer;
BLYNK_CONNECTED() {
  Blynk.syncVirtual(V2);
  Blynk.syncVirtual(V3);
  Blynk.syncVirtual(V4);
  Blynk.syncVirtual(V5);

}
BLYNK_WRITE(V2) {
  digitalWrite (LEDRED, param[0].asInt());
}
BLYNK_WRITE(V3) {
  digitalWrite (LEDGREEN, param[0].asInt());
}

BLYNK_READ(V4) {
  Blynk.virtualWrite(V4, dist);
}
void distSensor() {

  digitalWrite(trigger, LOW);
  delay(5);
  digitalWrite(trigger, HIGH);
  delay(5);
  digitalWrite(trigger, LOW);
  duration = pulseIn(echo, HIGH);
  dist = duration * 0.034 / 2;
  Blynk.virtualWrite(V4, dist);
  if (dist== 8 && notif == false ) {
    Blynk.notify("Your water is low, fill the tank");
    digitalWrite(LEDRED, LOW);
    digitalWrite(LEDGREEN, HIGH);
  }
  else {
    digitalWrite(LEDRED, HIGH);
    digitalWrite(LEDGREEN, LOW);
  }

  if (dist== 3 && notif == false ) {
   Blynk.notify("Your water is full, turn off the tap");
   digitalWrite(LEDRED, LOW);
    digitalWrite(LEDGREEN, HIGH);
  }
  else {
    digitalWrite(LEDRED, HIGH);
    digitalWrite(LEDGREEN, LOW);
  }
}

BLYNK_WRITE(V5) {
  myStepper.step(param.asInt());
}

void setup()
{

   lcd_i2c.begin  ();
  lcd_i2c.backlight();
  digitalWrite(LEDRED, HIGH);
  digitalWrite(LEDGREEN, HIGH);
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass, "  ", ); 
  pinMode(LEDRED, OUTPUT);
  pinMode(LEDGREEN, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(trigger, OUTPUT);

  myStepper.setSpeed(15);

  Serial.begin(115200);
  // myServo.attach(servoPin);

  timer.setInterval(1000L, distSensor);
   //lcd_i2c.setCursor(2, 0);
// lcd_i2c.print("Water level");

  //timer.setInterval(1000L, servo_button1);
  //timer.setInterval(1000L, servo_button2);
}

void loop()
{
  lcd_i2c.setCursor(0, 0);
 lcd_i2c.print("Water level IoT");

  Blynk.run();
  timer.run();

 // lcd_i2c.setCursor(2, 0);
 //lcd_i2c.print("Water level");

  int u;
  lcd_i2c.setCursor(0, 1);
  lcd_i2c.print("Innovation of Industry 4.0");
  for (u = 0 ; u < 16; u++) {
    lcd_i2c.scrollDisplayLeft();
    //lcd.scrollDisplayRight();
    delay(500);
  }
}
per1234 commented 6 days ago

Hi . Thanks for your interest in this open source project. This issue tracker is only to be used to report bugs or feature requests specific to the project. This is NOT an appropriate place to share or request assistance with your projects.

The appropriate place to share your projects is on the Arduino Project Hub:

https://projecthub.arduino.cc/

The appropriate place to request project assistance is on Arduino Forum

https://forum.arduino.cc/