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

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 »

Measure PWM Current with a Modified Moving Average

How do you measure a signal that keeps changing?

Measure PWM Current with MMA

Pulse Width Modulation (PWM) makes it possible to dim lights, control the speed of motors, and (with the help of filters) generate analog reference voltages. When measuring the voltage or current of a PWM signal, there are unique challenges. You can use this tutorial to measure PWM current with a modified moving average (MMA).

Continue Reading »

How a Brushed DC Motor works and how to use them

This Addohms Electronics Motor Tutorial goes into the third dimension. Using a 3D model, we show what makes a brushed DC motor, well, a “brushed motor.” (Hint: It’s the brushes!) Then, as usual, we break down two simple ways to control them with a microcontroller like the Arduino. You can use a single BJT Transistor (remember those from #10?), build a discrete H-Bridge to go in both directions, or use a popular H-Bridge chip like the L293D or L298D. (Notice the ‘D’!)

Tutorial Contents

The video starts with a couple of (mixed) motor examples. Do you know what a “stator” or “rotor” is? If not, that’s okay because that’s one of the first things we explain. After that, we add part like the commutator and brushes to make the Brushed DC Motor. After that is control with a transistor and an explosive reason you need a protection diode. 🙂 Then we show how an H-Bridge Works. Lastly, the advantages and disadvantages of this motor type.

You can see the full Brushed DC Motor Tutorial on YouTube or on the AddOhms page.

Social Media Guide for Engineers, a How-To

Click here to find the 1 magic trick to using social media ;)

Social Media Guide for Engineers

Engineers are notorious introverts. An untrue generalization is that introverts hate being social. Like all humans, introverts are social creatures. We just prefer only to discuss the topics which are of interest to us. We will listen to anything. This social media guide for engineers explains why and how you can participate in social media, without being social.

Let’s address something head-on. Gone are the days of just “here’s what I ate” or “I’m in the bathroom” social posts. Social media channels are mature platforms for communication. Sure, junk still exists. However. You can filter out the signal from the noise when you following my social media guide for engineers.

Continue Reading »

3D Printer Tips I wish I knew 3 years ago

Here's how I stopped getting annoyed

3d printer tips by bald engineer

While I bought my 3D printer a couple of years ago, in March of this year, it only had 75 hours of use. Since March, my counter is over 300 hours. Why? After spending some time doing the right tweaks my printer is printing crazy good. Here are some of my 3D printer tips.

Maybe you’re in the market for a printer, use one at school, get access to one through a maker space, or (like me) used to use yours for a desk ornament, these 3D printer tips are likely to help.

Continue Reading »

5 Common Arduino Programming Mistakes

Code compiles but doesn't work? Check these 5 mistakes.

5 common arduino programming mistakes

Whenever someone sends me some code that doesn’t work, there are a few common Arduino programming mistakes that I check. Some of these mistakes I make myself.  In most cases my code will compile just fine. Sometimes, these mistakes won’t generate any compiler error.

When my Arduino code is acting up, these are the first things I check. Here are my 5 common Arduino programming mistakes, I use to debug non-working code.

Continue Reading »