Over-The-Air (OTA)
Learn how to utilize Over-The-Air (OTA), a feature that allows you to upload sketches remotely.
The new Arduino Cloud brings a lot of new things, and one of them is the OTA (over-the-air) feature. This feature allows you to upload programs wirelessly to your Arduino boards. This way, as soon as you have a compatible board connected to a WiFi network and configured to work with OTA, you won’t need to physically connect the board to the computer in order to upload new sketches to it. Instead, everything will work over-the-air.
Over-the-air update is now available through Arduino Cloud and the Arduino Cloud Editor, which is an always up-to-date online IDE that stores sketches in the Cloud. It also allows you to wirelessly upload sketches from a browser, to any board that is connected to that computer.
This tutorial will guide you through the necessary steps to configure your board to work with the OTA feature.
Compatible Hardware
OTA is supported on several Arduino devices, as well as many ESP32 devices.
Supported Arduino Boards
- Arduino UNO R4 WiFi
- Arduino MKR WiFi 1010
- Arduino Nano 33 IoT
- Arduino Nano RP2040 Connect
- Portenta H7
- Portenta Machine Control
- Nicla Vision
Verified ESP32 Boards Supporting OTA
The following ESP32 boards have been tested and verified to support OTA:
- ESP32-S2-DevKitC
- NODEMCU-32-S2
- WEMOS LOLIN D32
- ESP32-S3-DevKitC
- WEMOS LOLIN D32
- ESP32-CAM
- NodeMCU-32S
- Freenove ESP32 WROVER
- ESP32-DevKitC32E
- DOIT ESP32 DevKit v1
How does it work
In order to configure the feature, we will need to create a project in the Arduino Cloud following the next steps.
1. Go to the Arduino Cloud by clicking the Cloud icon in the top right of the Arduino homepage.
Note: You will need to have an Arduino account to be able to use both the Web editor and Arduino Cloud features.
2. Once you are logged in the Arduino Cloud, you need to create a new thing and name it something, for this example let's call it “smart_led”. Inside the thing let’s include a boolean variable called
light
, set variable permission to Read & Write and select the On Change variable update policy. Once we have these characteristics set, click on add variable.Note: If you want to know more about how to get started with the Arduino Cloud, visit the getting started tutorial.
3. Once you have added the variable, you’ll need to associate your device to this new thing and add your network credentials.
4. Next step is to create a dashboard with a Switch widget, linked to the lights variable that you created before. Once it is set, click on the use dashboard button and go to things > smart_led > Sketch
5. It is time now to edit the sketch. Let’s create a program that turns ON/OFF the
LED_BUILTIN
embedded on your board. To do so, you will need to add just four lines of code to the auto generated sketch:- Initialise as
the boolean variablefalse
at the beginning of the program.led_status
- Set as
theOUTPUT
pin of the board in theLED_BUILTIN
function.setup()
- Modify the state of the
pin with theLED_BUILTIN
variable in theled_status
function. To do so, let’s use theloop()
statement.digitalWrite()
- Add the statement
inside theled_status = !led_status
auto generated function.onLightChange()
Check the highlighted lines in the following code to see what required changes are.
6. Once the sketch has uploaded to your board, let’s check that everything is working as it should. To do so, go back to the Arduino Cloud and once in there, go to the smart_led dashboard we created before. Now, when you turn the light widget in the dashboard ON or OFF, the LED in your board should also turn ON or OFF.
Now that we have checked that everything is working as it should, let’s go back to the Things > smart_led > Sketch tab in the Arduino Cloud, and see what has happened there.
Once in the sketch tab, you'll see a toggle switch next to the board. The toggle switch lets us select a new option for connecting our board. Selecting the cloud icon instead of the USB icon means that when we upload to the board, it's done Over the Air.
If you select this option, you should be able to upload sketches to your board wirelessly. Let’s learn how to do it, by following the next steps.
1. Let’s modify the program in order to blink the LED each second when we click the button ON, and switch it Off when the button OFF is pressed. To do it, you will need to modify the
loop()
function by adding the highlighted lines shown in the following sketch.2. Power your board from a different power supplier than your computer's USB cable. Powering it through a phone charger's USB should be enough.
3. Once you have powered the board from a power source other than your computer, you should only see the Over-the-Air option. Select it, and upload the program to the board.
Note: This option will take a bit longer than usual, since the process of compiling and uploading the program to the board over-the-air is a longer process.
4. Now, if you switch the widget on the Arduino Cloud dashboard ON and OFF, the LED will either blink every second or go off.
But how does it work, inside?
An Arduino Cloud sketch is generated by the Arduino Cloud application, it leverages the Arduino Cloud and Arduino Connection Handler libraries to give your sketch IoT powers.
When uploading a sketch over-the-air:
- The sketch is compiled for the selected board type.
- The compiled file is stored in a AWS S3 bucket.
- OTA file url location is associated with the target device.
- OTA_REQ flag set to true to instruct the board to start the OTA file download.
- OTA file length/CRC is verified.
- Updated sketch is flashed on the board.
Conclusion
In order to upload sketches Over-the-Air to your Arduino board you need:
- An OTA Compatible board.
- An IoT Sketch to be uploaded.
Next steps
If you want to continue learning about amazing IoT features or projects you can check:
More tutorials
You can find more tutorials in the Arduino Cloud documentation page.
Suggest changes
The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.
License
The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.