Shift Register only works when hand is close

I am trying to learn to use the TPIC6B595N shift register http://www.adafruit.com/datasheets/tpic6b595.pdf but I am having a strange problem. The register only works every now and then and very often it works only when my hand is nearby.

I don't have to touch anything actually, just put my hand close to the register. I have tested this extensively and it doesn't always happen but about 80% of the time I just have to put my hand in a specific way and it works.

I have read of this problem before here: Controlling 24 LEDs with shift registers but it just says that when the SRCLR pin (clockPin) is low, the register would clear. It didn't give a real fix though that I can see.

Hopefully someone can give me some guidance on this.

I have attached my basic sketch and my code is here:

void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(clearPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
  Serial.begin(9600);
  Serial.println("*");
  
  // delay a little and then set 
  delay(100);
  // Always start by sentting SRCLR high
  digitalWrite( clearPin, HIGH);
}

void loop() {
  // write to the shift register with the correct bit set high:
  Serial.print("counter: ");
  Serial.println(0);
  registerWrite();
  delay( 1000 );
}

// This method sends bits to the shift register:

void registerWrite() {
  // the bits you want to send
  byte bitsToSend0 = 0;
  // write number as bits
  
  bitWrite(bitsToSend0, 0, HIGH);
  //bitWrite(bitsToSend0, 1, LOW);
  //bitWrite(bitsToSend0, 2, HIGH);

  // turn off the output so the pins don't light up
  // while you're shifting bits:
  digitalWrite(latchPin, LOW);
  
  // shift the bits out
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend0);

  // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, HIGH);
}

Where's the decoupling capacitors?

You're missing a bunch of connections.

Connect each GND pin to GND. You've only got one attached right now.

Also you don't have a pulldown on the G pin. That pin decides if the LEDs are all on or off so you don't want to leave it floating. Pulling it down with a 10K resistor to ground will make the LEDs that you've set to be on, stay on.

Also, keep in mind those breadboard power rails often have a break in the middle of them. Putting a couple jumpers across the center at the top and bottom of the board to make sure the power is getting where it needs to be is a good idea, but if your chip is powering up at all, that's probably not an issue with your breadboard.

And as majenko sugested, a 0.1uf decoupling cap between the VCC pin and GND might help. That helps remove noise in the circuit that could lead to erratic behavior.

majenko:
Where's the decoupling capacitors?

I didn't know I needed one. I am quite new to electronics and am trying to control an LED matrix. What would I use a decoupling capacitor for in this situation?

Use a 0.1ceramic capacitor on the power pins of each external chip.

Grumpy_Mike:
Use a 0.1ceramic capacitor on the power pins of each external chip.

Plus a larger electrolytic (say 100µF) on the power lines of the breadboard where the power connections arrive from the Arduino.

shiznatix:
What would I use a decoupling capacitor for in this situation?

When a chip turns on and off it creates noise on your power rails. The voltage in the parts of the circuit near the chip fluctuate. This is noise. If the noise is too great, then when a pin should read low it might read high instead, or vice versa.

The decoupling caps charge up when you place them in the circuit. Then when a dip in power starts to occur, they discharge a bit which raises the voltage back to where it should be.

Typically you put one or two small capacitors, say, 10uf and 0.1uF between an IC's VCC and GND pins as close to the IC as possible to prevent any noise from getting to it, or being generated by it.

Thanks, I will grab these extra parts today and put some stuff together, hopefully all will go well.

@scswift:
What though, is an IC?

Integrated Circuit.
A whole bunch of individual components crammed into something smaller.

Grumpy, just to clarify, 0.1 what?

Shpaget:
Integrated Circuit.
A whole bunch of individual components crammed into something smaller.

Grumpy, just to clarify, 0.1 what?

0.1µF, aka 100nF aka "104" aka "Magic Bullet"...

shiznatix:
Thanks, I will grab these extra parts today and put some stuff together, hopefully all will go well.

@scswift:
What though, is an IC?

An IC is a chip. Like your shift register. As someone else mentioned, it stands for "integrated circuit".

Btw for your decoupling capacitors, get little ceramic ones. You don't need to worry about polarity with those.

scswift:
Btw for your decoupling capacitors, get little ceramic ones. You don't need to worry about polarity with those.

