Best way to achieve real-time communication between arduino+esp8266 and android?

Hello,

I am trying to set up a small system were basically the goal is to have a motion detector sensor and whenever motion is detected, a notification is shown in an android device (Ideally the system would support all platforms but I'm assuming a single platform would make it easier to achieve)

What I've done:
I have managed to connect the PIR sensor to the arduino and effectively detect movement
I managed to connect the arduino to my local network and set a simple web server, to achieve this I have used an ESP8266 module (module not shield), updated its AT firmware, and I have used a library named WiFiESP to allow my arduino to communicate with the ESP through the AT commands

What I've tried:
I tried IFTTT, used web hooks, installed the app my phone. Discarted this solution after simulating a POST request to the service and seeing that it took 3 minutes for the notification to appear on my smartphone (after this I decided not to try and implement it on arduino)
I tried (unsuccessfully) to use google firebase, I set up the service but the problem was that the example I found on the internet used the wifiesp8266 library which, if I'm not mistaken, is a library to program the ESP itself and not the arduino (my setup is a bit different as I have mentioned - Arduino communicates with esp module via WiFiESP library that uses AT commands)

In light of this, is there any alternative solution you would recommend? Is there a more simple way to achieve what I want? The only goal of all this is for me to receive a notification on my phone everytime the motion sensor detects movement..

Thank you for reading this rather extensive post and for taking the time to help :slight_smile:

I don't know the best way, but this is a good site to search for examples and ideas https://randomnerdtutorials.com/ and it's quite easy to merge methods from various projects to get what you want or simply try them out to evaluate/gain experience.

Thingspeak is a good site for displaying data also can react to events/setpoints and perform various actions and alerts, including sending emails and interacting with IFFT

Here are a few questions that might help you further.

Does your sensor have a power supply, or does it need to run on a battery?

  • with power you can use WiFi
  • running on battery you need to look for a low power protocol like Bluetooth LE

Do you want the be in the room with your phone or do you want to be far away?

  • with BLE you can directly connect to your phone and use an app to see the data
  • with WiFi you can send data through your router to anything in the world
  • if you want to be anywhere but need the sensor on battery you might need a gateway e.g. a Raspberry Pi

Did you have a look at the new Arduino Nano 33 series? They even have the sensor onboard.

https://store.arduino.cc/arduino-nano-33-ble-with-headers
https://store.arduino.cc/arduino-nano-33-iot

"The only goal of all this is for me to receive a notification on my phone everytime the motion sensor detects movement.."

The basic setup will probably be an application on the android device acting as a server waiting for some type of notification from the arduino client that detects the condition. You will need to implement a method of communication between the two devices. There are probably various methods, but not necessarily simple or inexpensive. What is your android device, and what communication capabilities does it have?

How about sending email directly from Arduino. Your phone will get email notification when email comes. See a project on Arduino Project Hub

dnarciso:
The only goal of all this is for me to receive a notification on my phone every time the motion sensor detects movement..

With such a clearly expressed objective you have two obvious choices.

  1. Arduino sends an email using the Esp8266, thereby triggering a notification on the phone
  2. Arduino sends an SMS, using a phone shield, thereby ditto.
    The latter is probably easier to expedite but the shield is more expensive. Running cost would be dependent on your phone plan.

The deployment of the sensor is the same in both instances. If you use the ESP8266, the Arduino is probably redundant, which might have some bearing on your comment about the library.

God only knows what a web hook is.

If 3rd parties are involved (isp, cellphone provider), real time can never be guaranteed.

I've seen sms'es come in hours after they were sent.
Email servers or isp down is another problem if you go that route.

sterretje:
real time can never be guaranteed.

OK, LoL, I guess realtime is a relative term. I've never has a problem, but I don't text much. Still, of all the systems, I guess texting is the simplest, least demanding, and most reliable.

azeo:
I don't know the best way, but this is a good site to search for examples and ideas https://randomnerdtutorials.com/ and it's quite easy to merge methods from various projects to get what you want or simply try them out to evaluate/gain experience.

Thingspeak is a good site for displaying data also can react to events/setpoints and perform various actions and alerts, including sending emails and interacting with IFFT

At a first glance it looks like the tutoriais are very much based on the NodeMCU which can function as stand-alone solution, since I only have the ESP8266 module I do not think this will be of much help but I will explore further and see if I can gather some useful information from there, thanks! :slight_smile:

Klaus_K:
Here are a few questions that might help you further.

Does your sensor have a power supply, or does it need to run on a battery?

  • with power you can use WiFi
  • running on battery you need to look for a low power protocol like Bluetooth LE

Do you want the be in the room with your phone or do you want to be far away?

  • with BLE you can directly connect to your phone and use an app to see the data
  • with WiFi you can send data through your router to anything in the world
  • if you want to be anywhere but need the sensor on battery you might need a gateway e.g. a Raspberry Pi

Did you have a look at the new Arduino Nano 33 series? They even have the sensor onboard.

Arduino Nano 33 BLE with headers | Arduino Official Store
Arduino Nano 33 IoT | Arduino Official Store

No, it does not. My plan is to use the 5v port from the arduino to power the sensor.

Yes I believe wifi is the best solution, bluetooth would not be able to achieve communication between my arduino and smartphone as there are a few walls and the normal distance (from where I want to place the sensor to the smartphone) is about 20-30 meters.

The distance itself is not that far but is far enough to make bluetooth not usable I believe

I did not have a look at that arduino but still I would like to use my existent hardware if possible :slight_smile:

zoomkat:
"The only goal of all this is for me to receive a notification on my phone everytime the motion sensor detects movement.."

The basic setup will probably be an application on the android device acting as a server waiting for some type of notification from the arduino client that detects the condition. You will need to implement a method of communication between the two devices. There are probably various methods, but not necessarily simple or inexpensive. What is your android device, and what communication capabilities does it have?

I believe that could work, making the smartphone act as a web server and waiting for a specific request from the arduino, when the request comes it shows a notification.

The question is, if the app is running in the background, would it still be able to receive the request (would the web server still run when the app was in background)?

IoT_hobbyist:
How about sending email directly from Arduino. Your phone will get email notification when email comes. See a project on Arduino Project Hub

That is actually not a bad idea, and other members have also suggested this. I will definitely explore this. Thanks :slight_smile:

Nick_Pyner:
With such a clearly expressed objective you have two obvious choices.

  1. Arduino sends an email using the Esp8266, thereby triggering a notification on the phone
  2. Arduino sends an SMS, using a phone shield, thereby ditto.
    The latter is probably easier to expedite but the shield is more expensive. Running cost would be dependent on your phone plan.

The deployment of the sensor is the same in both instances. If you use the ESP8266, the Arduino is probably redundant, which might have some bearing on your comment about the library.

God only knows what a web hook is.

I will explore the email solution, the SMS comm would force me to have a SIM card with an associated cost and I do not want this.

Yes I agree the arduino would be redundant in that case, the only reason why I am using the arduino is to have more memory for the code required to do what I want.

Web hook is the name of a service in IFTTT, it is simply a web service.

Thank you for your input :slight_smile:

sterretje:
If 3rd parties are involved (isp, cellphone provider), real time can never be guaranteed.

I've seen sms'es come in hours after they were sent.
Email servers or isp down is another problem if you go that route.

I agree with you but if the communication is to happen inside a local network then realtime communication is more or less guaranteed, it will certainly not take 3 minutes. For this project I just need communication inside the same local network, I do not even need an ISP. I realized now that maybe I should have stated this in the beginning

"I believe that could work, making the smartphone act as a web server and waiting for a specific request from the arduino, when the request comes it shows a notification."

I haven't seen a smartphone being used or setup to support a web server running on them, but I'm not familiar with what is available for smart phones. If that could be done, that would be interesting.

dnarciso:
I realized now that maybe I should have stated this in the beginning

You're dead right about that. Your clearly stated need to place an alert on the phone strongly implies something that could keep you informed while on a business trip to Vladivostock, and rather more than "same local network".
See reply #11 and, BTW, you might find the ESP that I understand you already have has more memory than an Arduino.

Yes I agree the arduino would be redundant in that case, the only reason why I am using the arduino is to have more memory for the code required to do what I want.