"Blynk Connection Issue with Arduino and ESP8266 in IoT Project"

20 views Asked by At

I'm working on a project where I'm using an Arduino Uno with a sensor to detect objects. I also have an ESP8266 module that I want to use to send notifications to a user whenever the sensor detects an object.

I've already set up the sensor and the Arduino code to detect objects and trigger actions accordingly. However, I'm unsure about how to establish communication between the Arduino Uno and the ESP8266, and how to configure the ESP8266 to send notifications to a user's device

Here's my current Arduino code:

#include <SoftwareSerial.h>



// Define pins numbers

const int trigPin = 9;

const int echoPin = 10;

const int buzzerPin = 11;

const int ledPin = 13;



// Define variables

long duration;

int distance;

int dangerDistance; 



SoftwareSerial espSerial(2, 3); // RX, TX



void setup() {

  Serial.begin(9600);

  espSerial.begin(9600); // Initialize SoftwareSerial for communication with ESP8266



  pinMode(trigPin, OUTPUT);

  pinMode(echoPin, INPUT);

  pinMode(buzzerPin, OUTPUT);

  pinMode(ledPin, OUTPUT);

}



void loop() {

  // Clears the trigPin

  digitalWrite(trigPin, LOW);

  delayMicroseconds(2);



  // Sets the trigPin on HIGH state for 10 microseconds

  digitalWrite(trigPin, HIGH);

  delayMicroseconds(10);

  digitalWrite(trigPin, LOW);



  // Reads the echoPin, returns the sound wave travel time in microseconds

  duration = pulseIn(echoPin, HIGH);



  // Calculating the distance

  distance = duration * 0.034 / 2;

  dangerDistance = distance;



  if (dangerDistance <= 5) {

    digitalWrite(buzzerPin, HIGH);

    digitalWrite(ledPin, HIGH);



    // Send distance data to ESP8266

    espSerial.print("D:");

    espSerial.println(distance);

  } else {

    digitalWrite(buzzerPin, LOW);

    digitalWrite(ledPin, LOW);

  }



  // Prints the distance on the Serial Monitor

  Serial.print("Distance: ");

  Serial.println(distance);



  // Add a delay before the next iteration

  delay(1000);


}

What I've Tried:

Explored online tutorials for Arduino-ESP8266 communication but found them unclear. Successfully connected ESP8266 to Wi-Fi and tested basic AT command communication. Set up Blynk project, obtained token, and tested basic functionality with Blynk app.

Expectations:

Seeking guidance on reliable communication setup between Arduino Uno and ESP8266. Want to configure ESP8266 to send notifications (via Blynk or other methods) when Arduino sensor detects an object

0

There are 0 answers