Saturday, December 21, 2013

How to use the 74HC595 Shift Register

I bought a bunch of 74HC595's a while ago and didn't really know what they were. They were super cheap though. I'm on Christmas break now so I finally have time to actually do stuff. The 74HC595 chip basically lets you use three pins on your arduino, and extends those into 8 more output pins. It's known as a shift register or serial to parallel converter. So the mini project I'm doing for this post is blinking Christmas colored leds. It's easy, but explains very well how the shift register works.

To start off, the way you control the output's on the 595 is by sending it a byte. A byte has 8 bits, and each bit corresponds to a pin on the 595. For example, if you send the byte 10101010, every other output would be HIGH, and the zeros would be LOW. In the Arduino IDE, there's a reserved word called MSBFIRST, or LSBFIRST, which stands for most significant bit first, or least significant bit first. Meaning that if you send 00001111 with MSBFIRST, the first four outputs will be LOW because it would read from right to left. But if you send it with LSBFIRST, the first four will be HIGH, because it reads if from left to right. Now on to the wiring.

Here's a small list of things we're going to need:
Three IO pins on the Arduino
Power and Ground from the Arduino
8 leds
8 220 ohm resistors (Red, Red, Brown)
74HC595 IC

On the 595 chip, we're going to use pins 11, 12, and 14. Which are the Clock pin, Latch pin, and data input pin respectively. I'll explain what those pins do later.

On your breadboard, connect the anode(+) of the led to the resistor, and cathode(-) to the common ground rail. Then the outputs for the 595 chip are on pins 1-7, and pin 15. Connect wires from those pins to each resistor. Pin 1 starts when the cutout is in the IC. It reads in a continuous loop, so pin 8 is on the very bottom left, then pin 9 starts directly across from it on the bottom. and continues up.

On my Arduino, I'm using pins 4, 5, 6 to connect to the three control pins on the shift register.

Here it is made in Fritzing, which is really fun to use by the way!

Now that it's all wired up we can write the code.

We have three pins being used on the Arduino. Pins 4, 5, 6. Arduino pin 4 is going to pin 11 on the shift register. Arduino pin 5 goes to pin 13 on the shift register. Arduino pin 6 goes to pin 14 on the shift register. Wire everything up exactly as you see it in the breadboard view above.

You can find some examples I made for the shift register on my github.

Understand how the function shiftOut works is key to using this shift register. The syntax for it is as follows: shiftOut(dataPin, clockPin, MSBFIRST, B11111111); based on that, the two control pins are the dataPin and clockPin. We want the register to read the Most Significant Bit First, and then we give it the byte pattern. Whenever you want to change the outputs, you need to set the latchPin LOW, make your changes, then set the latchPin HIGH again for the outputs to go into effect.

For example here's a function I made that set's all the outputs LOW:

void flashAllLow() {
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
  digitalWrite(latchPin, HIGH);

Notice how latchPin goes LOW, then we make the changes we want, then set it HIGH again.

If you want to make an LED chaser you can use the << operand. What that does is shift the bits to the left a certain amount of times. Example: B00000001<<2 would become B00000100, the 1 got shifted to the left twice. To make an LED chaser we would want to continuously move that bit over in a for loop. An example of doing that is here:
  for (int k= 0; k < 8; k++) {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, B00000001<<k);
    digitalWrite(latchPin, HIGH);
Again, all of this code can be found on my github page.

The way I figured out how to use these shift registers was by reading a crap load of tutorials online, and just kept trying new things with them.
Here's some really good links that helped me understand how these are all working.

Explains the << operand
"Can you move over?"
Shift-Registers + Arduino, by Kevin Darrah
shiftOut tutorial

Here's a few pictures of my build.

 a .gif of the leds flashing in random patters
 Breadboard picture of my wiring

and another picture

Feel free to ask questions! Typically I made these posts at 4AM so my way of thinking is probably heavily distorted...

Tuesday, December 3, 2013

[Work in Progress] High Altitude Balloon

The project I'm currently working on is a High Altitude Balloon. I got interested in this after seeing video footage on YouTube of people showing the Earth from 100,000 feet or higher. I'm still in the early brainstorming process of this, but I'm really excited to get this whole thing started.

I want to over complicate my HAB because I feel like everyone else has done the same thing, so obviously I want mine to be different, and more challenges makes could make the whole project more fun!

For me to consider my project a 100% success, it must meet these requirements:

  • Arduino based
  • Must transmit GPS coordinates at all times, even once the payload has landed
  • Live first person video
  • Transmit GPS using APRS
  • The parachute cannot be inline with the balloon and payload, it has to eject from within the payload
  • Waterproof and shockproof
I've already bought a GPS module ( but after reading online, I realized it will only work up to 18,000 meters which is about 60,000 feet. That GPS module uses the SIRF chipset, which is very common so when picking out a GPS module for a HAB, make sure it's not that. It's still a fun GPS module though and maybe I'll make another little project out of it or something. The data sheet for the PMB-688 can be found at

In order to transmit the GPS coordinates via APRS you need to transmit it on 144.390MHz in order for local digipeters to pick it up on the APRS network. The transmitter I will likely use is the HX1 radio module (, which has plenty of support with the Arduino online. What's great with using APRS is that you can track the balloon in real time online at, and you can search by call sign, and HAB's usually have a -11 at the end of the call sign.

A problem I read with other HAB's is that once they land on the ground, it get's really hard for them to be found, because if it lands in the woods or a hilly terrain it could be hard for the GPS signal to get out to the digipeters. A way for me to make my chances easier to overcome this problem is to somehow detect the orientation of the payload on the ground, reorient if I need too, then extend an antenna as high as possible to make better contact. A mini mars rover would be cool too...

I'm still not sure how I'm going to make the parachute pop out of the payload, but to disconnect the cord that connect the payload to the balloon, I think I'm going to have the cable somehow attached to a resistor and use a relay to short a battery over it to cause it to overheat and break causing the cable to become disconnected.

As for FPV, I found out with a GoPro you can record video and output video at the same time to a video transmitter. Which is perfect for what I need. I found a helpful video explaining what to do here:

That's really all I've thought of so far, hopefully I can get something built during Christmas break, but mostly I'm excited for the video footage!

Here's a whole bunch of links I've bookmarked that I find really helpful:
And ignore any spelling or grammar mistakes... it's like 4:30 in the morning.