BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Mega 2560, Hc-05, Sr-04 and Blynk

Hey guys, I’m trying to send the serial.print lines from my loop section based on the data being gathered by the 6 ultrasound sensors. I’m using a hc-05 module to send the data to Blynk (LG, android phone) and I want to display each of the ‘warnings’ on the app. I just don’t know how to go about getting them on the screen. I’d ideally like to display 6 virtual LED lights again based on the measurments taken.

Any help is much appreciated,
Thank you

//The following twelve lines set pin numbers for the ultrasonic sensors. 
int trigPin1=7; //Front transmitter (Object ahead detection).
int echoPin1=6; //Front receiver.
int trigPin2=5; //Right transmitter (Lane keeping).
int echoPin2=4; //Right receiver.
int trigPin3=3; //Rear right transmitter (Right blindspot detection).
int echoPin3=2; //Rear right receiver.
int trigPin4=14; //Rear centre transmitter (Parking sensor).
int echoPin4=15; //Rear centre receiver.
int trigPin5=16; //Rear left transmitter (Left blindspot detection).
int echoPin5=17; //Rear left receiver.
int trigPin6=18; //Left transmitter (Lane keeping).
int echoPin6=19; //Left receiver.

void setup() {
  Serial.begin (9600); //Sets serial port to 9600
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);
  pinMode(trigPin3, OUTPUT);
  pinMode(echoPin3, INPUT);
  pinMode(trigPin4, OUTPUT);
  pinMode(echoPin4, INPUT);
  pinMode(trigPin5, OUTPUT);
  pinMode(echoPin5, INPUT);
  pinMode(trigPin6, OUTPUT);
  pinMode(echoPin6, INPUT);
}

void loop() {

  //Object Ahead Distance.
  long duration1, distance1;
  digitalWrite(trigPin1, HIGH);
  digitalWrite(trigPin1, LOW);
  duration1 = pulseIn(echoPin1, HIGH);
  distance1 = (duration1/2) / 29.1;
  
   delay(500);
   if (distance1 >= 40){
    Serial.println("Nothing Ahead, Okay ");}
   else if (distance1 <= 39 || distance1 >= 29){
    Serial.println("Vehicle Ahead, Slow ");}
   else if (distance1 <= 29){
    Serial.println("Stop");}

  //Right Lane Keeping.
  long duration2, distance2;
  digitalWrite(trigPin2, HIGH);
  digitalWrite(trigPin2, LOW);
  duration2 = pulseIn(echoPin2, HIGH);
  distance2 = (duration2/2) / 29.1;

    delay(500);
   if (distance2 <= 2){
    Serial.println("In Lane ");}
   else if (distance2 >= 2){
    Serial.println("Adjust Steering ");}
    
  //Rear Right Blind Spot Detection.
  long duration3, distance3;
  digitalWrite(trigPin3, HIGH);
  digitalWrite(trigPin3, LOW);
  duration3 = pulseIn(echoPin3, HIGH);
  distance3 = (duration3/2) / 29.1;

  delay(500);
   if (distance3 >= 20){
    Serial.println("Right Blind Spot Clear ");}
   else if (distance3 <= 20){
    Serial.println("Vehicle In Blindspot ");}
    
  //Parking Sensor.
  long duration4, distance4;
  digitalWrite(trigPin4, HIGH);
  digitalWrite(trigPin4, LOW);
  duration4 = pulseIn(echoPin4, HIGH);
  distance4 = (duration4/2) / 29.1;
  
   delay(500);
   if (distance4 >= 40){
    Serial.println("Nothing Behind, Okay ");}
   else if (distance4 <= 39 || distance4 >= 29){
    Serial.println("Object Behind, Slow ");}
   else if (distance4 <= 29){
    Serial.println("Stop" distance4);}

  //Rear Left Blind Spot Detection.
  long duration5, distance5;
  digitalWrite(trigPin5, HIGH);
  digitalWrite(trigPin5, LOW);
  duration5 = pulseIn(echoPin5, HIGH);
  distance5 = (duration5/2) / 29.1;

  delay(500);
   if (distance5 >= 20){
    Serial.println("Left Blind Spot Clear ");}
   else if (distance5 <= 20){
    Serial.println("Vehicle In Blindspot ");}
    
  //Left Lane Keeping.
  long duration6, distance6;
  digitalWrite(trigPin6, HIGH);
  digitalWrite(trigPin6, LOW);
  duration6 = pulseIn(echoPin6, HIGH);
  distance6 = (duration6/2) / 29.1;

    delay(500);
   if (distance2 <= 2){
    Serial.println("In Lane ");}
   else if (distance2 >= 2){
    Serial.println("Adjust Steering ");}
    Serial.print("\e[1;1H");
}

