Imagine being able to communicate with any device from anywhere in the world. You can control your TV, lights, washing machine, dishwasher, toaster, coffee machine — anything you want — just for a few bucks.
You can do it with Arduino. I have a lot of these lying around in my room, ready to automate another device of mine.
In one of my previous articles, I covered how you can use Arduino as a switch to turn any device on or off.
Today, I will discuss the pros and cons of various wireless methods used to create communication between Arduino and smartphones. This would not only allow you to use your phone as a switch, but it would also enable it to send specific commands for operations and get the state from Arduino.
Various Ways to Send and Receive Data
There are multiple ways to set up communication between Arduino and a smartphone, and each one of them is useful in certain cases. Here are a few of them.
You can send and receive data using the HTTP protocol. HTTP POST and GET requests are used to establish communication. For this, you can use an ESP8266-NodeMCU module. This module can facilitate the connection and even has GPIO ports.
It is a stateless platform (i.e. the communication between devices is closed when the message is received by the receiver). HTTP is best for scenarios where the data does not need to be fetched frequently.
It requires less computational power.
- HTTP is comparatively slower than web sockets. A new connection has to be made every time you need to send or receive data.
A good analogy would be chatting: You send a message and wait for the reply to send another message. ESP32 HTTP GET and HTTP POST with Arduino IDE | Random Nerd Tutorials In this guide, you'll learn how to make HTTP GET and HTTP POST requests with the ESP32 board with Arduino IDE. We'll…randomnerdtutorials.com
Bluetooth consumes less energy than most wireless communication technologies (2.5 mW).
It is less prone to the interference of data, which can be the case with other wireless methods. It is best for short-range wireless communication.
Bluetooth is short-range communication technology and cannot function properly sometimes — even outside a room.
It does not allow internet connection. This defeats the purpose of true anytime-anywhere communication.
If you have a nerdy group of friends, it is the worst option, as it is prone to interceptions and attacks. Control LED RGB WS2812B using Bluetooth and Android Short tutorial how to control LED RGB WS2812B with Android Application through Bluetooth communication. This project is…create.arduino.cc
You can also use services such as Blynk, which has a mobile app for smartphones and a library for Arduino to set up communication.
Online services (advantages)
Online services usually won’t require much coding and hard work. Everything is done for you. You just need to connect the dots.
Paid services will regularly update and bring more features with time.
Allows you to control devices from anywhere in the world, anytime you want.
Online services (disadvantages)
These services are often not free or have restrictions or friction.
The service may not have certain features you need.
You are at the mercy of a third-party service, which may not be good if you are looking for commercial applications.
WebSocket is a stateful protocol (i.e. the connection is open until one of the devices disconnects). Unlike HTTP, web sockets do not need to make a new connection every time they want to send some data.
It the best choice for real-time applications such as gaming and trading, where there is a continuous flow of data.
A good analogy would be a phone call: Until a party disconnects, both the parties can talk and communicate.
- It is computationally expensive compared to the HTTP protocol and thus is only used when a real-time connection is necessary. ESP8266 NodeMCU WebSocket Server: Control Outputs (Arduino IDE) | Random Nerd Tutorials In this tutorial you'll learn how to build a web server with the ESP8266 using WebSocket communication protocol. As an…randomnerdtutorials.com
To use these technologies, you can either create a mobile app or use ESP8266 as a web server (for HTTP and WebSockets).
Let me know if you need any help.
Did you find this article valuable?
Support Shubh Patni by becoming a sponsor. Any amount is appreciated!