Author Archives: SparkFun Electronics

Adventures in Science: Rotary Encoders

via SparkFun Electronics Blog Posts

There are two types of rotary encoders: incremental and absolute. Incremental encoders are useful for determining how many times a shaft has rotated or even counting fractions of a rotation. Absolute encoders, on the other hand, can determine the exact position of a shaft (depending on the resolution and precision of the encoder disc). For the video, I focus mainly on incremental encoders, how they can be used in wheeled robots to measure distance traveled, and how quadrature encoders work to determine the direction a shaft is spinning.

Incremental encoders, in their basic form, detect light, magnetic or physical changes on a disc that rotates with the shaft. We show an optical encoder in the video as a demo (the build for which can be found on Hackster). We then add two photocells to the encoder demo to show how a quadrature encoder works. We can use a simple magnetic encoder to count the number of rotations on a shaft, which we can use to determine how far a robot has traveled by placing one on each motor. Code for making our robot (lovingly named “Fred”) move in a straight line for one meter can be found here.

Many of the top competitors in AVC use a combination of rotary encoders and a magnetometer (compass) to create a dead reckoning system that allows their robot to navigate around the course. Additionally, many self-balancing robots rely on encoders along with an inertial measurement unit (IMU) to determine if the robot is leaning one way or the other.

What are some other useful, fun or unusual uses for rotary encoders that you’ve seen?

comments | comment feed

friday product post: micro:bit!

via SparkFun Electronics Blog Posts

Hello and welcome, one and all! We are very happy you joined us today for our official announcement of our micro:bit product launch! We actually released all of these products for pre-order about a month ago, but we wanted to make a big deal about them today since we are so excited to be carrying them! On top of the stand-alone micro:bit Board and the simple-to-set-up Go Bundle, we are also happy to introduce three new adapter boards for the micro:bit, as well as five new kits. Alright, let’s jump in and see what we have today!

Now imagine this same video coming from the Micro Machines Man.

micro:bit Board

micro:bit Go Bundle


To get started, you are going to need one of these fine products. On the left is the stand-alone micro:bit Board, and on the right is the micro:bit Go Bundle, which includes all of the basic cables and power requirements you need to get hooked up. Both have been available for sale for some time, and we have covered them in great length already, thanks to Shawn’s Getting Started videos. We wanted to make sure to show these items off one more time because most of the following boards and kits do not include a micro:bit itself.

At the flip of the switch you can get your micro:bit moving!

SparkFun moto:bit

SparkFun micro:bot kit


Robots are fun, and the micro:bit is the perfect controller for learning how to build and program robots! Combining the micro:bit with the SparkFun moto:bit carrier board creates a flexible, low-cost robotics platform for robot enthusiasts young and old! With the SparkFun micro:bot kit you will be able to create simple robots quickly without spending hours learning how to build and program your latest creation. Available as both a kit and a stand-alone board, neither requires any soldering or in-depth programming experience.

Know what’s happening outside BEFORE you venture out.

SparkFun weather:bit

SparkFun micro:climate kit


When combined with the micro:bit, the SparkFun weather:bit provides you with a fully functional weather station. With this bit you will have access to barometric pressure, relative humidity and temperature readings

The SparkFun micro:climate Kit is a full weather station kit that is built on top of the weather:bit carrier board. Unlike previous weather kits we’ve carried, the micro:climate kit includes our tried-and-true Weather Meters and Soil Moisture Sensor, so whether you’re an agriculturalist, a professional meteorologist or a hobbyist, you will be able to build a high-grade weather station powered by the micro:bit. You can even talk via wireless communication between two micro:bits with this kit to be able to monitor the weather without being exposed to it!

w3 l0v3 m1cr0:b17!

SparkFun gamer:bit

SparkFun micro:arcade kit


We love games! We love writing games, building games and, yes, even building game consoles. That’s where the SparkFun gamer:bit and micro:arcade kit for the micro:bit comes in! The gamer:bit carrier Board (which is included in the kit), gives you access to a number of pins in the form of buttons laid out in a similar form factor to the classic Nintendo NES controller. With the micro:arcade kit you will be able to turn a classic controller into an arcade cabinet by connecting just a few buttons and switches. You can even easily control a moto:bit board with a micro:bit attached with the gamer:bit, providing you with an easy-to-set-up robotics platform.