You need to read and implement this, before you do anything else:

Pete.

Thank you, I’ll have a read now.

I followed a tutorial earlier to get Blynk paired with the Hc-05 but couldn’t work out how to display the Serial.print data on the app. Most of the tutorials display the measured data whereas I want to display the “warnings”, based on the measurements. What would be the best examples to look at for this?

Thanks

You can echo your serial output to the Terminal widget, or just use the Terminal widget on its own.
Look at the documentation and examples for the Terminal widget.

Pete.

Update: I’ve had a read through the ‘keep your void clean’ article and have put together a script based on that and the bluetooth and terminal examples. The first line of the sctrip is generating the “‘BlynkTimer’ does not name a type” error. I’ve removed and manually installed the Blynk libraries as that seemed like a possible issue, with no luck.

Any help is again apprecaited.
Thanks

BlynkTimer timer; // Announcing the timer
#define BLYNK_USE_DIRECT_CONNECT
#define BLYNK_PRINT Serial

// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
#include <BlynkSimpleSerialBLE.h>
SoftwareSerial DebugSerial(30, 32); // RX, TX

#define BLYNK_PRINT DebugSerial

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "V_bpVuNp0cm8kzcFAm4KgqEzk4bnvY8z";

// Attach virtual serial terminal to Virtual Pin V1
WidgetTerminal terminal(V1);

// You can send commands from Terminal to your hardware. Just use
// the same Virtual Pin as your Terminal Widget
BLYNK_WRITE(V1)
{

  // if you type "Marco" into Terminal Widget - it will respond: "Polo:"
  if (String("Marco") == param.asStr()) {
    terminal.println("You said: 'Marco'") ;
    terminal.println("I said: 'Polo'") ;
  } else {

    // Send it back
    terminal.print("You said:");
    terminal.write(param.getBuffer(), param.getLength());
    terminal.println();
  }

  // Ensure everything is sent
  terminal.flush();
}

int trigPin1=7; //Front transmitter (Object ahead detection).
int echoPin1=6; //Front receiver.
int trigPin2=5; //Right transmitter (Lane keeping).
int echoPin2=4; //Right receiver.
int trigPin3=3; //Rear right transmitter (Right blindspot detection).
int echoPin3=2; //Rear right receiver.
int trigPin4=14; //Rear centre transmitter (Parking sensor).
int echoPin4=15; //Rear centre receiver.
int trigPin5=16; //Rear left transmitter (Left blindspot detection).
int echoPin5=17; //Rear left receiver.
int trigPin6=18; //Left transmitter (Lane keeping).
int echoPin6=19; //Left receiver.

void setup() 
{
// Debug console
  DebugSerial.begin(38400);

  DebugSerial.println("Waiting for connections...");

  // Blynk will work through Serial
  // 9600 is for HC-06. For HC-05 default speed is 38400
  // Do not read or write this serial manually in your sketch
  Serial.begin(38400);
  Blynk.begin(Serial, auth);
  Serial.println("Waiting for connections...");

  // Clear the terminal content
//  terminal.clear();

  // This will print Blynk Software version to the Terminal Widget when
  // your hardware gets connected to Blynk Server
  terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  terminal.println(F("-------------"));
  terminal.println(F("Type 'Marco' and get a reply, or type"));
  terminal.println(F("anything else and get it printed back."));
  terminal.flush();
  
  // put your setup code here, to run once:
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);
  pinMode(trigPin3, OUTPUT);
  pinMode(echoPin3, INPUT);
  pinMode(trigPin4, OUTPUT);
  pinMode(echoPin4, INPUT);
  pinMode(trigPin5, OUTPUT);
  pinMode(echoPin5, INPUT);
  pinMode(trigPin6, OUTPUT);
  pinMode(echoPin6, INPUT);
  timer.setInterval(1000, sensorDataSend); //timer will run every sec
}

