Uploading Arduino Code Wirelessly – OTA
Welcome back to another tutorial from RootSaid. In this post, I’ll be showing you how you can upload a code Over the Air to your WiFi-enabled Arduino board – Arduino OTA Code Upload, without using any USB cable.
What is Arduino OTA Code Upload?
Before going further, let’s take a moment and understand Arduino OTA Code upload. Usually, what will you do when you want to upload/update a code running in your Arduino Board of your Robot or your Smart Home system? Most of the time, we will have to turn off the whole system, disconnect the board from the PCB or breadboard, bring it closer to your laptop or your mobile phone, connect your Arduino Board to your PC, upload the code and push it back to the PCB. What if you could upload the code without doing any of that?
Arduino OTA Code Upload is a new feature that enables you to upload or update a new code to your project without even connecting the board to your PC.
How does Arduino Wireless Coding Works?
First, we will create an account, create a project in Arduino IoT Cloud, add our Arduino Board, and link it to the project. We will also configure the WiFi network through which this board will be communicating with the IoT Cloud. Once it is done, we will use the Arduino Online Sketch editor to write our program. The first program will contain codes to connect back to the Arduino IoT server and keep the board updated with the cloud. This will also enable the Arduino OTA Upload feature in the sketch editor. Once it is done, we can select the Over the Air option from the editor and click on upload.
What happens during Wireless Code Upload?
When we click upload with OTA Selected, the sketch is first compiled depending on the type of board that is linked to ‘Thing’. The compiled sketch is stored in an AWS S3 bucket. For those who are not aware of the S3 bucket, it is an online cloud service by Amazon where we can store files. At the same time, the target device is associated with the OTA file URL. Then, certain flags are set to logic that will initiate the board to start downloading the file that is stored in S3. Once the file is verified, the code is flashed. Get more details about Arduino Over the Air code upload from here.
Arduino OTA Code Upload Video Tutorial
If you are a beginner and you’re totally interested in building your own robots and electronic projects then this channel is for you.
My name is Jithin and I’m super excited to teach you everything you need to know about what you need to know. So let’s upload the first sketch Over the Air.
Steps to Upload Arduino Code OTA
Step 1 – Uploading Arduino Code Wirelessly- Creating a Thing
For that, the first thing you have to do is you have to create an account in Arduino IoT Cloud and sign into it. Once you have signed in you should be able to see all the things created by you. As you can see here I have created three things before.
A thing is like a project. For this project, I’ll be creating a new thing. To do that click on create thing and give it a name. Let’s name it OTA demo.
Step 2 – Adding Arduino Board
The next thing you have to do is, you have to link a board to this project.
To do that click on the select device and since we’ll be adding Arduino Nano 33 IoT, which is not in the device list, click on Setup > New Device > Set up an Arduino device.
At this point, you have to make sure that your Arduino Nano 33 IoT is connected to your PC and Arduino Create Agent is running on your PC.
As you can see here, Arduino Nano 33 IoT has been detected by an Arduino Create Agent. Now to configure that click on configure and give it a name. Click on next.
Now, a code will be uploaded to your board and will be configured for you. It will take up to five minutes. But it took only one minute for me. Now Arduino Nano 33 IoT has been added to our device list. Now click on done and go to devices. You should see nano 33 IoT with status ready to connect.
Step 3 – Adding Variables
Now go back to things and click on OTA demo. There if you want you can add variables. To add variables, click on add variable and give your variable a name, set variable type, and click on add variable. You should see your variable inside your thing configurations.
Step 4 – Setting Up WiFi
Now to set up WiFi, you have to click configure under Network. There you have to provide your WiFi name (SSID) and password. Now click on save and you are done. It’s time for coding.
Step 5 – Coding
You can straight away go to sketch. The best thing about Arduino IoT Cloud is they will generate a sample sketch that contains all the critical variables and functions which are needed to run the code. Now all you have to do is add the extra variables and the functions.
Preparing Code for OTA Upload
If you look here, you can see that Arduino Nano 33 IoT is connected to port COM 6 of our PC.
So guys here is the blink sketch. According to this code, the built-in led will turn on for one second and turn off for one second and will repeat the code. That means it will blink once every second. Now click on upload. At this point, we are uploading the code to the board via port COM 6; that means we are uploading the code through a USB cable.
Now if you take a look at the board you can see that the led is blinking once every second.
Uploading Arduino Code Over the Air
Now we will slightly modify the code. Let’s change the delay, let’s change it to 500 and 200. Now if you take a look at ports available, you can see that one more option is available to upload the code to your board; that is the Over the Air option. Now simply select Over the Air and click on upload. Code upload has been started but it will take a little bit more time than wired upload.
Once the code is uploaded you should see the blinking frequency has changed. That’s how you upload the code Over the Air to your Arduino board. Once this option is available you no longer have to connect your board to your PC using a USB cable you can upload the code wirelessly.
Get more details about Arduino Over the Air code upload from here.