The micro:bit even has its very own SIK!

SparkFun Inventor's Kit for micro:bit


The SparkFun Inventor’s Kit (SIK) for micro:bit is a great way to get creative, connected and coding with the micro:bit. The SIK for micro:bit provides not only the micro:bit board but everything you need to hook up and experiment with 12 electronic circuits! With the SIK for micro:bit you will be able to complete circuits that will teach you how to read sensors, move motors, build Bluetooth devices and more.

micro:bit Educator Lab Pack


Don’t worry, educator friends, we have you covered as well! The micro:bit Educator Lab Pack includes 10 micro:bit boards and everything you need to get you started with the new learning platform. The Lab Pack has everything you need, including micro:bits, cables, battery packs and a few parts to experiment with. This package provides an easy way to introduce your students to the micro:bit without any difficulty or parts hunting.

SparkFun micro:bit Breakout

SparkFun micro:bit Breakout (with Headers)


The SparkFun micro:bit Breakout (available with headers as well as without headers) is a board that connects to the micro:bit and expands the capabilities of the development platform by providing access to more pins and allowing for connections to the I2C and SPI buses. This breakout board for the micro:bit’s edge connector allows intermediate and advanced users to connect the micro:bit to breadboards and other sensors, motors, LEDs and more!

MI:pro Case for micro:bit


You will want to keep your micro:bit safe, and that’s where the MI:pro, a simple and compact protective case, comes in! These cases feature a three-layer construction style with ability to wall-mount the whole assembly onto any surface you want while still providing access to all buttons and ports on the micro:bit. Though these cases do feature wall-mountable tabs, the biggest benefit of using a case is to not accidentally short out the pads on the back of the micro:bit.

micro:bit Battery Holder - 2xAA (JST-PH)


Finally, if you possess just the micro:bit Board and don’t have any way to power it, make sure to pick up this battery holder. This specific power supply is equipped with a JST-PH connector, which the micro:bit requires. A typical JST connector won’t work, so make sure you have the correct one!

Whew… that was a lot to get through, but we made it! There are a lot of things to do with the micro:bit, and we hope with some of these new products you will be able to use the new board to its fullest potential! As always, we can’t wait to see what you make with these parts! Shoot us a tweet @sparkfun, or let us know on Instagram or Facebook. We’d love to see what projects you’ve made!

Thanks for stopping by. We’ll see you next week with even more new products!

comments | comment feed

Enginursday: A PSoC-Based Digital Load Box

via SparkFun Electronics Blog Posts

If you’ve ever had to build a power supply, you may have needed to test it to a certain current limit. Too often, the way to do this is by stacking up large wattage resistors in series and parallel until you’ve got something that approximates the load you want.

I got tired of doing this, and whipped up this little tool to help me test my power supplies with a little more aplomb.

Assembled digital load

I’m a big fan of the Cypress PSoC line of processors, which is on our FreeSoC2 Development Board, so I decided I’d use a FreeSoC2 to implement my load. The PSoC has a huge advantage over other systems in that it has a lot of onboard analog circuitry (four op-amps), true 8-bit DAC outputs (instead of PWM), a high-accuracy 16-bit differential sigma-delta ADC and a couple of channels of SAR ADC. With all of this onboard power, I was able to reduce the external circuitry down to a few resistors and a FET as a load element.

PCB circuitry

You can see here the 10:1 attenuator for the input voltage sense, which allows us to test power supplies up to 50V. The FET is going to be operated in the ohmic region, where it behaves like a voltage-controlled resistor rather than a constant resistance switch as we usually use it.

PSOC Circuitry

This is the internal circuitry created within the PSoC. Two DAC channels provide a coarse (16mV/count) and fine (4mV/count) adjustment for the gate drive voltage. These signals are brought out of the PSoC, run through a couple of 47k resistors, and then pushed back through an inverting amplifier with a gain of 1 to create a summing amplifier for driving the FET gate.

For user I/O, we’re using a 20x4 character LCD, along with one of our MPR121-based cap sense keypads. The FreeSoC2 has a dual-voltage domain setup that allows us to run some pins at 5V and others at 3.3V, so you don’t have to worry about level shifting the 3.3V signals for the MPR121.

