Table of Contents
Today we will look at the newest member of the expanding Arduino Nano family, the Nano ESP32. This is the first Arduino to use an ESP32 as its primary processor instead of as a communications coprocessor.
Introduction
Most experimenters are familiar with the Arduino Nano boards. These compact microcontrollers have been around in one form or another since 2008. They are popular due to their simple factor; they fit nicely on solderless breadboards as well as perfboards and PCBs.
The Nano family has grown considerably since the first ATMega328-based boards were released. Newer models include WiFi and Bluetooth connectivity, more powerful microcontrollers, and more memory. But they have all retained the same pinout as the original board.
Today we will look at the newest member of the Nano family, the Arduino Nano ESP32. It’s the seventh Nano, and at about 18 US dollars, it’s the second cheapest (the least expensive Nano is the Nano Every at about 12 dollars).
Arduino Nano ESP32
The name of this new board pretty well says it all – this is an Arduino Nano based on an ESP32 microcontroller.
While this is the first Nano to have an ESP32 as its main processor (in fact, it’s the first Arduino board to use the ESP32 as its main processor), this is not the first Nano with an ESP32 chip. Two other boards, the 33 IoT and RP2040 Connect, use the ESP32 as a communications coprocessor.
The onboard ESP32-S3 has been mapped out to a standard Nano pinout. There is some additional memory, an onboard buck converter, and this is the first Nano to use a USB-C connector for power and data.
Welcome to the Family!
The Nano family has grown considerably since the first Arduino Nano was released in 2008. With the addition of the new Arduino Nano ESP32 board, there are now seven Nano boards:
- The original Arduino Nano – This board is a 5-volt logic device based around an ATMega328 microcontroller. It’s essentially an Arduino Uno R3 with two additional analog inputs, and is still very popular as it has been “cloned” by many manufacturers.
- The Nano Every – This is an upgrade to the original Nano. Like the original, it is a 5-volt logic device, however this board is based upon an ATMega4809 microcontroller. Currently, this is the least expensive Arduino Nano.
- The Nano 33 BLE – This board features Bluetooth connectivity but no WiFi. It’s a 3.3-volt logic device built around the nRF52840 microcontroller chip.
- Nano 33 BLE Sense – An upgraded version of the Nano 33 BLE, this board has many onboard sensors.
- The Nano 33 IoT – This Nano has both WiFi and Bluetooth connectivity, and is based upon the popular SAMD21 microcontroller.
- Nano RP2040 Connect – This board also has WiFi and Bluetooth connectivity. It is based upon the Raspberry Pi RP2040 microcontroller.
- The Arduino Nano ESP32 – The newest Arduino Nano, and currently the second least expensive (it’s four dollars cheaper than the original Nano). This is the board we are examining today.
All the Nano boards have essentially the same pinout, but as two boards use 5-volt logic, they are not necessarily drop-in replacements for one another.
Nano ESP32 Pinouts and Features
If you’ve used any of the Nano boards, you’ll recognize the pinout diagram for the new Nano ESP32, as all boards have common pinouts.
One thing that you’ll notice is that the following pinout diagrams include both the Arduino pin designation (i.e. D12) and the ESP32 GPIO pin number (i.e. GPIO47). This is done for two reasons:
- You can use the Espressif ESP32 boards manager with this board, instead of the Arduino boards manager. If you do, then you need to reference the pins using the ESP32 GPIO numbers.
- If you program in MicroPython you’ll need to use the ESP32 GPIO numbers to reference the pins.
Data Pins
The Arduino Nano ESP32 has the usual set of data pins and maintains the same pinout as the earlier Nano boards (including the strange reversal of D0 and D1).
You can also use the analog input pins as data pins if you don’t require an analog interface.
Analog Pins
The Arduino Nano ESP32 has eight analog to digital inputs. Each one is capable of 12-bits of resolution, but they default to 10-bits to maintain compatibility with older sketches.
UART
As with the earlier models, there is a single UART on pins DS0 and D1.
I2C
There is a single I2C bus whose connections default to analog pins D4 and D5 to maintain compatibility with older sketches and libraries. You can, however, reassign the I2C bus to a different set of pins.
SPI
The board has an SPI bus whose data and clock connections are illustrated above. Note that you can use any of the remaining data pins for CS (Chip Select).
Power
There are a couple of options for powering the Arduino Nano ESP32 board. The most common (and obvious) method is the USB-C connector, from which the board will draw 5 volts.
Another method of powering the board is to apply voltage to the VIN pin. It can accept voltages from 4.5 to 21 volts, but Arduino recommends keeping it in the 6 to 18-volt range.
As for voltage outputs, there is a 3.3-volt output that you can use to drive external peripherals and sensors. An on-board buck converter produces this voltage.
Another output is the VBUS pin, which only works when the board is powered by USB-C. It will provide 5-volts from the USB-C connector. If VIN powers the board, then there is no voltage on the VBUS pin.
As with the other Nano boards, the ground connections are marked with a white border for easy identification.
Boot & Reset
The Arduino Nano ESP32 has a reset button and a reset input pin.
There are also two pins, B0 and B1, that are used to enter bootloader mode. We will be discussing the use of these pins in more detail in the section about using MicroPython.
LEDs
There are three LEDs on the Arduino Nano ESP32 board.
The power LED is a green LED mounted beside the USB-C connector.
On the other side of the USB-C connector is an amber LED. This is the LED attached to data pin D13, a feature common to most Arduino boards.
There is also an RGB LED mounted next to the reset switch. You can use it in your programs, and it also is used to display status during bootloader operations.
Getting Started with the Arduino Nano ESP32
So now that you’ve seen an overview of the board, it’s time to get working with it!
Arduino IDE Setup
I’ll be working with the Arduino IDE 2.x for these experiments, as I prefer its advanced features. However, you can also use the older IDE version 1.8x if you wish.
The first step in working with the new Nano board is to install a boards manager. Arduino has provided a modified version of the ESP32 boards manager for this.
Open the IDE and click on the Boards manager icon (the “board” icon, second from top on the left). In the search box, type “esp32”. This should produce two results:
- An Arduino ESP32 Boards Manager
- An Espressif ESP32 Boards Manager
While you can actually use the Espressif boards manager, you are best to start with the Arduino one. Select it, and it will be installed in your IDE.
Once you have it installed, you can test it out by connecting your Nano ESP32 to your computer. You should be able to select it now from the connection dialog box.
WiFi Scan Test
As with all boards managers, the Arduino ESP32 boards manager will install a number of sample sketches that you can use to test out your board, or as the basis for your own programs.
The sketches installed are mostly generic ESP32 sketches, and some of them will require modifications to work with the Nano ESP32 board. Many of them, however, will work right out of the box.
One easy test of the board, one that also displays its communications capabilities, is to use the WiFi Scan Test sketch. This is a basic WiFi scanner that displays the SSID.
Load this sketch from the following location: File/Examples/Examples for Arduino Nano ESP32/WiFi/WiFiScan.
You can examine the sketch to see how it works, essentially it just loads the WiFi Library and uses the scanNetworks function. It then prints out the results to the serial monitor.
Load the sketch to your Arduino Nano ESP32 and give it a try. You should see a list of the WiFi networks in your vicinity, along with their signal strength and encryption type.
Building a Human Interface Device
One of the abilities of the Arduino Nano ESP32 is that it can be operated as a “Human Interface Device”, or HID. An HID is simply any device that humans can use to control a computer, typically a mouse or keyboard.
HID Mouse
We will be using the HID capabilities of the Arduino Nano ESP32 board to construct a mouse. This mouse will just use five pushbutton switches, four to move the mouse and one to serve as a left-click.
If you wish, you can expand this with one more pushbutton to serve as a right-click button.
HID Hookup
Here is how we will be hooking up our simple “mouse”:
All the pushbuttons are momentary-contact, normally-open devices.
HID Code
We will be using another one of the samples sketches that were installed along with the Arduino ESP32 Boards Manager. As I mentioned previously, many of these sketches were intended for other boards and will require some modification to work with the Nano ESP32. This is one of them.
The modifications are pretty simple, all you need to change is the I/O pin numbers used for the pushbuttons, as the ones in the original sketch are not all available on the Arduino Nano ESP32 board.
Here are the corrected pin numbers:
1 2 3 4 5 6 |
// set pin numbers for the five buttons: const int upButton = 12; const int downButton = 11; const int leftButton = 10; const int rightButton = 9; const int mouseButton = 8; |
Otherwise, the sketch remains as it was.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
/* ButtonMouseControl Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due. Hardware: - five pushbuttons attached to D12, D13, D14, D15, D0 The mouse movement is always relative. This sketch reads four pushbuttons, and uses them to set the movement of the mouse. WARNING: When you use the Mouse.move() command, the Arduino takes over your mouse! Make sure you have control before you use the mouse commands. created 15 Mar 2012 modified 27 Mar 2012 by Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/ButtonMouseControl */ #if ARDUINO_USB_MODE #warning This sketch should be used when USB is in OTG mode void setup(){} void loop(){} #else #include "USB.h" #include "USBHIDMouse.h" USBHIDMouse Mouse; // set pin numbers for the five buttons: const int upButton = 12; const int downButton = 11; const int leftButton = 10; const int rightButton = 9; const int mouseButton = 8; int range = 5; // output range of X or Y movement; affects movement speed int responseDelay = 10; // response delay of the mouse, in ms void setup() { // initialize the buttons' inputs: pinMode(upButton, INPUT_PULLUP); pinMode(downButton, INPUT_PULLUP); pinMode(leftButton, INPUT_PULLUP); pinMode(rightButton, INPUT_PULLUP); pinMode(mouseButton, INPUT_PULLUP); // initialize mouse control: Mouse.begin(); USB.begin(); } void loop() { // read the buttons: int upState = digitalRead(upButton); int downState = digitalRead(downButton); int rightState = digitalRead(rightButton); int leftState = digitalRead(leftButton); int clickState = digitalRead(mouseButton); // calculate the movement distance based on the button states: int xDistance = (leftState - rightState) * range; int yDistance = (upState - downState) * range; // if X or Y is non-zero, move: if ((xDistance != 0) || (yDistance != 0)) { Mouse.move(xDistance, yDistance, 0); } // if the mouse button is pressed: if (clickState == LOW) { // if the mouse is not pressed, press it: if (!Mouse.isPressed(MOUSE_LEFT)) { Mouse.press(MOUSE_LEFT); } } // else the mouse button is not pressed: else { // if the mouse is pressed, release it: if (Mouse.isPressed(MOUSE_LEFT)) { Mouse.release(MOUSE_LEFT); } } // a delay so the mouse doesn't move too fast: delay(responseDelay); } #endif /* ARDUINO_USB_MODE */ |
It’s a pretty simple sketch, thanks to the USB and USBHIDMouse functions. After defining the connections, they are set up as inputs. We also start the mouse and USB objects in Setup.
In the Loop, we read the state of the pushbuttons. If any of the directional pushbuttopns were pressed, then we determine the X and Y coordinates of the mouse and use a Mouse.move method to position our mouse pointer.
If the left-click switch was pressed, we use the Mouse.press method to create a “click”.
HID Demo
Load up the sketch and try it out! You can just test the “mouse” using the Arduino IDE, or you can use another program – pretty well everything uses a mouse!
I tested my “mouse” using the mouse test utility in Ubuntu Linux. It worked fine, I was able to position the cursor and do both a single and double click.
You could use something like this as part of an interface or automation project. There is also an equivalent sketch for emulating a keyboard.
Using MicroPython with the Arduino Nano ESP32
One of the features of the Arduino Nano ESP32 is that it can be programmed using MicroPython instead of C++.
Let’s see how we can do this.
MicroPython
MicroPython is a small implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimized to run on microcontrollers.
The project was launched in 2013 by Damian George, a physicist from the University of Cambridge, UK. George launched a Kickstarter campaign in 2013 to fund the initial development of MicroPython. The campaign was successful, raising over £97,000 from 1,920 backers.
The first board running MicroPython was the PyBoard, specifically designed for MicroPython. Since then, MicroPython has been ported to numerous microcontrollers, including the ESP32 and RP2040.
As an interpreted language, MicroPython is slower than C++. However, it is easier to work with and allows you to immediately test changes to your program without the need to compile and upload.
Installing MicroPython on the Nano ESP32
To work with MicroPython on the Nano ESP32, we must replace the bootloader program embedded in the microcontroller. Arduino has provided a tool to make this very easy.
Start by downloading the Arduino MicroPython Installer. This application is available for Windows, macOS, and Linux, so be sure to download the version appropriate for your computer. Install the application on your computer.
Enter Bootloader Mode
Before you can install the MicroPython bootloader, you will need to place the Arduino Nano ESP32 into “bootloader mode”.
While there is a method you can use by clicking the Reset button a few times, I find the following method much easier:
- Place the Nano ESP32 on a solderless breadboard or into a Nano prototyping board.
- Plug the USB-C cable into the Nano, and plug the other end into your computer’s USB port.
- Place a jumper wire temporarily between Ground and the B1 pin. There is a Ground pin right next to B1. The RGB LED should glow green, which is unsurprising as B1 is also connected to GPIO0, the same pin that drives the LED.
- Press and release the Reset button.
- Now remove the jumper wire. The LED will have its red and blue segments illuminated at half-brightness, so it will appear “violet”. This indicates that you are now in bootloader mode.
Install MicroPython
Now we can install our MicroPython bootloader. Run the Arduino MicroPython Installer application, and it should detect the microcontroller (ensure you don’t have any other microcontrollers connected to the computer).
Once the board is detected, all you need to do is press the big green “Install MicroPython” button. The application will get the latest release of MicroPython and install it.
The utility will also allow you to install the latest nightly build of MicroPython, something that I would not recommend unless you have a specific reason for doing so.
Arduino Lab for MicroPython Code Editor
Now that you have installed MicroPython on the Arduino Nano ESP32, the next step is to install an editor. The Arduino IDE will not work with MicroPython.
There are many editors out there suitable for the task, but today we will look at the one from Arduino. Although it isn’t as full-featured as other editors, it will do the job.
The Arduino editor is called the Arduino Lab for MicroPython, and it’s available for Linux, Mac, and Windows. You can download it from the Arduino site.
Once you have it installed, open the Arduino Lab for MicroPython. Take a few moments to “play” with it and get familiar with the interface.
You note a big yellow banner reading “Disconnected” on the bottom half of the interface. To connect your Arduino Nano ESP32, click the “Connect” button on the top taskbar. A modal window will pop up, displaying the connection(s) to any compatible microcontrollers. If you have more than one, I would exit and remove the second microcontroller!
Assuming that you just see one connection, click on it. Your Nano ESP32 will now be connected to your Arduino Lab for MicroPython editor.
Testing the MicroPython Installation
You can perform a quick test of the installation by running the script that comes up when you first open the editor.
The script is a simple one that just prints out a period ten times. Click on the Run button to see the results in the terminal at the bottom of the screen.
Another script you can run is the following one; it is essentially a MicroPython version of the Blink sketch.
1 2 3 4 5 6 7 8 9 10 |
from machine import Pin import time myLED = Pin(0, Pin.OUT) while True: myLED.value(0) time.sleep(1) myLED.value(1) time.sleep(1) |
Pin 0 is the green segment of the RGB LED, so this script will cause the LED to flash green once per second.
Test out the script on your Nano ESP32. Once you see it working, try modifying it to use a different LED segment.
This not only proves that your MicroPython installation is good, but it also illustrates how easy it is to edit MicroPython programs and see the results instantly.
Reinstalling the C++ Arduino Bootloader
Once you have installed MicroPython on the board, you will no longer be able to use it in the Arduino IDE. This makes perfect sense; after all, you have replaced the Arduino bootloader with the MicroPython one.
If you would like to reinstall the Arduino bootloader, it’s a pretty simple procedure. Just remember that you’ll be wiping out all of your MicroPython work, so you may want to use the file utilities in the Arduino Lab for MicroPython to
The first step in reinstalling the Arduino Bootloader is to put the board into bootloader mode, as you did earlier.
Once it is in bootloader mode, you can open up the Arduino IDE. I recommend having either the Blink sketch or a blank sketch open, as whatever is in the IDE will be transferred to the Arduino when the bootloader is installed.
The IDE should see the connection to the Nano ESP32, but it will likely identify the board incorrectly. You’ll have to open the connection and change it to the Arduino Nano ESP32.
The next step is to go into the Tools menu and scroll to Programmer. Highlight it, and a second item called “Esptool” will appear. You need to select this if it isn’t already selected.
Finally, open the Sketch menu and select Upload Using Programmer. This will load the bootloader and the sketch you have in the IDE.
Your Arduino Nano ESP32 is now back to running C++.
Join the Arduino IoT Cloud
In addition to its many other features, the Arduino Nano ESP32 is also compatible with the Arduino IoT Cloud. This makes it an ideal platform for building IoT applications, which you can program in C++ or MicroPython.
The Arduino IoT Cloud
The Arduino IoT Cloud is a cloud service that supports many microcontrollers and microcomputers, both Arduino and non-Arduino boards. You can control these devices and obtain data from them using a web-based Dashboard; there are also iOS and Android apps that mimic the dashboard’s functionality.
The Arduino Nano ESP32 is compatible with the Arduino IoT Cloud and is an inexpensive platform for building cloud computing devices.
Required Accounts
To perform the following experiment, you’ll need a couple of accounts, which you may or may not already have:
- An Arduino Account – This is a free account you can create using an email address. You may already have one of these, especially if you have placed a previous order from the Arduino Store or participated in the Arduino Forum.
- An Arduino Cloud Plan – There are several paid levels to choose from, as well as a Free tier. You can perform the following experiment using the Free tier if you don’t have a paid account.
Required Software – The Arduino Create Agent
Before connecting a board to the Arduino IoT Cloud, we must run a small program on our computer. This software, called the Arduino Create Agent, permits the web-based Arduino IoT Cloud and Web editor applications to get access to the USB port, which it needs to communicate with your microcontroller.
The Arduino Create Agent is available for Windows, macOS, and Linux. It is a one-time installation that will start and run in the background whenever you start your computer. You’ll see an Arduino icon in your system tray, and you can use this icon to stop the program if you wish.
Our IoT Cloud Project – Temperature & Humidity Meter
To illustrate the use of the Arduino Nano ESP32 with the Arduino IoT Cloud, we will build a small project.
Our project will be a simple temperature and humidity meter. Although it’s a basic design, it is pretty accurate, thanks to an Adafruit AHT20 temperature and humidity sensor. This is an I2C device that has an accuracy of 1% for temperature and 3% for humidity.
We’ll monitor the temperature and humidity using a dashboard.
Connecting the Arduino Nano ESP32 to the Arduino IoT Cloud
We’ll begin our project by connecting our Nano ESP32 board to the Arduino IoT Cloud and registering it. This step is required for every device that connects to the cloud.
If you haven’t done it yet, install the Arduino Create Agent on your computer. You can confirm that it is running by observing the Arduino icon in your taskbar. Also, connect your Arduino Nano ESP32 board to the USB port on your computer.
Now go to the Arduino IoT Cloud console. This page has several tabs at the top:
- Things – This tab, which opens by default, is where you configure the parameters, devices, and variables for your Things.
- Dashboards – Thai is where you will construct and view your dashboards.
- Devices – This is where you will list and configure the devices attached to your IoT Cloud.
- Integrations – This tab links to third-party integrations for the Arduino IoT Cloud.
- Templates – This is a list of templates to start a project.
We must go to the Devices tab to add our board to the cloud.
Once in Devices, click the Add button. This will pop up a dialog box, which will walk you through adding a new device.
The first thing that we need to do is tell it that we are adding an Arduino board to the cloud. After we do this, the application will search your USB ports for a compatible board.
When it finds the Arduino Nano ESP32, it will suggest a name for the board. Every device in the Arduino IoT Cloud requires a unique name. You can, and probably will want to, overwrite the name with one of your choices.
In the next step, you will get a screen with important information, including a unique Security Key. You must retain this information; without the Security Key, you won’t be able to create a Thing. There is a Copy button that copies the details to your clipboard, and you can also download a PDF with the information.
After you gave safely saved the security information, you can continue. After a few seconds, your board will be added to the list of boards you can use on the Arduino IoT Cloud.
Building a Thing
The central part of our project is our “Thing”, which contains the code and device information.
Go to the Arduino IoT Cloud Dashboard and open the Things tab. Click the Create button to build a new Thing.
Give your Thing a title, such as “IoT Weather”. It can be anything as long as it is unique.
Associate a device with your Thing by clicking the Select Device button. You’ll get a list of available devices, select the Nano ESP32 from the list (if this is your first time using the IoT Cloud, then it will be your only choice).
Now we need to create a couple of cloud variables. Cloud variables can be passed through the cloud between devices and dashboards. We require two variables, one for temperature and one for humidity.
Give each variable a unique name, such as “relHumid” and “celTemp”. For each one, make the following selections:
- Variable Type – Floating Point Number.
- Variable Permissions – Read Only.
- Variable Update Policy – On change.
Next, we need to connect a network to our Thing. Click the Configure button and provide the following information:
- WiFi Name – Your WiFi SSID
- Password – Your WiFi network password
- Secret Key – Paste the Secret Key you saved when connecting to the Arduino IoT Cloud.
Now we are ready to write our sketch. Actually, a lot of it has been written for us already.
IoT Cloud Sketch
When you configure the variables and network in your Thing, it automatically builds the structure of the sketch that you’ll use on the Nano ESP32 board. You can see this sketch in the Sketch tab.
You may note a number in red by the Sketch tab; this is the number of changes in the sketch since you last looked at it. Clicking on the red number will display the details of the changes made.
The sketch can be edited in the Sketch tab, but you’ll probably find it easier to work with using the Arduino Web Editor. Click the Open Full Editor button to open the Web Editor in a new tab.
There are actually a few files associated with the Thing:
- Main Sketch – This is what we will be editing. It will be named after the Thing.
- ReadMe.adoc – A Read Me file that you can edit to include details about your project.
- thingProperties.h – The Thing Properties. Do not edit this file!
- Secret – A file with your SSID, password, and Secret Key. In the Web Editor, this file is dynamically linked to the Network configuration settings. It’s a good idea to leave this file alone as well.
The only file we will concern ourselves with is the main sketch. We need to edit it to add code for the AHT20 sensor and to pass the sensor values to the two cloud variables we created earlier.
Here is our final sketch:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
/* Sketch generated by the Arduino IoT Cloud Thing "Untitled" https://create.arduino.cc/cloud/things/61049c2a-daa2-43b2-a629-2762f4906b5b Arduino IoT Cloud Variables description The following variables are automatically generated and updated when changes are made to the Thing float celTemp; float relHumid; Variables which are marked as READ/WRITE in the Cloud Thing will also have functions which are called when their values are changed from the Dashboard. These functions are generated with the Thing and added at the end of this sketch. */ #include "thingProperties.h" // Include Adafruit AHTX Library #include <Adafruit_AHTX0.h> Adafruit_AHTX0 aht; // Values to hold temperature and humidity float readtemp; float readhum; void setup() { // Initialize serial and wait for port to open: Serial.begin(9600); // This delay gives the chance to wait for a Serial Monitor without blocking if none is found delay(1500); // Defined in thingProperties.h initProperties(); // Connect to Arduino IoT Cloud ArduinoCloud.begin(ArduinoIoTPreferredConnection); /* The following function allows you to obtain more information related to the state of network and IoT Cloud connection and errors the higher number the more granular information you’ll get. The default is 0 (only errors). Maximum is 4 */ setDebugMessageLevel(2); ArduinoCloud.printDebugInfo(); if (!aht.begin()) { Serial.println("Could not find AHT20 Check wiring"); while (1) delay(10); } Serial.println("AHT20 found"); } void loop() { ArduinoCloud.update(); // Your code here // Create objects for sensor data sensors_event_t humidity, temp; // Populate temp and humidity objects with fresh data aht.getEvent(&humidity, &temp); // Serial Print Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C"); Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH"); //Update local variables readtemp = temp.temperature; readhum = humidity.relative_humidity; //Pass values to cloud variable celTemp = readtemp; relHumid = readhum; delay(500); } |
The area commented out at the top was generated by the Arduino IoT Cloud when we created our Thing. The generated sketch also included the reference to thingProperties.h and the Serial Monitor setup.
We have added a library from Adafruit for using our sensor and have created an object named “aht” to represent it. We also define two floats to store the temperature and humidity.
In the Setup, we have added a line to start the AHT20 sensor; the Arduino IoT Cloud generated the rest of the code.
All the code in the Loop after “Your code here” is ours! We define sensor objects to represent temperature and humidity, populate them and then read them to the serial monitor. We then pass them to our local variables, which, in turn, are passed to the cloud variables. After a half-second delay, we do it all again.
Once you have the code in the editor, load it onto the Nano ESP32. Be patient when using the Web Editor, as it is much slower than the desktop IDE.
You can use the Serial Monitor in the Web Editor to see the results once the upload is done.
You should also see the variables dynamically updated in the Things configuration tab.
Building a Dashboard
The final step is to build a Dashboard, which is a set of online controls and displays that you can use with your Thing. These items are referred to as “widgets”.
Move over to the Dashboard tab and select the Create button to open a new dashboard for editing.
Your dashboard will be untitled, so the first step is to name it. As we are building a temperature and humidity monitor, you can select something like “IoT Thermometer”.
Now click the Add button. A list of widgets will appear. Select a suitable widget for displaying temperature, I chose a Gauge. The widget will be added to your canvas (you can reposition it later), and its editor will open.
The most important parameter here is the Link Variable, this is the cloud variable that the widget is attached to. Click on the Link Variable button to set the value. You’ll get a list of Things in the left panel; select the one we are working on. The right panel will display its cloud variables. Select the one you defined for temperature and click the Link Variable button to complete the task.
Repeat this task with the humidity variable. You can use another gauge or try the Percentage widget, which I used, as humidity is expressed as a percentage.
Both widgets should now display the readings from the sensor. You have now added your Arduino Nano ESP32 to the Arduino IoT Cloud and built a Thing and a Dashboard for it.
Conclusion
The Arduino Nano ESP32 is indeed an interesting board. Essentially, it’s another ESP32-S3 board, so you can directly compare it to offerings from Espressif and other manufacturers.
It does have a few advantages over other ESP32 modules. The main one is its size; the Nano form factor is perfect for solderless breadboards, whereas many Espressif modules are too large to fit.
But it also has fewer GPIO pins than many Espressif modules; in some applications that won’t matter, but occasionally, it’s a deal-breaker.
Its price is competitive, and being an Arduino product, the build quality is excellent. And, of course, you can count on Arduino to support the board with further documentation and updates.
I would certainly recommend that you put a few of these boards into your parts collection.
Welcome to the family, Arduino Nano ESP32!
Parts List
Here are some components that you might need to complete the experiments in this article. Please note that some of these links may be affiliate links, and the DroneBot Workshop may receive a commission on your purchases. This does not increase the cost to you and is a method of supporting this ad-free website.
Arduino Nano ESP32 – Arduino Store
AHT20 Temperature & Humidity – Adafruit
Resources
Arduino Nano ESP32 Cheat Sheet – A guide to the new Arduino Nano ESP32.
Arduino IoT Cloud Cheat Sheet – A guide to getting started with the Arduino IoT Cloud.
PDF Article – A PDF version of this article.
Code from Article – All of the code used here in one ZIP file
I really enjoy your videos, on a wide range of topics. I need someone that can point me in the right direction. I recently purchased an Arduino Nano ESP32 and I love it! I am already learning so much about developing hardware and software. I was able to successfully use board as a Serial Passthrough so that I can see the output of my Ultimate GPS breakout Board, I can see the streams of the GPS data coming through. I want to try and port this to the MicroPython environment and I am just not having any luck. I am… Read more »