Off-The-Shelf Hacker: Instantly Upgrade Your Arduino Project Design

Arduinos are great for low-power standalone jobs that simply read inputs, do a few calculations then set some outputs. They have a mix of analog and digital input/output pins and can talk to other boards over serial, I2C and other interfaces. They are also fast, use firmware-based programs and are single-minded in their function. They work great for a lot of jobs. My own project, Hedley the Robotic Skull now uses an Arduino Nano clone as a driver board for his jaw servo. I recently replaced the old Arduino NG with the Nano.
I was sitting there looking at the skull and it struck me. Could I swap an ESP8266-based module, commonly known as a NodeMCU dev kit, in place of the Arduino Nano and still have Hedley be able to talk to me. The two boards are about the same size. They cost about the same at under $5 each. They have similar pins, although there are some important differences, that we’ll cover later in this article. Lastly, you can program both boards with the Arduino IDE and associated libraries. Readers may recall recent discussions about using the NodeMCU in my yard sprinkler project.
Why would I replace an Arduino Nano with a NodeMCU? Let’s take a look.
Solve Problems Differently
A NodeMCU has built-in WiFi. Let that sink in for a minute.
While this is very cool, we certainly don’t need WiFi to move Hedley’s jaw servo, using some serial data from a Processing program on the Raspberry Pi. It is a near drop-in replacement, nevertheless for that particular job.
The LED-above-the-head revelation is that you can solve a whole new set of problems if your Arduino is easily networked.
We have to expand our “local hardware point solution” thinking into a “machine-to-machine” networked perspective. Perhaps many machines to many machines. That’s the essence of the Internet of Things (IoT), right?
I’m talking about making the jump from using a standalone microcontroller for trivial problems like moving Hedley’s jaw, to scale-able solutions using groups of little point solutions that talk to each other and the outside world. Keeping networking in mind becomes part of the design process that helps you realize solutions never before possible.
How About a Current Project Idea?
I don’t like the sensor lights in my back yard. First off, they are pretty pricey. Second, they aren’t that reliable. And, it’s hard to turn them all on at once. You definitely can’t turn them on remotely. Lastly, unless I see the light go on, there’s no way to know if anything or anybody has been in the backyard. What or who was creeping around the yard between midnight and 5:00 AM? Don’t know, no data.
An Arduino Nano, a passive infra-red sensor, a relay board, a little power supply and a pair of 20-watt LEDs could light up a corner of the yard when something passes in front of the device. That would give me what I have now.
By simply swapping in a NodeMCU and changing the firmware slightly I could instantly attain intruder logging capabilities, hardware status data, alarm activation or even initiate defensive measures. Using data collected over time we could track movement around the property and discover patterns that I could leverage to prevent problems or have vastly improved situational awareness.
I ordered the relay board and a small power supply last week. I’ll use one of my recently acquired NodeMCUs along with an infra-red sensor from the parts bin, in my new yard light project. The existing 150-watt sealed-beam spotlights can easily be wired to the relay board for the first iteration of the project. Replacing the sealed beams with 110-volt LED spotlights is trivial since they’re switched by the relay board as well.
NodeMCU vs. Arduino Nano
Like everything in engineering, there are a few trade-offs when subbing a NodeMCU for a Nano.
The NodeMCU board only has one analog input pin, so reading analog sensors isn’t really it’s strong point. It also has 13 general-purpose digital input/output pins, some of which share duty as the various communication interfaces, like I2C and SPI. You pretty much have to think digital sensors when using this board.
On the other side, the Nano has eight analog inputs, with everything else pretty much being the same as the NodeMCU. Big deal.
The other trade-off is power consumption. Since the NodeMCU board has a wifi radio, it will draw considerably more power when communicating with your local network, than the straight Arduino Nano without WiFi. Reports are you might hit 350 mA when transmitting data. I haven’t done any actual testing and that might be material for a future story. Needless to say, everybody on the web knows that ESP8266-based devices are pretty power hungry. Something to consider, although if you are running your project on a small power supply and not a battery, power consumption might be a non-issue.
The Nano printed circuit board is also roughly two-thirds the width of the NodeMCU board. They both are standard breadboard friendly. I’ve seen both boards available without pre-soldered header pins, so wiring them into your project is pretty easy.
Let’s Talk Firmware
Actually swapping the NodeMCU board for the Nano, on Hedley, took about five minutes. I used two breadboards and moved the wires from one to the other. Be aware that the Nano uses a 5-pin USB mini-b connector, whereas the NodeMCU uses a standard micro-B USB configuration. Cell phone cables typically use the later, so powering up your NodeMCU might be slightly easier.
Of course, you’ll need the right cable to program whichever board you choose.
Although the NodeMCU uses a built-in Lua programming implementation, I’m still using the Arduino IDE (integrated development environment) to write code. Moving from the Nano to the NodeMCU requires specifying the hardware under the “Tool” and “Board” menu. The “ESPduino (ESP-13 module)” selection worked fine. I did my tests using version 1.8.7 of the Arduino IDE software.
I switched the servo data pin to GPIO4 (physical pin D2) in the firmware for the NodeMCU board. I used GPIO6 in the Arduino NG and Nano versions. Other than that, the code was exactly the same.
Hedley’s jaw moved exactly the same way using the NodeMCU device, as it did with either the Nano or the antique NG board.
Be sure to check out the sample programs for all the ESP8266 devices in the Arduino IDE. There are a ton of them. Just take your existing Nano programs and hack in the ESP8266 (networking) parts.
Also, don’t forget that MQTT gives you one-to-many and many-to-one capabilities. There are lots of MQTT sample programs too. I’ll use MQTT messages to my Linux notebook or possibly a new MQTT broker as the data transport mechanism with both the yard sprinkler and the yard light projects. If an unwanted visitor comes into the yard not only could we turn on the lights, we might also run them off with a soaking from the sprinkler. Wouldn’t that be fun?
Networked design thinking. Get it?
Wrap Up
Standalone Arduino Nano projects are very inexpensive and definitely suit certain project requirements. With a little more effort and thinking “networking-ly,” the ESP8266-based modules are pretty darned useful.
Make the jump and open up a whole new world of physical computing.
Stay tuned for updates.
Feature image: Replacing The Arduino Nano With The NodeMCU board (ESP8266).