Finally, the code is written in C under PSoC Creator 4.0. The PSoC on the FreeSoC2 is clocked (for this application) at 64MHz, which is fast enough to do the PID loop, floating point math and all, at 1kHz, despite the lack of an FPU on the processor.

All the code, schematics and such are uploaded to this GitHub repository. I don’t recommend trying to make the board I made just yet; I neglected to add the 47k resistors and a connector for the cap sense keyboard. I’m going to respin the board and add these things.

If you do try out a similar project, or if you have any thoughts on this, let us know in the comments below!

comments | comment feed

Air Quality Sensor Experiment

via SparkFun Electronics Blog Posts

Ever since the SparkFun Air Quality Breakout was released I’ve wanted to find a fun project for this pocket air quality sensor. Turns out that a perfect opportunity was right in front of me. I recently had a roommate move out of my place, so I decided to take readings while I “cleaned” the room. This certainly wasn’t a controlled scientific experiment by any means, but it was interesting to see the different readings during the cleaning process. Keep in mind that this sensor measures TVOCs (Total Volatile Organic Compounds), so before we begin, here is a quick definition from Indoor Environment Group of the Lawrence Berkeley National Laboratory:

Researchers, and those who investigate indoor air quality problems, sometimes measure and report “total volatile organic compound” or “TVOC” concentrations. The term TVOC refers to the total concentration of multiple airborne VOCs present simultaneously in the air. TVOC methods do not measure all VOCs in the air, but a subset of VOCs that are expected to be present. Measuring TVOC concentrations is less expensive than measuring the concentrations of many individual VOCs. However, there are two main limitations to TVOC measurements. First, different TVOC measurement methods can yield substantially different TVOC concentrations and the differences between measurement methods will depend on the mixture of VOCs present. Secondly, the toxicity and the odor thresholds of individual VOCs within the VOC mixture may differ by orders of magnitude; therefore, the total concentration is not likely to provide a useful measure of total toxicity or total odor level. In general, TVOC measurements in buildings have not been useful in predicting health effects.

After reading about TVOC readings I knew not to make any grandiose statements about the measurements I would get and any relation they may have to health effects. This would essentially become an experiment based on curiosity and nothing else. With that being said, let’s begin.

The Empty Room

The completely empty room measured 12'x12'x8'. Before my roommate moved out I told him not to do any cleaning of any sort. I kept the windows and doors shut to try to prevent any air flow. Neither the A/C nor the furnace were on, and I placed the sensor in the middle of the room. For each different step I would let the sensor sit for 20 minutes and then take the reading.

Original Reading

After the recommended burn-in time of 48 hours and a run-in of 20 minutes (you must allow 20 minutes for the sensor to warm up and output valid data), I established a base reading of 161 TVOCs.

alt text

Step 1: Vacuum

After a double vacuum session, the TVOC level actually came up a bit to 136 TVOCs. I did film while I vacuumed and noticed that the readings fluctuated up and down. Possibly due to me moving around and creating air flow or the vacuum could have been kicking up some dust, so to speak.

alt text

Step 2: Clean the Windows

This one is interesting because I used a “naturally derived” glass cleaner and still my reading shot up to 897. According to the National Pollutant Inventory, Ethanol (which is the active solvent in the window cleaner) is considered a VOC.

alt text

Step 3: Dusting

For this step I dusted the window seals, baseboards and the top of the door trimming. I sprayed a standard dusting spray (not naturally derived) on a rag several times throughout the process but tried not to let too much of the spray out into open air. The sensor had a readout of 1156 TVOCs. The max readout on this sensor is 1187, so I feel pretty safe saying this probably wasn’t the ideal breathing situation, and I was starting to feel like I really needed some fresh air.

alt text

Step 4: Air Freshener

Not that the room wasn’t already fragrant enough from the window cleaner and dusting spray, but I wanted to see what a few waves of Air Freshener might do to the readings. I have to say I fully expected the sensor to reach its max of 1187, but the opposite actually happened. Within one minute of spraying, the reading was down to 575, and it eventually settled at around 436 TVOCs.

alt text

Step 5: Air Purification Remedies

Before I simply opened the windows, I wanted to try some different air cleansing methods to see if anything could give fairly quick results. The first thing I tried was running an air purifier for 20 minutes. The readings went from the mid-500s to 354. I’m not sure if this actually did a whole lot of good or if it was simply because some of the previous cleansing products had settled.

