Author Archives: SparkFun Electronics

IoTuseday: WiFi Maximizer with DIY Yagi-Uda Antenna

via SparkFun Electronics Blog Posts

In a previous IoTuesday post, I gave examples of makeshift antennas you could build at home. I wanted to make my own and create a kind of “WiFi Divining Rod.” I used a SparkFun ESP8266 Thing Dev board and OLED attached to the antenna, which would connect to a WiFi access point and display the received signal strength indication (RSSI) on the OLED. I could then change the antenna’s position and orientation to determine the best connection to the access point.

DIY Yagi next to ESP8266 Thing Dev board

I liked the design of the Yagi-Uda antenna, as they are simple to build and seem to be fairly forgiving (mine didn’t turn out particularly straight). I followed Biotele’s Instructable to create an antenna out of Popsicle sticks, paper clips and glue.

The Instructable shows a 15-element Yagi-Uda, which theoretically gets you about a 15 dBi gain (see here to learn more about decibel reference values). I needed something that was smaller and handheld. One nice thing about Yagi-Uda antennas is that you can just trim elements off the end and trade gain/beamwidth for antenna length (more or less – it does change the beam pattern).

You can download the AB9IL Java app that Biotele used in their article to view the beam pattern of a Yagi-Uda. Here, I entered the same dimensions of Biotele’s antenna and then removed the last eight “director” elements. This, in theory, would get me less gain (around 10 dBi) with a slightly wider beamwidth.

Yagi-Uda Plot

After building the antenna, I attached a Thing Dev board (using some foam tape) and an OLED to the end of the antenna’s backbone, which kept the U.FL cable as close as possible to the antenna’s driven element. I wrote a quick Arduino sketch that simply reported the RSSI of the WiFi connection on the OLED.

RSSI on OLED from ESP8266

I performed some basic tests to see how the custom Yagi-Uda compared against the Thing Dev board’s PCB antenna, and I was pleasantly surprised. I went out to the front of the SparkFun building (by our beehive – about 75 meters away from the building) and held up an unmodified Thing Dev board. I changed its orientation to find the highest RSSI, and the best receive strength I could get was around -67 dBm.

RSSI readings

I tested the RSSI again with the “WiFi Maximizer” (best name I could come up with for a Thing Dev board taped to a makeshift Yagi-Uda antenna), and found that that I could get around -61 dBm (same position, not necessarily the same orientation).

Testing the Yagi-Uda outside

With my completely unscientific testing, I figured I was getting around 6 dB of gain over the onboard PCB antenna, which isn’t bad considering the backbone was crooked, the elements weren’t exactly lined up, and there was no impedance matching whatsoever (among a whole host of other issues, I’m sure).

I have not performed a line-of-sight distance test, but I’m willing to bet I would be able to connect to our building’s WiFi at a farther range than with just the PCB antenna. If you’re looking for a quick (and very cheap) way to boost your Internet of Things (IoT) device’s connection, then this makeshift antenna is one good way. This might work well, for instance, in a classroom setting where students need to build a device to take measurements at a location where the nearest WiFi access point is a kilometer away.

Additionally, the directional nature of the Yagi-Uda means that you could potentially use this setup in a small-scale transmitter hunting game (assuming the transmitter was broadcasting a 2.4 GHz WiFi signal).

What other antenna tricks can you offer to help boost the range of IoT devices (specifically, something in the 2.4 GHz or 5 GHz bands) without spending a fortune?

comments | comment feed

Adventures in Science: Arduino Arithmetic Operators

via SparkFun Electronics Blog Posts

Building on data types and literals from last week, we look at how we can add, subtract, multiply and divide literals and variables in C and C++ (specifically, in the Arduino environment).

There are six main arithmetic operators in C and C++:

  • = is the assignment operator. It does not necessarily show equality but is used to set values to variables.
  • + is for addition. You can add two numbers or values in variables together.
  • - is subtraction, and it is used to subtract one number from another.
  • * is multiplication for multiplying two numbers together.
  • \ is division. Note that when using integers, you don’t get fractions or a remainder from this operation.
  • % is the modulo operator, and it is used to get the remainder from a division operation.

If you need a fractional result from division, you can use the float data type. If you’re using literals to perform the division, make sure you add some kind of decimal to one of the numbers. For example, 19 / 5 should be 19.0 / 5.

To make writing and reading code easier, you can use compound assignment operators. These perform some math operation on a variable and then store the result back in the same variable.

Operator Meaning Example
a += b a = a + b a += 3
a -= b a = a - b a -= 3
a *= b a = a * b a *= 3
a /= b a = a / b a /= 3
a %= b a = a % b a %= 3
a++ a = a + 1 a++
a-- a = a - 1 a--

