PWM a 3-pin PC fan with an Arduino

Note: 4-pin fans already have a PWM signal

Aeroscope Measuring a Fan

A question came up on IRC regarding how to PWM a 3-pin PC fan with an Arduino using analogWrite(). Controlling the fan was seemingly straightforward. The problem was that the hall effect sensor, or TACH signal, was incredibly noisy. The noise made it impossible to measure the fan’s rotation. Working through the question, I found three issues to tackle:

  1. You need to use a PNP transistor
  2. Filter capacitors help
  3. Create a non-blocking RPM measurement (with millis())

This post addresses all three issues regarding how to PWM a 3-pin PC fan with an Arduino.

Continue Reading »

During #22 of the Hardware Developers Didactic Galactic meetup, I discussed Oscilloscopes. (Previously James talked about capacitors.) In the presentation, I broke down the internals of an oscilloscope. The presentation started off with a block diagram. Then I discussed the main components: vertical amplifier, A/D, memory controller, some of the computer side stuff, and the keynote was on triggering.

The trigger circuit of an oscilloscope fascinated me since very early in my HP/Agilent career. When I saw trigger modes like Pulse, Violation, Rise Time, and “Runt,” I thought: Wow, this must be the most complicated circuit in the scope! While it isn’t trivial, it very clever how just a few pieces of (relatively) simple hardware drive one of the most important aspects of a digital scope.

Download Slides

Rick Altherr also gave an excellent talk on ECUs and their sensors. (I always thought ECU only meant engine control unit. His talk helped me understand why that isn’t really the case anymore!) It was great to learn about the combination of the engine mechanics with the electronics that control it. !)

See Rick’s Slides

Raspberry Pi Startup Script Tutorial

Part 3: Pi Soft Power Controller, what to put on the Pi

raspberry pi startup script

The last couple of weeks I have been making progress and posts on my RetroPie build. I’m putting a Raspberry Pi inside of an actual SNES (well Super Famicom). Part 1 covered the schematic for a Soft Power Controller. In Part 2 I broke down the RPSPC state machine. This 3rd and final post of the series is a Raspberry Pi startup script tutorial. It covers how to make scripts run at startup and shutdown.

When I started researching how to make Raspbian run a script at startup and shutdown, I found a ton of links and questions asking for help. None of them helpful. Why? Because they were wrong. At least, they are now.

/etc/rc.d doesn’t matter!

It turns out, Raspbian Jessie does not use SysV for init (anymore). So it does not matter what you scripts you put in /etc/rc.d. Pretty simple but missed by many!

Here is a correct Raspberry Pi Startup Script Tutorial.

The Key is systemd

Once I started researching how to make systemd do what I wanted, new problems emerged. The syntax for systemd is not as straightforward as I first thought. Thanks to readers, I was pointed towards the RedHat systemd manual. After reviewing it, I was able to create a service that runs at startup and shutdown.

In the end, I was unable to prevent this process from running during reboot. There seem to be some more layers to make sure systemd knows the difference. In the end, I decided it was not necessary to avoid the reboot.

Continue Reading »

Soft Power Controller State Machine

Here's the logic behind the Pi Soft Power Controller

RPSPC State Machine

Previously I looked at the hardware needed to build a Raspberry Pi soft power supply. This week I’m looking the state machine for the microcontroller. Why is such a complicated circuit necessary? I am replacing a Super Famicom (SNES) motherboard with the Pi. The trick is, I want to use the original power switch to turn the Pi on and off.

This requirement presents a problem. When the switch goes into the “OFF” position, power needs to stay on long enough for the Pi to properly shutdown. So the switch itself can’t provide power to the Pi directly. With minor changes, the code in this state machine could be made to work with push buttons as well. If I add that feature in the future, I’ll update the code on the RPSPC GitHub project.

Before continuing with the state machine, first I need to thank all the mailing list members. You guys really rock. When I asked for state machine diagraming tool suggestions, you guys sent me enough options for an entire (future) post to compare them. 

Continue Reading »

Raspberry Pi Soft Power Controller – The Circuit

Part 1 Control Rasp Pi power with an Arduino-based controller

The RetroPie project enables retro-gaming with a Raspberry Pi. All of the Pi models have enough computing power to emulate the major 8-bit and 16-bit computers of the 80s and 90s. With the Pi 3 I have even been able to play PS1 games with no problem. My current project is to put my Raspberry Pi running RetroPie into an old Super Famicom (SFC), or SNES, case. The catch? I want the original SPST power switch to work. And by work, I mean allow the Raspberry Pi to shutdown properly when the switch goes into the off position.  To accomplish this task, I am building a Raspberry Pi soft power controller.

Raspberry Pi Soft Power Block Diagram