void sensorDataSend()
{
//Object Ahead Distance.
  long duration1, distance1;
  digitalWrite(trigPin1, HIGH);
  digitalWrite(trigPin1, LOW);
  duration1 = pulseIn(echoPin1, HIGH);
  distance1 = (duration1/2) / 29.1;
  
   if (distance1 >= 40){
    Blynk.virtualWrite(V1, "Nothing Ahead, Okay");}  // sending sensor value to Blynk app
   else if (distance1 <= 39 || distance1 >= 29){
    Blynk.virtualWrite(V1, "Vehicle Ahead, Slow");}
   else if (distance1 <= 29){
    Blynk.virtualWrite(V1, "Stop");}

     //Right Lane Keeping.
  long duration2, distance2;
  digitalWrite(trigPin2, HIGH);
  digitalWrite(trigPin2, LOW);
  duration2 = pulseIn(echoPin2, HIGH);
  distance2 = (duration2/2) / 29.1;

   if (distance2 <= 2){
    Blynk.virtualWrite(V1, "In Lane ");
   else if (distance2 >= 2){
    Blynk.virtualWrite(V1, "Adjust Steering ");
    
  //Rear Right Blind Spot Detection.
  long duration3, distance3;
  digitalWrite(trigPin3, HIGH);
  digitalWrite(trigPin3, LOW);
  duration3 = pulseIn(echoPin3, HIGH);
  distance3 = (duration3/2) / 29.1;

   if (distance3 >= 20){
    Blynk.virtualWrite(V1, "Right Blind Spot Clear ");
   else if (distance3 <= 20){
    Blynk.virtualWrite(V1, "Vehicle In Blindspot ");
    
  //Parking Sensor.
  long duration4, distance4;
  digitalWrite(trigPin4, HIGH);
  digitalWrite(trigPin4, LOW);
  duration4 = pulseIn(echoPin4, HIGH);
  distance4 = (duration4/2) / 29.1;
  
   if (distance4 >= 40){
    Blynk.virtualWrite(V1, "Nothing Behind, Okay ");
   else if (distance4 <= 39 || distance4 >= 29){
    Blynk.virtualWrite(V1, "Object Behind, Slow ");
//   else if (distance4 <= 29){
//    Serial.println("Stop" distance4);}

  //Rear Left Blind Spot Detection.
  long duration5, distance5;
  digitalWrite(trigPin5, HIGH);
  digitalWrite(trigPin5, LOW);
  duration5 = pulseIn(echoPin5, HIGH);
  distance5 = (duration5/2) / 29.1;

   if (distance5 >= 20){
    Blynk.virtualWrite(V1, "Left Blind Spot Clear ");
   else if (distance5 <= 20){
    Blynk.virtualWrite(V1, "Vehicle In Blindspot ");
    
  //Left Lane Keeping.
  long duration6, distance6;
  digitalWrite(trigPin6, HIGH);
  digitalWrite(trigPin6, LOW);
  duration6 = pulseIn(echoPin6, HIGH);
  distance6 = (duration6/2) / 29.1;

   if (distance2 <= 2){
    Blynk.virtualWrite(V1, "In Lane ");
   else if (distance2 >= 2){
    Blynk.virtualWrite(V1, "Adjust Steering ");
    Serial.print("\e[1;1H");}
}

void loop()
{
Blynk.run();        // run Blynk magic
  timer.run();        // run timer every second
}```

Some of your code appears to be missing, because you’ve not included any of the Blynk libraries.

Pete.

Apologies, I’ve updated the above code. I’ve also included the script that combines the bluetooth and terminal examples below and it compiles okay. In the script above I’ve attempted entering the Timer functions and my project script within it.

Thanks

#define BLYNK_USE_DIRECT_CONNECT
#define BLYNK_PRINT Serial

// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
#include <BlynkSimpleSerialBLE.h>
SoftwareSerial DebugSerial(30, 32); // RX, TX

#define BLYNK_PRINT DebugSerial

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Attach virtual serial terminal to Virtual Pin V1
WidgetTerminal terminal(V1);

// You can send commands from Terminal to your hardware. Just use
// the same Virtual Pin as your Terminal Widget
BLYNK_WRITE(V1)
{

  // if you type "Marco" into Terminal Widget - it will respond: "Polo:"
  if (String("Marco") == param.asStr()) {
    terminal.println("You said: 'Marco'") ;
    terminal.println("I said: 'Polo'") ;
  } else {

    // Send it back
    terminal.print("You said:");
    terminal.write(param.getBuffer(), param.getLength());
    terminal.println();
  }

  // Ensure everything is sent
  terminal.flush();
}

void setup()
{
  // Debug console
  DebugSerial.begin(38400);

  DebugSerial.println("Waiting for connections...");

  // Blynk will work through Serial
  // 9600 is for HC-06. For HC-05 default speed is 38400
  // Do not read or write this serial manually in your sketch
  Serial.begin(38400);
  Blynk.begin(Serial, auth);
  Serial.println("Waiting for connections...");

  // Clear the terminal content
//  terminal.clear();

  // This will print Blynk Software version to the Terminal Widget when
  // your hardware gets connected to Blynk Server
  terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  terminal.println(F("-------------"));
  terminal.println(F("Type 'Marco' and get a reply, or type"));
  terminal.println(F("anything else and get it printed back."));
  terminal.flush();
}

void loop()
{
  Blynk.run();
}

So is your problem resolved now, or do you have a specific question?

Pete.

The script I posted in the 5th post of the topic generates the error '‘BlynkTimer’ does not name a type; did you mean ‘BlynkBitSet’?"

I’ve reinstalled the library as it seems like that is a common issue, but no luck.

That’s bexause you have this line:

BlynkTimer timer; // Announcing the timer

at the very top of your code before this line:

#include <BlynkSimpleSerialBLE.h>

which tells the compiler to use the Blynk library which contains the code that makes BlynkTimer work.

Also, these two lines conflict with eachother:

You have also managed to get yourself totally messed-up when it comes to your serial ports. The Mega has 4 serial ports, so there should be no reason whatsoever to use SoftwareSerial to create an additional serial port.
Maybe you should read this recent post:

:Pete.

Thank you Pete for your ongoing support. I really appreciate your help.

Following the links and advice you’ve provided I’ve managed to get a connection to my phone and the terminal constant printing 1’s. In the updated script below, it shows the text I want to print depending on the measurments taken by the sensors in the “void sensor” section. How do I display these instead of the numbers I’m currently getting?

Thank you

#define BLYNK_PRINT Serial

#include <BlynkSimpleSerialBLE.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Attach virtual serial terminal to Virtual Pin V1
WidgetTerminal terminal(V1);

// You can send commands from Terminal to your hardware. Just use
// the same Virtual Pin as your Terminal Widget
BLYNK_WRITE(V1);

BlynkTimer timer;

int trigPin1=11; //Front transmitter (Object ahead detection).
int echoPin1=10; //Front receiver.
int trigPin2=9; //Right transmitter (Lane keeping).
int echoPin2=8; //Right receiver.
int trigPin3=7; //Rear right transmitter (Right blindspot detection).
int echoPin3=6; //Rear right receiver.
int trigPin4=5; //Rear centre transmitter (Parking sensor).
int echoPin4=4; //Rear centre receiver.
int trigPin5=3; //Rear left transmitter (Left blindspot detection).
int echoPin5=2; //Rear left receiver.
int trigPin6=30; //Left transmitter (Lane keeping).
int echoPin6=32; //Left receiver.

void setup() 
{
    // put your setup code here, to run once:
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);
  pinMode(trigPin3, OUTPUT);
  pinMode(echoPin3, INPUT);
  pinMode(trigPin4, OUTPUT);
  pinMode(echoPin4, INPUT);
  pinMode(trigPin5, OUTPUT);
  pinMode(echoPin5, INPUT);
  pinMode(trigPin6, OUTPUT);
  pinMode(echoPin6, INPUT);
  
  Serial3.begin(9600);
 
  Serial.begin(9600); // Debug console
  
  Blynk.begin(Serial3, auth);

  Serial.println("Waiting for connections...");

  timer.setInterval(1000L, sensor);
}

void sensor()
{
//Object Ahead Distance.
  long duration1, distance1;
  digitalWrite(trigPin1, HIGH);
  digitalWrite(trigPin1, LOW);
  duration1 = pulseIn(echoPin1, HIGH);
  distance1 = (duration1/2) / 29.1;
  
   if (distance1 >= 40){
    terminal.println(V1, "Nothing Ahead, Okay");}
   else if (distance1 <= 39 || distance1 >= 29){
    terminal.println(V1, "Vehicle Ahead, Slow");}
   else if (distance1 <= 29){
    terminal.println(V1, "Stop");}
    Serial.print(distance1);
    Serial.println("cm");

     //Right Lane Keeping.
  long duration2, distance2;
  digitalWrite(trigPin2, HIGH);
  digitalWrite(trigPin2, LOW);
  duration2 = pulseIn(echoPin2, HIGH);
  distance2 = (duration2/2) / 29.1;

   if (distance2 <= 2){
    terminal.println(V1, "In Lane ");}
   else if (distance2 >= 2){
    terminal.println(V1, "Adjust Steering ");}
    Serial.print(distance2);
    Serial.println("cm");
    
  //Rear Right Blind Spot Detection.
  long duration3, distance3;
  digitalWrite(trigPin3, HIGH);
  digitalWrite(trigPin3, LOW);
  duration3 = pulseIn(echoPin3, HIGH);
  distance3 = (duration3/2) / 29.1;

   if (distance3 >= 20){
    terminal.println(V1, "Right Blind Spot Clear ");}
   else if (distance3 <= 20){
    terminal.println(V1, "Vehicle In Blindspot ");}
    Serial.print(distance3);
    Serial.println("cm");
    
  //Parking Sensor.
  long duration4, distance4;
  digitalWrite(trigPin4, HIGH);
  digitalWrite(trigPin4, LOW);
  duration4 = pulseIn(echoPin4, HIGH);
  distance4 = (duration4/2) / 29.1;
  
   if (distance4 >= 40){
    terminal.println(V1, "Nothing Behind, Okay ");}
   else if (distance4 <= 39 || distance4 >= 29){
    terminal.println(V1, "Object Behind, Slow ");}
//   else if (distance4 <= 29){
//    Serial.println("Stop" distance4);}
    Serial.print(distance4);
    Serial.println("cm");
    
  //Rear Left Blind Spot Detection.
  long duration5, distance5;
  digitalWrite(trigPin5, HIGH);
  digitalWrite(trigPin5, LOW);
  duration5 = pulseIn(echoPin5, HIGH);
  distance5 = (duration5/2) / 29.1;
    
   if (distance5 >= 20){
    terminal.println(V1, "Left Blind Spot Clear ");}
   else if (distance5 <= 20){
    terminal.println(V1, "Vehicle In Blindspot ");}
    Serial.print(distance5);
    Serial.println("cm");
    
  //Left Lane Keeping.
  long duration6, distance6;
  digitalWrite(trigPin6, HIGH);
  digitalWrite(trigPin6, LOW);
  duration6 = pulseIn(echoPin6, HIGH);
  distance6 = (duration6/2) / 29.1;

   if (distance2 <= 6){
    terminal.println(V1, "In Lane ");}
   else if (distance6 >= 2){
    terminal.println(V1, "Adjust Steering ");}
    terminal.println(V1, "\e[1;1H");
    Serial.print(distance6);
    Serial.println("cm");
    Serial.print("\e[1;1H");
}

void loop()
{
  Blynk.run();        // run Blynk magic
  timer.run(); // Initiates BlynkTimer
}

I think you need to add terminal.flush(); commands to send the data to the terminal widget. Take a look at the Terminal example in Sketch Builder.

Pete.

It seems ‘Blynk.virtualWrite’ instead of ‘terminal.println’ worked.

How can I jump back to the top of the first line once all lines have been displayed instead of constantly flowing? I used “\e[1;1H” for another terminal program but that doesn’t work with Blynk.

Thank you

Sorry, I have no idea which segment of code you’re referring to, or what it is that you’re trying to achieve.

Pete.

I’d like the terminal to jump back to the top after displaying all 6 results in the ’ void sensor’ section then write the new results over the top of the last ones. I’ve attached a video of how it looks in a desktop terminal program I have to make it clearer.

I’ve also tried the \r at the end with no luck.
Blynk.virtualWrite(V1, "Nothing Ahead, Okay", "\r");}

returning to the top and overwriting

Okay, I think you need to do a terminal.clear(); at the beginning of the void sensor() process.

Pete.

I think we can move this topic to solved now.

Thank you Peter for helping. I’ve posted my script below which enables the use of 6 ultrasound sensors each having warning signs which are displayed on the terminal widget dependant on the distances. The data is sent via a HC-05 Bluetooth module and once certain distances are seen the LED widgets change colour to warn the user.

#define BLYNK_PRINT Serial

#include <BlynkSimpleSerialBLE.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

WidgetLED led1(V2);
WidgetLED led2(V3);
WidgetLED led3(V4);
WidgetLED led4(V5);
WidgetLED led5(V6);
WidgetLED led6(V7);

#define BLYNK_GREEN     "#23C48E"
#define BLYNK_RED       "#D3435C"

// Attach virtual serial terminal to Virtual Pin V1
WidgetTerminal terminal(V1);

BlynkTimer timer;

int trigPin1=11; //Front transmitter (Object ahead detection).
int echoPin1=10; //Front receiver.
int trigPin2=9; //Right transmitter (Lane keeping).
int echoPin2=8; //Right receiver.
int trigPin3=7; //Rear right transmitter (Right blindspot detection).
int echoPin3=6; //Rear right receiver.
int trigPin4=5; //Rear centre transmitter (Parking sensor).
int echoPin4=4; //Rear centre receiver.
int trigPin5=3; //Rear left transmitter (Left blindspot detection).
int echoPin5=2; //Rear left receiver.
int trigPin6=14; //Left transmitter (Lane keeping).
int echoPin6=15; //Left receiver.

void setup() 
{
    // put your setup code here, to run once:
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);
  pinMode(trigPin3, OUTPUT);
  pinMode(echoPin3, INPUT);
  pinMode(trigPin4, OUTPUT);
  pinMode(echoPin4, INPUT);
  pinMode(trigPin5, OUTPUT);
  pinMode(echoPin5, INPUT);
  pinMode(trigPin6, OUTPUT);
  pinMode(echoPin6, INPUT);
  
  Serial2.begin(9600);
 
  Serial.begin(9600); // Debug console
  
  Blynk.begin(Serial2, auth);

  Serial.println("Waiting for connections...");

  timer.setInterval(1000L, sensor);

  led1.on();
  led2.on();
  led3.on();
  led4.on();
  led5.on();
  led6.on();
}

void sensor()
{
//Object Ahead Distance.
  terminal.clear();
  long duration1, distance1;
  digitalWrite(trigPin1, HIGH);
  digitalWrite(trigPin1, LOW);
  duration1 = pulseIn(echoPin1, HIGH);
  distance1 = (duration1/2) / 29.1;
  
   if (distance1 >= 40){
    Blynk.virtualWrite(V1, "Nothing Ahead, Okay", "\r");}
   else if (distance1 <= 39 || distance1 >= 29){
    Blynk.virtualWrite(V1, "Vehicle Ahead, Slow");}
   else if (distance1 <= 29){
    Blynk.virtualWrite(V1, "Stop");}
    Serial.print(distance1);
    Serial.println("cm");
    
      if (distance1 >= 40) {
    led1.setColor(BLYNK_GREEN);}
    else if (distance1 <= 29) {
    led1.setColor(BLYNK_RED);}

     //Right Lane Keeping.
  long duration2, distance2;
  digitalWrite(trigPin2, HIGH);
  digitalWrite(trigPin2, LOW);
  duration2 = pulseIn(echoPin2, HIGH);
  distance2 = (duration2/2) / 29.1;

   if (distance2 <= 2){
    Blynk.virtualWrite(V1, "In Lane");}
   else if (distance2 >= 2){
    Blynk.virtualWrite(V1, "Adjust Steering");}
    Serial.print(distance2);
    Serial.println("cm");
 
      if (distance2 = 2) {
    led2.setColor(BLYNK_GREEN);}
    else if (distance2 <= 2) {
    led2.setColor(BLYNK_GREEN);}
    else if (distance2 >= 2) {
    led2.setColor(BLYNK_RED);}
    
  //Rear Right Blind Spot Detection.
  long duration3, distance3;
  digitalWrite(trigPin3, HIGH);
  digitalWrite(trigPin3, LOW);
  duration3 = pulseIn(echoPin3, HIGH);
  distance3 = (duration3/2) / 29.1;

   if (distance3 >= 20){
    Blynk.virtualWrite(V1, "Right Blind Spot Clear");}
   else if (distance3 <= 20){
    Blynk.virtualWrite(V1, "Vehicle In Blindspot");}
    Serial.print(distance3);
    Serial.println("cm");

      if (distance3 >= 20) {
    led3.setColor(BLYNK_GREEN);}
    else if (distance3 <= 20) {
    led3.setColor(BLYNK_RED);}
    
  //Parking Sensor.
  long duration4, distance4;
  digitalWrite(trigPin4, HIGH);
  digitalWrite(trigPin4, LOW);
  duration4 = pulseIn(echoPin4, HIGH);
  distance4 = (duration4/2) / 29.1;
  
   if (distance4 >= 40){
    Blynk.virtualWrite(V1, "Nothing Behind, Okay");}
   else if (distance4 <= 39 || distance4 >= 29){
    Blynk.virtualWrite(V1, "Object Behind, Slow");}
//   else if (distance4 <= 29){
//    Serial.println("Stop" distance4);}
    Serial.print(distance4);
    Serial.println("cm");
    
      if (distance4 >= 40) {
    led4.setColor(BLYNK_GREEN);}
    else if (distance4 <= 29) {
    led4.setColor(BLYNK_RED);}
    
  //Rear Left Blind Spot Detection.
  long duration5, distance5;
  digitalWrite(trigPin5, HIGH);
  digitalWrite(trigPin5, LOW);
  duration5 = pulseIn(echoPin5, HIGH);
  distance5 = (duration5/2) / 29.1;

   if (distance5 >= 20){
    Blynk.virtualWrite(V1, "Right Blind Spot Clear");}
   else if (distance5 <= 20){
    Blynk.virtualWrite(V1, "Vehicle In Blindspot");}
    Serial.print(distance5);
    Serial.println("cm");
    
    if (distance5 >= 20) {
    led5.setColor(BLYNK_GREEN);}
    else if (distance5 <= 20) {
    led5.setColor(BLYNK_RED);}

    //Left Lane Keeping.
  long duration6, distance6;
  digitalWrite(trigPin6, HIGH);
  digitalWrite(trigPin6, LOW);
  duration6 = pulseIn(echoPin6, HIGH);
  distance6 = (duration6/2) / 29.1;

   if (distance6 <= 2){
    Blynk.virtualWrite(V1, "In Lane");}
   else if (distance6 >= 2){
    Blynk.virtualWrite(V1, "Adjust Steering");}
    Serial.print(distance6);
    Serial.println("cm");
    Serial.print("\e[1;1H");
 
      if (distance6 = 2) {
    led6.setColor(BLYNK_GREEN);}
    else if (distance6 <= 2) {
    led6.setColor(BLYNK_RED);}
    else if (distance6 >= 2) {
    led6.setColor(BLYNK_RED);}
}

void loop()
{
  Blynk.run();        // run Blynk magic
  timer.run(); // Initiates BlynkTimer
}