The Arduino Reference Guide is still a good place to see which operators the Arduino supports.

While this video is intended as a reference for beginners, what slick tricks have you used or seen with operators? Any tips for good overloading practices? Please share your thoughts in the comments below.

comments | comment feed

Safe Cracking with Robots

via SparkFun Electronics Blog Posts

I have been infatuated with locks and mechanisms from a very early age. For my 7th birthday, my grandparents gave me a box of locks and keys; I promptly drove my parents insane as I ‘locked’ things around the house. Later, I signed up for all sorts of mail order ‘Train to be a Locksmith’ publications in an attempt to learn what was then the taboo black art of lockpicking.

Fast forward a few dozen years, and lock picking tools and how-to videos are cheap and prevalent. I have picked my way through many lock types and enjoyed teaching friends the meaning behind ‘locks keep honest people honest’ (household locks are surprisingly easy to pick, they just keep out honest people). In a similar vein, I have wanted to learn how to crack safes like they do in the movies. Yes, yes, we know it’s fake. But for every bad Hollywood scenario there is usually a grain of legitimacy buried in there somewhere. Safe cracking is a profession that’s been around since safes were invented. I wanted to know how much work and how viable safe cracking could be.

My wife is amazing; for Christmas this year, she gave me a fire safe she purchased off of Craigslist. It was super cheap because the seller didn’t have the combination. Best present ever.

Step 1) Get a safe that hasn’t been opened.

Step 2) Deploy robot army.

Common home combination fire safe

My safe is the very regular home-brand that is not particularly advanced but secure enough to deter crimes of convenience. If you know anything about ‘picking’ safes, you do it by feel. Manufacturers know this, so this safe has a ratchet built into the dial that fairly effectively thwarts the ability to listen or feel with a few additional safety features built-in as well. We’ll cover in detail how we built the safe cracking robot and all the lessons we’ve learned shortly after the safe is cracked. Now, let’s talk contest…

$200 in Prizes

We’re going to live stream the cracking of our safe starting at 10AM MDT on Wednesday, March 29th. It’s going to be a cross between watching a cliff hanger and paint drying. We’re only about 60% sure we’ll get the safe open. Who knows how long it will take? Comment on this post with your guess of how much time you believe it will take us to open the safe in the form hh:mm:ss. The closest guess wins a $100 gift cert to SparkFun. Additionally, you are encouraged to guess the combination in the format AA/BB/CC. The closest combination guess will also win $100. Price-Is-Right rules apply: closest without going over. We’ll use your time and combination guesses to break any ties if they arise. Comments and entries close at 9:59AM Wednesday before the robot powers up.

Safe cracking robot front

Safe cracking robot top

Let me be clear, the robot theoretically works, but we have not yet opened the safe. We’re pretty sure there’s nothing in the safe. We’ve moved it a few times. Nothing rattles around, but who knows? Maybe there’s a bar of gold inside! Or a ham sandwich. We don’t know, but we’re going to find out.

comments | comment feed

Friday Product Post: All’s Well That Means Well

via SparkFun Electronics Blog Posts

Hello, and welcome to another Friday Product Post! Today we have a big treat for you, in the form of new, reliable power supplies from Mean Well! That’s right, four new units with custom-made power cables (sold separately) all available now. These aren’t your regular supplies, either; each provides a great deal of wattage at a great price. Let’s see what Feldi has to say about them!

If all’s well that ends well, then the ends should justify the means.

Mean Well Switching Power Supply - 100W


This is a 100W single output switching power supply from Mean Well. This power supply is extremely reliable and able to output 5VDC at 20A. We’ve been testing this power supply for quite some time and can definitely attest to its durability with its metal casing, short circuit, overload and overvoltage protections.

Inside the metal case that surrounds the power supply you will find a selector switch to change the voltage range between 85VAC to 132VAC and 176VAC to 264VAC, or 248VDC to 373VDC.

But that’s not all…

Mean Well Switching Power Supply - 150W


We also have a 150W version able to output 12VDC at 12.5A…

Mean Well Switching Power Supply - 350W


The large 350W version with 24VDC at 14.6A output…

Mean Well Dual Output Switching Power Supply - 24W


And, for the adventurous, a dual output 24W supply board as well!

However, you are going to need some way to hook these all up to power. Don’t worry; we have you covered!

Adam Tech Wall Adapter Cable (NA)