Here’s a block diagram of the power controller. The basic blocks in a Raspberry Pi soft power controller include the LDO, a switching supply for the Pi, an AVR-based microcontroller, and the Raspberry Pi. This post will describe each of these hardware blocks.

One design objective was to draw as little current as possible when off. For my RetroPie, I will not be running on battery. However, I do not like the idea of wasting energy when something is turned “OFF.”

This overview is a multi-post write-up. This first part is on the hardware. In the next post, I will explain the AVR’s firmware. Later, I will come back to the Raspberry Pi side of the project.

Last week’s post was on Project Sharing Sites. I’m using two for this project. will host the build log while GitHub has all of the design files. And by all of the file I mean the schematics, firmware, laser cutter files (soon), and Raspberry Pi code. Project Page  GitHub Repo

Continue Reading »

If you have any interest in retro computing or technology, The 8-Bit Guy is one of the best YouTube Channels. His latest video hits a little closer to home. He shows how to Character LCDs work and how to hook them up. He always does a great job with his videos, so I encourage you to check out some of his others.

He’s has some other good videos such as the one on how 8-bit video game graphics worked and, one of my favorites, how disk drives worked.

Share projects on one of these 4 platforms

Contribute back to the open source hardware community

share projects

Sharing is the maker community’s foundation. When you share projects with others, you contribute to the community. In the past, you might just post your project on a personal website. Today there are many options to share projects.

This weekend I “finished” my reflow oven controller, Open Vapors. Believe it or not, five years ago there were not a bajillion similar projects. In fact, I based my design on the only completely open source project I found. It is a reflow oven controller Arduino shield from Rocket Scream.

After completing my controller, I was excited to share the project. Then I started to think about where to post the files. Obviously, here at is one option. But I wondered. Is there a better place where others could benefit from my work?

This post is a few notes on the platforms used to share projects. At first, these might seem like they all serve the same purpose. From a high level that is true. However, there are small differences that you should consider when you share projects with the open source hardware community.

Continue Reading »

Detect short and long button press using millis

Different actions based on how long the user presses a button

detect short long button press using millis

To detect a short and long button press using millis can give your project more functionality without adding more buttons. In this line-by-line example, I show how to react to a user pressing a button for a short period (100ms) or a long period (over 500ms). My example changes the blink rate of an LED on short presses. A long button press turns off the LED.

In the code, I make use of a struct so that a single variable can be used to track multiple parameters. The benefit of this method is that adding multiple buttons is easy. You could create an array of these tyepdef’d variables.

Download At GitHub

Continue Reading »

Best Sorting Resistors Method 

At least, according to me.

sorting resistors method

When you buy a grab bag of components, you might need to tackle sorting resistors. Here’s how I sorted some bags of random resistor assortments last week.


Then method I use for sorting resistors achieves these objectives:

  1. Fewer Bins. It doesn’t take long to create a large matrix of resistor values. My resistor sorting method is relatively compact.
  2. Quick to find. When I’m building up a circuit, I don’t want to spend time sorting through a pile. Once I know the value I need, I find a single package and then look for a single color band.
  3. Works with 4-band and 5-band resistors. Let me be upfront: I *hate* 5-band resistor color codes. While the 5th ring is supposed to be slightly offset, or wider, or a different type of color; it doesn’t matter. It’s nearly impossible to tell read a 5-band resistor color code when they are in a pile. However, using my method for sorting resistors, it doesn’t matter if I’m looking at a 4-band or 5-band resistor. I can immediately identify the resistor value.

Based on #3 alone, you might be wondering what is the fantastic method (and how much will it cost to get it!) Here’s the basics of my method for sorting resistors. (For FREE!)

Continue Reading »

Arduino Data Logger: Serial Monitor Alternatives

Forget the serial monitor, here's 5 other ways to do Arduino data logging

arduino data logger options

The Arduino serial monitor is usable when you want to watch data from an Arduino. However, it does not have a built-in method for saving the data. Here are some ideas if you want to build an Arduino data logger with or without a PC.

Important note on Arduino Data Logger examples

With all of these examples, please remember that whenever you open the Arduino’s serial port, the board will reset. So if your log file shows “Initializing SD card…” with a few data lines in between, it is because there is a reset happening.

Initializing SD card…initialized.
Temp: 34, Time: 03:24:44
Temp: 33, Time: 03:24:45
Temp: 34, Time: 03:24:46

Initializing SD card…initialized.
Temp: 34, Time: 03:24:50
Temp: 34, Time: 03:24:51
Temp: 33, Time: 03:24:52
Temp: 34, Time: 03:24:53

In that code you can see data logging started and then restarted. What happened is that after programming, the board starts logging. Then when you open the Serial Monitor, the data logger restarts.

To solve this issue, either disable auto-reset, add a 3-4 second delay at the start of setup(), wait for a character to be received, or wait for a button press. That will give you time to open the Serial Monitor.

Continue Reading »