The next thing I tried was a diluted mixture of tea tree oil, which is said to purify the air due mainly due to its antiseptic and fungicidal properties. The beginning reading in the mid-300s went down to 297 TVOCs after another 20 minutes. Again, my guess is this was just due to settling.

Next up was trying out the magical powers of my Himalayan salt lamp. I made sure it was warmed up for a while before I brought it in so that all the negative ions could go capture all those pollutants (as some claim they can do). However, after another 20 minutes there was nothing substantial when the reading ended at 268 TVOCs.

The last experiment was to see just how fast some trusty plants could swallow up a common household VOC — CO2. I brought in eight small plants and surrounded the sensor with them for yet another 20 minutes. I didn’t expect to see much of a difference with only leaving these around for 20 minutes, and I was correct. The TVOC reading only came down to 241.

Step 6: Fresh Air Time

Now it was time to open the windows and the door and turn on a fan. Within a couple minutes, the sensor was nearly to 0. Even with some lingering scents from the products used, simply getting some fresh airflow to the room made an instant difference.

What Did We Learn?

Probably not a whole lot. I think we knew that most of the household cleansing products we use probably aren’t the best for us to breath in. It was fun to put some numbers to them, though. One thing that did surprise me was just how fast opening windows and getting some airflow in your home instantly improved the air quality (in terms of TVOCs). Open your window and get outside, people!

Have you experimented with an air sensor? Tell us about it in the comments below.

comments | comment feed

ESP8266 + Cayenne = <3

via SparkFun Electronics Blog Posts

Great news for IoT developers: the ESP8266 Thing Dev Board is now supported by Cayenne, opening up development possibilities to anyone creating IoT projects. Cayenne is free for makers and already supports the work of 260,000 users with its drag-and-drop IoT Project Builder, allowing you to quickly design, prototype and commercialize IoT projects.

SparkFun ESP8266 Thing - Dev Board


You can check out some of the first ESP8266 Thing Dev Board projects on Cayenne here, like this ultrasonic sensor and trigger motor project. If you want to get a jump on your next IoT project (and tap into some motivation), on July 20 we’re launching a Hackster contest.

Watch our video to see how easy it is to connect the Thing Dev Board to Cayenne, and begin building a connected project (and get a sneak peek about our upcoming contest).

comments | comment feed

Adventures in Science: LIDAR

via SparkFun Electronics Blog Posts

It’s been a while since the last Adventures in Science, and I wanted to take a break from the super basics of Arduino programming to discuss something slightly more advanced: LIDAR! While the principles behind LIDAR are not very complicated (shoot a laser at something and measure the time it takes for the reflected light to return), it has a variety of applications in science, robotics and law enforcement. This week, we examine the fundamentals of LIDAR and show how to make a simple sweeping distance scanner out of a servo and the LIDAR-Lite v3.

In the case of the LIDAR-Lite v3, an infrared laser is shot out of the transmitter and the time it takes for that reflection to return to the receiver is measured. We can calculate the distance by using the equation:

Calculate distance from a timed reflection

Here, d is the distance to the object (in meters), c is the speed of light (3.0 x 108 m/s) and t is the time it takes (in seconds) for the light to leave the transmitter, bounce off the object and return to the receiver. We divide by two to account for the fact that the light has to make a round trip (to the object and back).

By strapping the LIDAR unit to a servo, we can sweep it back and forth, taking distance measurements at every degree. This creates a sort of “distance map” of a 180-degree slice in front of the system, which we can store as an array. With this information, we can look for objects (smaller numbers in the array) or gaps and passageways (larger numbers in the array). When applied to robotics, we can create a simple vision system where the robot can drive toward the open areas to navigate down a hallway or between hay bales.

The big issue with the servo sweeping unit is that it takes two seconds to take one full scan, which can result in a painfully slow robot. For a faster scan, a slightly more advanced unit is required, such as the Scanse Sweep, which continually rotates and can perform a full 360° scan around 10 times per second. Fun fact: the Scanse Sweep uses a LIDAR-Lite v3 on top of a motor with a slip ring to pass data.

If you are looking for a more advanced method of object detection and avoidance in your next robotics project, LIDAR is a great solution, as it gives you good accuracy and precision over a relatively far distance (up to 40 m for the LIDAR-Lite v3).

comments | comment feed