These Adam Tech Wall Adapter Cables are terminated with a standard North American (NEMA 5–15P) plug at one end and three insulated spade terminal connectors at the other. Each cable is 1m long and provides a safe and appropriate way to hook up our Mean Well power supplies!

Adam Tech Wall Adapter Cable (EU)


We also have a European version available!

Alright, folks, that’s it for today. We know you can get a lot of power out of this Friday’s products. We’ll catch you back here with even more new products next Friday. See you then!

comments | comment feed

Enginursday: Battery Management

via SparkFun Electronics Blog Posts

In this modern age of cellphones, we’ve all come to expect a certain degree of elegance from our portable electronics' battery systems. But in DIY electronics it’s common to find jumpers or switches that brutally disconnect the battery from its host. Or, no disconnect at all and puffy, discharged LiPos lying about haphazardly on the workbench. In my FLiR Pi Cam build, for instance, though voltage monitoring was built in, I left it to the user to isolate the batteries via a DPDT switch recessed in the body — not very elegant at all!

This post explores how to use the power control features of the Battery Babysitter to make a product with the features we expect from portable embedded electronics.

The Host Project

alt text

This is an incident light meter I built inspired from another DIY project I found at I built it partly because I wanted to try some menu stuff out on the screen, and partly because I could use it to help light scenes for photography.

Incident light meters need to be thrown in a camera bag and used on and off during a shoot, often from odd angles. It just wouldn’t make sense to have a wire that needed to be plugged in, so this is a great platform to try out the Battery Babysitter in order to make a product that performs as people expect.

The “actual” functions of the device are really just obtained by connecting the TSL2561 sensor to the I2C bus and whacking on a TeensyView, followed by coding, coding and more coding. And maybe a little math mixed in there. At the end I’ll leave you with a schematic and repository, but this isn’t about how light is measured; it’s about batteries and usability. So let’s get to it!

Design Goals

It’s a good idea to specify what you want in the beginning when designing something. Here’s what I came up with for adding battery support to my project.

  • Low off-power requirements/no mechanical isolator. This thing should take months to discharge while off.
  • Screen icons for battery:
    • Must display quantity of “% use remaining”
    • May display battery charging state.
  • Minimize number of buttons.
  • Sleep after some length of time (self power-down function).

Fulfilling Those Goals

alt text

Before stuffing the project in the box, the entire project was developed on a breadboard. This allows the circuits in question to be tested and the construction to be well thought-out, avoiding sudden last-minute changes to the design after mechanical production has begun.

If we can describe how each goal is met, and how we can test each goal in the prototype, we can have confidence that the circuit will work as expected. So let’s do that now.

Low Off Power

  • The Battery Babysitter must be able to go into SYSOFF mode. We’ll test this by measuring the off current through the battery terminal.

Pouring through the Battery Babysitter’s schematic, power flow goes first through the fuel gauge IC, through the charger IC, then to the user. Looking for off currents in the respective datasheets,

alt text

The charger is a bit cryptic in off current. The SYSOFF pin is pulled up with a 5 meg resistor, so the control load connected internally must be quite low, below 1uA. This is good, but the charger is downstream of the fuel gauge, so this pin alone can’t turn everything off.

alt text

The fuel gauge specifies a few operational modes. For lowest operation, the device should be commanded to shut down by I2C.

Ideally, I expect less than 5uA of drain during off time, which would take years to drain a 1000mAh battery. In reality, I found that the process of shutting down the fuel gauge was quite involved, and it’s intended to operate automatically. Conceding that design point, the measured battery off current came to about 60uA. At 1000mAh, that’s almost two years of off time before the battery goes dead. I’ll expect to charge this every couple months.

Screen Icons

  • The screen must display a little battery in the corner and a symbol to show whether it’s charging or not.

alt text

A bitmap image is used to mock up what the icons will look like

To make the graphics of the battery (and the screen in general), I used a bitmap editor extensively. Ok, you got me; I used mspaint with the zoom all the way in and the grid enabled. Then, I converted the pixels into HEX, knowing that the MSb is on top. For instance, the plug starts with 0x28, 0x28, 0x7C… The graphics are encoded into functions like drawPlug and batteryStyle1(x, y, %) so they can be easily used.

To detect charge state, it’s easy to look for a positive current flow into the battery. If the condition is met, the plug is drawn. To prevent constant drawing on the screen, though, I check the current and percent remaining by the Babysitter’s SOC (state of charge) function and only update if there is a new value to display.

Minimize Number of Buttons

  • Reuse a function button for both the power supply enabler and the intended function. To test, the button must not interfere with the operation of the power supply while operating, and the digital input pin must still be able to detect changes in voltage while the power system is enabled.

