Sending simple serial commands to an Arduino

Don't send words when characters will do

sending simple serial commands arduino

Sending simple serial commands to an Arduino is the easiest way to communicate between an Arduino and a computer. The computer could be a PC, a Raspberry Pi, or any device that communicates with serial.

By sending and “decoding” a single character it is easy to add a simple debug menu or even serial menu. Plus, it is easy to extend.

Single Character vs. Full Words

The mistake I see many people make is that they try to send full-text strings as serial commands. For example, to turn on a LED, I have seen (silly) commands like “RED LED ON” or “RED LED OFF.” While you could use something like strcmp(), as I showed on the Multiple MQTT Topics example, that tends to be overkill for most serial commands.

Humans like words, computers like binary. Just send one character over serial.

switch (variable) {
  case ‘a’:
	// A Stuff

  case ‘b’:
  case ‘c’:
	// B and C Stuff

Continue Reading »

Multiple MQTT Topics with Arduino PubSubClient

Adding a few more subscriptions is pretty easy.

multiple mqtt topics

In my Arduino MQTT Examples, I kept things simple by only subscribing to a single topic. One of the strengths of MQTT is that a device can subscribe (or publish) to multiple topics. The broker will sort things out. Even though my first example only showed one, it is straight forward to get the Arduino PubSubClient library to subscribe to Multiple MQTT topics.

The quick answer is that you need to look at the MQTT response to find out which topic sent the payload.

tl;dr version

If you’re looking for a quick answer, here’s the magic code we’ll add to the callback() function.

void callback(char* topic, byte* payload, unsigned int length) {
if (strcmp(topic,"pir1Status")==0)
  // whatever you want for this topic

Keep reading for a more detailed explanation of how to Subscribe to Multiple MQTT topics with Arduino’s PubSubClient. Obviously, this code will work on Arduino boards with a TCP/IP interface and, of course, the ESP8266 based boards.

Continue Reading »

It is commonly known that ceramic capacitors change capacitance with applied voltage. What isn’t always as well known is how strong this effect can be and why it occurs. At KEMET we’ve put together a technical video that answers that question.

What is Ask An FAE?

Ask An FAE is a new video series we launched at my day job, KEMET. An FAE is a field application engineer. These engineers are very common in the electronics industry. Companies like KEMET, where I work, have FAEs who meet with customers to answer technical (and very detailed) questions about how to use their products. In UBM’s Mind of an Engineer survey, FAEs were ranked as one of the top information sources for design engineers.

At KEMET we decide to use FAEs to answer the questions. While I’m not an FAE today, I was in the past and happy to kick off the series with our CEO.

Check out KEMET’s Ask An FAE

2016 Great Year for Enginerds

Top Tutorials from


While many want to call 2016 the worst year ever, I feel that is an entirely undeserved title. It certainly could have been a better year, but it wasn’t the worst that I can remember. For the engineering community, both professional and hobbyist, it seems to have been a fantastic year. My gauge for this feeling is the activity on In 2016, I saw almost half a million sessions contributing over 1.2 million page views. (That’s 98% more people looking at 313% more tutorials compared to 2015.)

Here’s a breakdown of the most visited pages (tutorials) on the site.

Overall Top 5 Tutorials for 2016

First up is a simple list with the most views, across all content.

  1. MQTT Tutorial for Raspberry Pi, Arduino, and ESP8266
  2. Raspberry Pi GUI Tutorial
  3. millis() Tutorial: Arduino Multitasking
  4. Arduino, how do you reset mills()?
  5. Top 4 transistors for your kit

Continue Reading »

ArcAttack is a band that performs at the Bay Area Maker Fare, among other places. They feature massive signing Telsa coils. (Here’s a video I show when I saw ArcAttack in 2013.) Singing Telsa coils are awesome. Everyone knows that. Which is why I found when Dianna Cowern, the Physics Girl, visited the band ArcAttack, electromagnets are just as cool. In addition to talking about their music, ArcAttack’s Joe does something amazing. He splits an aluminum soda can with just an electromagnet.

There are a few other neat tricks and some slow-motion stuff too. Near the end, he compresses a quarter with the scariest magnet setup I’ve ever seen. This video is definitely worth watching if you like anything related to Tesla coils–or electricity!

Wolfenstein 3D on Gameboy Color

Wolfenstein 3D defined the FPS genre in a way no one could have predicted. Just like the Gameboy defined portable gaming in a way no one could have predicted. Cartridge based computing and gaming offered something that disk (or disc?) based media never could: additional hardware.

The most famous example of additional hardware is the “SuperFX” chip that debuted with the SNES game Starfox. (It was in used in others in addition to a successor.) Most NES cartridges had other hardware too: mappers, sound generators, additional ram, etc. (more…)

If the Moon Were Only 1 Pixel

Josh Worth Art & Design

A tediously accurate scale model of the solar system

scrolling scale model of solar system

When I was growing up, I watched a lot of Star Trek. Over time I’ve looked into other Sci-Fi series. The occasional hit, like the reimaged Battlestar Galactica, caught my attention. But, for me, the voyages of the Enterprise defined “space” to me. Or the stories on Deep Space Nine. (There are no other Star Treks.)

Seeing a new alien or planet each week warps (see what I did there?) your mind to think that space is relatively small. But when you consider it takes almost 500 seconds for the light to travel from the Sun to the Earth, you begin to realize space is freaking huge.

That’s why this scrolling model of the solar system is so fantastic. It offers a unique sense of how “big” the universe really is–at least our solar system. Check it out on

Mooshimeter Review – Smartphone Multimeter

Can your phone replace your DMM?

Mooshimeter Review

For fifteen years I used my Radio Shack 22-168A digital multimeter as my go-to meter. A couple of years ago I bought a Fluke 115. Not because the RS meter lacked a measurement, but because I wanted a backlit screen. Here’s the crazy thing though in 20 years of multimeter development, there hasn’t been much innovation. Well outside of maybe auto-ranging.

All three meters I have, plus the Virtual Bench I reviewed about a year ago all continue to have the same limitation: they can only perform one measurement at a time. That’s one feature that makes my latest meter, the Mooshimeter, unique. It can measure both voltage and current at the same time. Oh, and it doesn’t have a screen.

Continue Reading »

Fading LED: analogWrite millis() Example

Add a fading LED without delay()

Fading LED millis() Example

It’s a well-known fact of engineering: LEDs make everything look better. And that means a Fading LED is even better. Using Arduino’s analogWrite(), fading a LED is just a matter of a loop. If you use delay(), you can’t easily add other actions. What can you do? Well, Fading a LED with millis() is pretty simple. Here’s the code to do it and a quick explanation.

Continue Reading »