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
breadboard
8 leds
8 220 ohm resistors (Red, Red, Brown)
74HC595 IC
Wires

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);
    delay(200);
  }
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 (http://www.parallax.com/product/28501) 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 http://www.parallax.com/sites/default/files/downloads/28501-PMB-688-v0.1.pdf.

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 (http://ava.upuaut.net/store/index.php?route=product/product&path=71_63&product_id=78), 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 aprs.fi, 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: http://www.youtube.com/watch?v=UKMQhWZtNRg.

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.

Thursday, October 24, 2013

Halloween Prank

https://github.com/jacobantoun/Halloween-Fun

Here's a little Halloween prank you can play on someone! What this is it's a little container of some sort and when a door opens, a spider will drop down and scare whoever walks through the door!

How it works is by using a Sonic distance sensor to detect when the door is opened, and when the door gets opened it uses a servo to slide open the lid to have the spider drop out!

So far I only have the prototype completed, using a toilet paper roll as the container and a cut up post card for the lid. It's really pretty easy and I can't wait to try it out on some unsuspecting people!

So what you need is:
Arduino
Servo
Sonic Sensor (I'm using the HC-SR04)
Hot glue gun or any type of glue
Wires
Container
Lid

I created a Fritzing image for the first time ever to show you how it's all connected.
The code for the project can be found on my github, along with all of my other projects I've made so far.

Now here's my prototype of this project! (I don't have a fake spider and I haven't mounted this anywhere fancy yet, except underneath my desk.)
video









Wednesday, October 23, 2013

How to use the Parallax QTI line sensor with Arduino

The code for the line sensors can be found at https://github.com/jacobantoun


I spent a lot of time reading up on line sensors and ended up having a lot of trouble finding code for 'line sensors'. I found out that sensors that I have are called QTI Sensors, which stands for Charge Transfer Infrared. I won't go into too much detail about that because I don't really understand what it all means. I got a lot of help using these line sensors from http://learn.parallax.com/KickStart/555-27401, which explains what the whole QTI thing is a lot better than what I probably could.

After reading more online I found out that you can read from these sensors in two different ways. analogRead or using an RCTime function that is duplicated from the Basic Stamp. It can be used to read the resistive sensors, line the QTI sensor. It reads the charge across the capacitor.

NOTICE: The wiring for these are a bit odd. It's not standard with it being Ground Power Signal (Black, Red, White) on the three wires. It's Ground Signal Power.


On github, I posted two files. One file using the sensor as an analog input, and another file using the RCTime function. I haven't noticed a huge difference in performance when comparing the two outputs, except the code for the analog input is shorter and I personally think it's a bit easier to understand.

But anyways, the parts needed for this are:
Arduino
BreadBoard
Wires
QTI Sensor/Line Sensor (Data Sheet for linesensorand this is the actual product)

If you go to my github you can download all the code you need to use these. Look under the QTISensor repository.
https://github.com/jacobantoun

Here's some pictures of just the wiring and whatever else.
 The 'face' of the line sensor

 the back of the line sensor

 How it's wired. The yellow wire is going to pin 5, and the purple wire is used as an LED indicator.


Sunday, October 20, 2013

How To Use The LM335Z Temperature Sensor With An Arduino

Parts needed:
LM335Z temperature sensor
1K ohm resistor (brown, black, red)
Breadboard
Some wire

I had a little trouble finding code for this temperature sensor online, but ended up getting enough pieces together to finally get it working.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//Sketch created by Jacob Antoun
//10/20/13
//
//Wiring Info:
//Nothing is connected on the collector
//Analog Pin 3 is connected to the Base
//1K ohm resistor is connected to the Base, after the AnalogPin
//Ground is connected to the Emitter
//

#define tempSensor A0 //Puts the LM355Z temperature sensor on anolog pin 0

const float miniVoltsToKelvin = 0.004882812 * 100; //found this online, I don't remember the source :(

void setup() {
  Serial.begin(9600); //initialize the serial monitor
}

void loop() {
  float kelvin;
  float fahr;
  kelvin = analogRead(tempSensor) * miniVoltsToKelvin; //converts the reading from the arduino into kelvin
  fahr = 1.8 * (kelvin - 273) + 32; //converts the kelvin to fahrenheit
  Serial.print(fahr); //prints to the serial monitor
  Serial.print(" degrees");
  Serial.println();
  delay(1000);
}

If you want a copy of the code, and to see other projects I'm working on, look at my GitHub.
https://github.com/jacobantoun/LM335Z

Below are just two images that show the wiring of the temp sensor


Just showing the wiring of it on a breadboard

Notice how nothing is connected to the collector, and look at the placement of the analog pin and resistor.