The idea of the SYSOFF pin is that it floats high (through a 5meg resistor) and needs to be pulled low in order to get the Babysitter to come online. By connecting two sink paths to the pin, essentially a NOR gate is created.

alt text

Either the user can push the button to pull SYSOFF low, and turn the system on, or the GIPO output can pull the line low to turn the system on.

The theory of operation is that when users want to use the system, they hold the power button until the processor boots. The first thing the processor does is configure its power control pin and pull it low. Now the user can let go of the button, and the system remains on. When the system wants to shut itself down, it can release the power control line. The SYSOFF line goes low, and everyone goes to sleep.

The diode is included to allow the button to function normally on its input pin while the SYSOFF line is being held low by the processor.

Sleep After Some Length of Time

  • The system must be able to turn itself off from firmware.

This can be done by bailing from the menu state machine if an mstick count has expired. Not yet implemented. For now, power off occurs when the soft key is hit in the system menu.

The Firmware

To make the system ‘catch’ as soon as possible, the power pin is configured and asserted as the first thing within begin().

void setup()
    //Assert power on pin
    pinMode(PIN_POWER_ON, OUTPUT);
    digitalWrite(PIN_POWER_ON, HIGH);


Then, when I want to turn the whole thing off, I simply drive the pin low in response to a button operation. There’s a bit more here to show the user what the system is doing, and to provide an out if the system fails to shut down.

if( encButton.serviceRisingEdge() )
        oled.setCursor(6, 6);
        oled.print("Power down.");
        digitalWrite(PIN_POWER_ON, LOW);
        oled.setCursor(6, 6);
        nextState = pSystemInit;

As an example of graphics drawing, here’s what the battery widget function does. First, it writes pixels to the screen memory with a bytewise draw command, and then it fills in the battery area based on the input percent.

void OLEDFunctions::batteryStyle1( uint8_t xIn, uint8_t yIn, float percent )
    drawByte(xIn + 0,yIn + 0,0xFE);
    drawByte(xIn + 1,yIn + 0,0x82);
    drawByte(xIn + 2,yIn + 0,0x82);
    drawByte(xIn + 3,yIn + 0,0x82);
    drawByte(xIn + 4,yIn + 0,0x82);
    drawByte(xIn + 5,yIn + 0,0x82);
    drawByte(xIn + 6,yIn + 0,0x82);
    drawByte(xIn + 7,yIn + 0,0x82);
    drawByte(xIn + 8,yIn + 0,0x82);
    drawByte(xIn + 9,yIn + 0,0xEE);
    drawByte(xIn + 10,yIn + 0,0x38);

    line(xIn + 2, yIn + 2, xIn + 2 + (percent * 6), yIn + 2);
    line(xIn + 2, yIn + 3, xIn + 2 + (percent * 6), yIn + 3);
    line(xIn + 2, yIn + 4, xIn + 2 + (percent * 6), yIn + 4);


All graphic functions in this project exist in a class that inherits the TeensyView object from the library. This separates the complicated drawing commands from the complicated state machine. The decoupling of these two things really helps to allow the firmware to be expanded — for example, when a new menu screen needs to be created.

Project Files

Take a look at this schematic to see how everything is wired together. If you’re interested in actually making this project, or just seeing how it works, the code, schematic and 3D printer models can be found in a GitHub repository.

alt text

You can see that the Babysitter’s output voltage drives the Teensy’s bulk input (Vusb), which is regulated down to 3.3V for the Teensy and attached systems. Also, the USB communication lines have been extended to the convenient exposed PTH pads of the Babysitter, so the Teensy can be reprogrammed with the case closed.

alt text

The mechanical build is designed so the battery slides between a couple of snappable proto boards, and the whole assembly slides into the enclosure. No case screws!

Parts used in this build:

And again, the repository can be found here:


Please share your thoughts and ideas in the comments below.

Happy making!


comments | comment feed

The micro:bit is now on pre-sale

via SparkFun Electronics Blog Posts

We have a special announcement for you today! The micro:bit, an easy-to-use, beginner-friendly, reprogrammable microcontroller, is now available for pre-sale.



Created as a collaboration between BBC and 29 partners, the micro:bit was designed to develop a new generation of tech pioneers. Previously only available outside the US, the micro:bit gained popularity after the BBC gave the board to every sixth grader in the UK last year.

The micro:bit has a number of exciting features, including a 25 LED array, Bluetooth and USB connectivity, an embedded compass and accelerometer, and mobile and web-based programming capabilities. It’s a great introduction to electronics and coding, and we hope to start shipping them in May!

comments | comment feed