In regards to this, can you give me an example? My local "electronics shop" is really terrible and the staff know less about electronics than your standard pizza delivery driver. So, when I go there, I need to know exactly what it is that I need.

A 100nF ceramic capacitor is a 100nF ceramic capacitor. If it doesn't say 100nF ceramic capacitor, or 0.1µF ceramic capacitor on the packet, then don't buy it. It may have the numbers "104" printed on the actual capacitor surface itself.

I found out that my local electronics shop works best if I go to them with their own inventory numbers and not component name, so take a look at their web site, if they have one, and see if they have their own code listed next to the part name.

shiznatix:

majenko:
Where's the decoupling capacitors?

I didn't know I needed one. I am quite new to electronics and am trying to control an LED matrix. What would I use a decoupling capacitor for in this situation?

The rule is simple, all digital logic chips should have a decoupling capacitor to ground on every supply right next to the
chip. (most chips have only one supply, here 5V). Typical symptoms of inadequate decoupling is random,
occasional misbehaviour. Unless you enjoy circuits that sometimes go wrong for no obvious reason don't
forget to decouple!

Without further information 0.1uF is a good default value that should work in most
circumstances, but the datasheet for the chip will have chapter-and-verse on decoupling requirements.
Buy decoupling capacitors in bulk, its much more economic!

How I buy decoupling capacitors:

I wasn't able to go to the shop myself today and my girlfriend may have gotten the wrong part. I have put all ground pings to ground and put a resistor between G pin and ground. These things seam to have really helped out but it hasn't totally fixed the problem. It still only works when a hand is near, but it is quite consistent and doesn't require much precision, just a human body nearby.

The capacitors I was able to get are 50V 0.1uF and 25V 10uF. I am not sure what the voltage here means, if it is a limit or what it should be run at.

Not sure if it matters, but I daisy chained another shift register on another breadboard and it seams like the closer the breadboards are to eachother, the more pronounced this problem is.

I have tried both capacitors across both shift registers but alas, nothing.

Should I just go myself to the store and ensure that I get the correct capacitors?

Edit: I also bought a few transistors to play around with but there is of course an issue here too. If I hold the wire that goes from the shift register to the base pin of the transistor between two fingers everything works perfectly with the transistor. But if I am not holding the wire, the current to the LED is super low, hardly any light up at all. I am not sure what would cause that but I can say that my wires are quite basic (my cables are just untwisted ethernet cables...).

Last Edit: The only company around me is called Elfa and on their website I can't find any 100 nf ceramic decoupling capacitors. My search leads me to https://www.elfaelektroonika.ee/elfa3~ee_en/elfa/init.do?cat=0&sq=ceramic+decoupling+capacitor+100+nf&sel=1&solrRows=10&selectedCategory=&fq=|inStock%3Atrue|priceRangeMin%3A0|priceRangeMax%3A1&sortBy=&sortOrder=&priceRangeMin=0&priceRangeMax=1&searchFilterInStock=inStock

We have become so bogged down in decoupling capacitors that we have failed to look at anything else.

I see that you are using pin D1 in your wiring diagram. You are also using the Serial port.

You can't do both. Try moving D1 to D2 instead.

Also, you haven't posted your complete code. You know how I can tell? You're not defining your pin variables anywhere. Please post your full code.

Ok, my package finally arrived with bunches of jumper wires and another arduino (micro this time)! I was also able to get the proper decoupling capacitors. After using proper jumper wires to wire everything up, it all seams to work properly.

So, thank you everyone for your help. I learned quite.

My last question is - on the datasheet for the shift registers that I am using (http://www.adafruit.com/datasheets/tpic6b595.pdf), there are 3 ground pins per register. Do I need to put each of these pins to ground or can I just put 1 to ground and call it a day? I just want to make sure I don't fry my registers.

Follow the data sheet's recommendation... Always unless you KNOW SPECIFICALLY OTHERWISE...From the symptoms you quote you have a 'floating' input to the S.R.
Go over your wiring carefully and If you don't find it... POST YOUR CODE AND AN ACCURATE DRAWING OF THE DEVICE. An Accurate Schematic would be great but good pictures of your wiring are better than nothing. Without your code and drawings/pictures anything returned is at best a guess...

Bob