#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#define trigPin 13 // pins for first sensor
#define echoPin 12
#define trigPin1 11 // pins for second sensor
#define echoPin1 10
#define trigPin2 9 // pins for third sensor
#define echoPin2 8
#define trigPin3 7 // pins for fourth sensor
#define echoPin3 6
WidgetLED led1(V1); // Virtual LEDs for the app
WidgetLED led2(V2);
WidgetLED led3(V3);
WidgetLED led(V0);
char auth[] = ""; // Write your auth code here
void setup() {
Serial.begin(9600); // Begin serial communication
Blynk.begin(auth); // configure blynk and connect to it's server
pinMode(trigPin, OUTPUT); // Defining the functions of the pins
pinMode(echoPin, INPUT);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(trigPin3, OUTPUT);
pinMode(echoPin3, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
long duration,distance1,distance2,distance3, distance,duration2, duration3, duration1 ; // defining variables
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
digitalWrite(trigPin3, LOW);
delayMicroseconds(2);
digitalWrite(trigPin3, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin3, LOW);
distance = pulseIn(echoPin, HIGH);
distance1 = pulseIn(echoPin1,HIGH);
distance2 = pulseIn(echoPin2,HIGH);
distance3 = pulseIn(echoPin3,HIGH);
if (distance >= 200 || distance <= 0){
Serial.println("Out of range"); // running the condition for the LEDs
led.off();
}
else {
Serial.print(distance);
Serial.println(" cm");
led.on();
}
if (distance1 >= 200 || distance1 <= 0){
Serial.println("Out of range");
led1.off();
}
else {
Serial.print(distance1);
Serial.println(" cm");
led1.on();
}
if (distance3 >= 200 || distance3 <= 0){
Serial.println("Out of range");
led3.off();
}
else {
Serial.print(distance3);
Serial.println(" cm");
led3.on();
}
if (distance2 >= 200 || distance2 <= 0){
Serial.println("Out of range");
led2.off();
}
else {
Serial.print(distance2);
Serial.println(" cm");
led2.on();
}
}
Comments