Control Arduino remotely when being in different places

Hello everyone,

I am making an Arduino Project, and this project is far from where I am right now. I would like to ask if it is possible to control via wifi or some other option and control or monitor the Arduino itself. For example, send commands through an Android APP, those type of things.

I have seen projects with wifi control but all of them consists on the person being near the Arduino and use the same wifi internet.

Thank you in advance.

Best Regards,

Daniel

Something like Blynk or Cayenne is probably what you are looking for.

That's quite straightforward to do.

Step 1: get a fixed external IP address for your network (ask your ISP for that - if you're on a business connection it should be a no-brainer, if you're on a home connection it's probably not possible). Then you can simply point your browser to that IP address (forget about an app if a web site can do - saves a lot of work).

If you can't get a fixed IP address: get a domain name and a DynDNS account to handle your constantly changing home IP address. Some routers have built-in support for DynDNS accounts.

Step 2: have your router forward a specific port (incoming connections on port 80 (http) or 443 (https - recommended)) to the internal IP of your project.

So that sorts the connection.

Now, if your project doesn't need too many IO ports consider replacing the Arduino by an ESP8266, which has the WiFi connectivity built in.

wvmarle:
That's quite straightforward to do.

Step 1: get a fixed external IP address for your network (ask your ISP for that - if you're on a business connection it should be a no-brainer, if you're on a home connection it's probably not possible). Then you can simply point your browser to that IP address (forget about an app if a web site can do - saves a lot of work).

If you can't get a fixed IP address: get a domain name and a DynDNS account to handle your constantly changing home IP address. Some routers have built-in support for DynDNS accounts.

Step 2: have your router forward a specific port (incoming connections on port 80 (http) or 443 (https - recommended)) to the internal IP of your project.

So that sorts the connection.

Now, if your project doesn't need too many IO ports consider replacing the Arduino by an ESP8266, which has the WiFi connectivity built in.

wooow, that is way out of my league. Is there a tutorial some where with this information?

Thanks for the reply

Daniel

rucabelda:
wooow, that is way out of my league.

And most everybody else's.
Read reply #1 again, for something a bit more friendly to ordinary folk. Switching to an ESP8266 is a pretty good idea though, even if you already have an Arduino, but not yet a WiFi shield.

Getting to communicate through a firewall is a problem indeed (as that's of course in part due to what a firewall is designed to stop from happening - so you have to actively enable this).

Blynk solves it with an external server, but then the MCU has to constantly call that server to drop off information for the app to retrieve and see whether there's any new command waiting, and this causes delays (a few seconds maybe - for many applications this is not an issue).

Neither are ideal solutions.

wvmarle:
Step 2: have your router forward a specific port (incoming connections on port 80 (http) or 443 (https - recommended)) to the internal IP of your project.

So once I do that, how does that affect my web browsing or other things of that sort on my other computers on the same network? That's the thing I never really understood. Never really got into networks much. I read that somehow as all my incoming traffic using http would get sent to the esp8266 instead of the other computers. But the other computers are all able to share those things so maybe the esp can share too? I honestly don't know this stuff.

Incoming port forwarding shouldnt affect normal activity at all.

When you are browsing a website the communication is between a random high-numbered port on your home router and port 80 or 443 at the website end. At no stage should a remote website be sending back traffic to your local port 80 or 443- it will be sent to the random high port used by the original request.

And before anyone jumps on me- the above is actually more complicated because your home router does Network Address Translation but that is left, as they say, as an exersize for the reader.

You may find this article useful: Interact With the Web in Real-time Using Arduino, Firebase and Angular.js | by pancy | Code Zen | Medium

OK thanks. That makes a little more sense. I didn't know that 80 wasn't for both ends.

What is the reason for choosing those two as opposed to some other random high numbers?

Skip the local webserver idea. Keep a database online that can be polled. Much safer. Even an MQTT setup is simple and there are several good apps for Android.

wvmarle:
Getting to communicate through a firewall is a problem indeed (as that's of course in part due to what a firewall is designed to stop from happening - so you have to actively enable this).

Blynk solves it with an external server, but then the MCU has to constantly call that server to drop off information for the app to retrieve and see whether there's any new command waiting, and this causes delays (a few seconds maybe - for many applications this is not an issue).

Neither are ideal solutions.

This is incorrect. The delay is almost unnoticeable. The delay is in the hundreds of milliseconds, not multiple seconds. I use Blynk myself and I also run a MQTT server on my local network. I cannot notice any difference in terms of delay.

But if you are having delay you can also run a Blynk server on your local network.

Delta_G:
OK thanks. That makes a little more sense. I didn't know that 80 wasn't for both ends.

What is the reason for choosing those two as opposed to some other random high numbers?

The remote web server is listening for incoming requests on port 80 and 443.

Delta_G:
OK thanks. That makes a little more sense. I didn't know that 80 wasn't for both ends.

What is the reason for choosing those two as opposed to some other random high numbers?

To expand a little on srnet's answer:

80 and 443 are "well known ports" (you can see the complete list at List of TCP and UDP port numbers - Wikipedia)

When your browser sees a URL like http://www.google.com its programmed to connect to port 80 (https connects to 443).

While you can run a webserver on any port you like you would have to specify the port number in the URL eg
http://www.example.com:8080 which tells your browser to connect to port 8080 instead of the default 80. This used to be a fairly common way of testing a new version of a website but its less common now that you can spin up a new VM with minimal cost or effort.

Ports below 1024 are considered special by the OS and require super-user rights to bind to. This used to be a security thing when computers on the internet were rare - nowdays anyone can get full admin rights on an Amazon or Redhat Virtual server for less than they spend on coffee in a month so its not so trustworthy anymore.

Lennyz1988:
Something like Blynk or Cayenne is probably what you are looking for.

I don't find Cayenne anywhere..

Blynk seems to me a bit limited. No? I don't know how to work either the app Blynk. How does the communication works between the arduino board and the app? don't I need a ESP8266 ?? Is it obligatory to have one?

I have seen some tutorials, but all of them seem a bit complex (lack of explanation) and others are too simple, only controlling leds..

Best regards,

Daniel Sousa

rucabelda:
I don't find Cayenne anywhere..

Blynk seems to me a bit limited. No? I don't know how to work either the app Blynk. How does the communication works between the arduino board and the app? don't I need a ESP8266 ?? Is it obligatory to have one?

I have seen some tutorials, but all of them seem a bit complex (lack of explanation) and others are too simple, only controlling leds..

Best regards,

Daniel Sousa

So you don't know much about how to do anything, but what you see isn't good enough for you?
How about you explain what your great project is, since it's so much more complex than 'only controlling LEDs'?

rucabelda:
I don't find Cayenne anywhere..

Blynk seems to me a bit limited. No? I don't know how to work either the app Blynk. How does the communication works between the arduino board and the app? don't I need a ESP8266 ?? Is it obligatory to have one?

I have seen some tutorials, but all of them seem a bit complex (lack of explanation) and others are too simple, only controlling leds..

Best regards,

Daniel Sousa

It won't get any simpler then Blynk or Cayenne. Blynk and Cayenne are aimed to be as simple as possible with tons of features. They even have a code builder, plenty of examples and extensive tutorials. If you don't understand the functions, then put more time into understanding them.

INTP:
So you don't know much about how to do anything, but what you see isn't good enough for you?
How about you explain what your great project is, since it's so much more complex than 'only controlling LEDs'?

Thank you for all the answers.

I would like to mention that I am new to the Arduino World and also don't know anything about networks, so any terms like port 80, 443, MQTT, MCU, DNS, IP, ISP, DynDNS are unfamiliar to me. On top of that, I have no idea Blynk works.

My project at the moment that is working right now (still needs to be physically implemented but it is doing what I want) is: automated watering system - Soil moisture sensors read the moisture of the soil and Arduino turns ON or OFF a solenoid valve to water the plants according the humidity in the soil. This is the current project.

What I would like in the future:

This project will be implemented in another location, around 200 km apart, and I would like to monitor and control the watering system - see the soil moisture during the day (graphs for example), send a command to water the plants or just stop watering at all in case of rainy days for example. This change of information/commands could be done via Computer or even cooler an App.

Off course, when I am going to do this, I will get more into the stuff.. but the information I am getting right now are a bit overwhelming but also interesting.

Best regards,

Daniel

The part for turning the valve is exactly the same when you would switch a led on or off. No difference at all. Your project is not that hard, just take your time, read and learn :slight_smile: