quiet start-up for shift register?

I have an arduino connected to a 74HC595 shift register, similar to the set-up in this tutorial (http://bildr.org/2011/02/74hc595/). The output pins of the shift register are connected to some relays. Output pin high sets relay off; output pin low sets relay on.

My problem is that when I start or reset the arduino, the relays chatter rapidly for a second or so. I would like to avoid this.

What is the best way avoid fluctuations in the shift register output pins when the arduino is starting up? I've tried writing to the shift register in the arduino setup() function, but that doesn't seem to be soon enough. I'm using digital output pins 8, 9 and 10 on the arduino to control the shift register. Would I have better luck with different pins?

Only sure way is to control the output enable pin also.
Pull it high with 10K resistor, and pull all the outputs high also.
When your sketch starts up, don't drive output enable low until you have shifted 1's in and are ready to start driving the outputs high or low.

How about - instead of tying OE to ground, connect it to an IO pin (any free Arduino pin) and a 10K pullup resistor.

The pullup resistor will keep OE high until you're ready for it, and when OE is high on a 74hc595 its output pins are in high impedance (disconnected).

When your startup & config code is done running in your Arduino sketch, do digitalWrite(yourPin, LOW) to enable the 74hc595's output pins, and away you go.

Good luck!

Thank you the quick and helpful answers. I had tried controlling OE; what I was missing was the pull-up resistors.

magagna:
How about - instead of tying OE to ground, connect it to an IO pin (any free Arduino pin) and a 10K pullup resistor.

The pullup resistor will keep OE high until you're ready for it, and when OE is high on a 74hc595 its output pins are in high impedance (disconnected).

When your startup & config code is done running in your Arduino sketch, do digitalWrite(yourPin, LOW) to enable the 74hc595's output pins, and away you go.

Good luck!

You can do that? That is beautiful.

You can do that? That is beautiful.

Yep, I've done this before with a LED matrix -- shut off OE, update the shift registers and switch to the next row, then turn OE back on. This gets rid of any ghosting between the rows.

shut off OE, update the shift registers and switch to the next row, then turn OE back on.

You can get flickering with this approach, if a lot of data is transmitted.

A better approach is to use the latch.

Can someone help me with a schematic on where to connect and put the resistor. I am novice and defenitely need your help to solve the same problem of mine.

The problem described here is an extremely badly thought-out design.

If you know that the shift register will be cleared on reset - set to LOW - and there is a control pin specifically to do just this, then it is simply stupid to use it in an active-LOW arrangement to control relays - or anything else. You are your own worst enemy if you make this blunder.

If you want to control relays, you use a TPIC6B595 (or its variants). It pulls down respective outputs when the corresponding latch bit is HIGH, and can drive 150 mA (more with the "C" version) to relays running at up to 45 V. Why would you ever do it any other way?

Hi Paul thanks for your reply. excuse me as I can understand only part of your answer. Let me ask you one more question.

  1. for the very first time I run the program I want to connect my relay to the arduino board and want the relay to remain off until i turn it on through my program. Now when I turn on the board the relay toggles on/off for multiple times and then it stabilizes. i connected it to pin 13 or arduino uno.
  2. When the power goes off and comes back i want the relay to return to its previous state (on/off)
  3. How can i avoid the initial toggling. should i connect it to different pin? i am planning to connect at least 8 relays and i guess i have to use pin 13 also.

I have basic understanding of electronics and will need little extra help to understand more technical terms. once again thanks for your reply.

The problem is that you have suggested that you have it wired such that the relays are actuated when the shift register output is LOW or perhaps even, open circuit.

I want to see a diagram of what circuit you are using to connect the relays before any useful suggestions can be made. Web link or photo of diagram. (All photos to be taken in daylight and perfectly focussed if you please!) "Connected to some relays" just isn't going to cut it, and we need to know what relays these are, their coil resistance and operating voltage. Are you using a pre-made module? If so, the Web link to this module.

I am using the below diagram an link as reference to build my circuit

http://cdn.instructables.com/FXF/4R6Z/HRCK38OG/FXF4R6ZHRCK38OG.MEDIUM.jpg

I am using uno bord and for the two green lines that goes to the relay i use pin 13 and 12

Thanks

Well now, that diagram does not in any way whatsoever refer to a 74HC595, so it is of no use whatsoever, nor is the (Ugh!) "instructable".

So let's have another try.

Oh wait!
:astonished: :astonished: :astonished: Oh! :astonished: :astonished: :astonished:

You mean your problem has nothing to do with the thread that you have added to? Now it makes more (or indeed, less!) sense!

I think you had better start again!

You are controlling a (twin) relay board.

You are using a UNO - at 5 V.

You are having some problems with spurious operation of the relays. I can guess part of the problem because it appears here so often.

Right, you must give a weblink to the relay board you are using.

You must show the complete code you are using; go and read the instructions, then mark up the code as such so we can examine it conveniently and accurately.

I bought the relay board on ebay the board uses optocoupler and jumper wires are connected to jd-vcc and vcc. There are four pins provided in the relay board. for which vcc and gnd I am connecting to the 5v and gnd pins in my uno. the other two pins I connected to pin 13 and 12.

Below is the code i am using. For now I am working with only one relay.

char val;         // variable to receive data from the serial port
int ledpin = 13;  // LED connected to pin 2 (on-board LED)

void setup()
{
  pinMode(ledpin, OUTPUT); // pin 3 (on-board LED) as OUTPUT
  digitalWrite(ledpin, LOW);  // turn ON pin 2

    Serial.begin(9600);       // start serial communication at 115200bps

}

void loop()

{
  if( Serial.available() )       // if data is available to read
  {
    ;
  }
  val = Serial.read();         // read it and store it in 'val'

  if( val == 'a' )               // if 'a' was received led 2 is switched off
  {
        digitalWrite(ledpin, HIGH);    // turn Off pin 2
  }
 
  if( val == 'A' )               // if 'A' was received led 2 on
  {
        digitalWrite(ledpin, LOW);  // turn ON pin 2
  }

}

cmagagna:
How about - instead of tying OE to ground, connect it to an IO pin (any free Arduino pin) and a 10K pullup resistor.

The pullup resistor will keep OE high until you're ready for it, and when OE is high on a 74hc595 its output pins are in high impedance (disconnected).

When your startup & config code is done running in your Arduino sketch, do digitalWrite(yourPin, LOW) to enable the 74hc595's output pins, and away you go.

Good luck!

I've found this works really well,for outputs 0 -7, but the overflow pin (which is not affected by the OE pin according to the datasheet) stubbornly remains on at startup and while the Arduino reset pin is being pressed. I'm not going to lose any sleep over it, it works well enough for my project (which will be transferred to an ATTiny so I'll run out of pins) but if anyone has any ideas - or spots an obvious flaw in my code - that would be useful, thanks.

  digitalWrite (latchPin, LOW);
   int i;
   for (i=0; i<=8; i++)      //Clear-down all outputs prior to O/P, inc overflow
      {
       digitalWrite (dataPin, 0);
       digitalWrite (clockPin, HIGH);
       digitalWrite (clockPin, LOW);
      }
    digitalWrite (latchPin, HIGH);

  pinMode (enablePin, OUTPUT);
  digitalWrite (enablePin, LOW);                //enable the ouput (hopefully!)

Sorry, you have a "snippets"problem - unless and until you actually post your code, I don't think it is worth figuring it out. :astonished:

Either that or go back and explain what is your purpose for using the cascade output.

Paul__B:
Sorry, you have a "snippets"problem - unless and until you actually post your code, I don't think it is worth figuring it out. :astonished:

Either that or go back and explain what is your purpose for using the cascade output.

No current (no pun intended!) use for it. I'm curious to know how to control this in case I need to know in future ta.

You can't. 595 has garbage in it. With OE you suppress it for the outputs but Q7' isn't affected by that. Would make daisy chaining a pain if it would... Aka, just use the outputs :slight_smile:

PS You could just use shiftOut() instead of your inline version of it :slight_smile:

septillion:
You can't. 595 has garbage in it. With OE you suppress it for the outputs but Q7' isn't affected by that. Would make daisy chaining a pain if it would... Aka, just use the outputs :slight_smile:

PS You could just use shiftOut() instead of your inline version of it :slight_smile:

I guessed it might be a design feature, never thought it might be to do with daisy-chaining but at least I know now, ta.

RMurphy195:
I guessed it might be a design feature, never thought it might be to do with daisy-chaining but at least I know now, ta.

Well, that is what it is for, and its crucial and in fact, only purpose.