SSR blinking, using 166 & 595 Registers w/Mosfit

Hey Guys, I'm a newbie here. First, y'all are awesome. There is so much good info here and I have been using this site for a few weeks (I'm too new to provide any value additional info).

I'm a Mechanical Engineer with a masters in Systems Engineering. I'm trying to get into circuit design and mechatronics. I'm installing a new router at home. In my control panel, I have manual switches to turn certain items on and off. The CNC will also have the ability to do the same. Originally I was just going to use some simple on-off-on switches but figured this would be a great side project to do some circuit designing....

I have a Arduino Mega 2560 and I need more digital inputs and outputs than offered (adding a touch screen and that uses a lot of them). So, after done some searching/learning, I think adding a 74HC166N shift register(s), would give me the additional inputs I need. Then I was going to pair that with a 595 shift register to control the outputs. Currently I have 595 sending signals to a ALD210808PCL Mosfet.

It took me quite a while to get everything "working." (By working I mean that I switch on and off any of the 8 switches [inputs to the 166] and the Mosfet turns on the right solid state relay.) Now that I have started putting a load to the SSR's, the SSR's are loosing their signal or something. The LED on them slowly fades until the circuit is broken, then it comes right back.

I don't know enough to know if I picked the wrong components or not. I also, have not hooked up a meter to monitor the signal strengths (don't know where to start probing).

Here is a list of the components I'm using:
SSR: Kerwinn KG1-1DA25
Mean Well: IRM-45-12ST
Input Shift Register: SN74HC166N
Output Shift Register: SN74HC595N
Mosfit(s): ALD210808PCL
Arduino Mega 2560
75 watt light bulb

Diagram:

Code: (Its mostly the Element 14 Learning Circuit 77 and 78 code)

////////////////////////////////
// Identify pins on Arduino Mega that are being used
////////////////////////////////
int ioSelect = 2;     // SR Pin 15.
int clockPulse = 3;   //SR Pin 7. 
int dataOut = 4;      //SR Pin 13.

int clearPin = 5; //Arduino pin 5 connected to Pin 10, SRCLR(Clear/Reset) of 74HC595
int serialData = 6;  //Arduino pin 6 connected to Pin 14, SER(serial input) of 74HC595 --- Serial in
int shiftClock = 7;  //Arduino pin 7 connected to Pin 11, SRCLK(shift clock) of 74HC595 -- this lets the register know when to accept a new input
int latchClock = 8;  //Arduino pin 8 connected to Pin 12, RCLK(storage/latch clock) of 74HC595 -- high pulse shifts data from rgister to latch

/////////////////////////////////
/// Identify variables
////////////////////////////////

int j;               //used in a for loop to declare which bit is set to 1
int value;           //stores the digital read value of the data pin 
                     //(0 if no button is pressed, 1 if a button is pressed)

byte switchVar = 0;  //stores a byte array to show which button was pressed


void setup() {
  //////////////////////////////////
  // Identify how pins are used //
  /////////////////////////////////
  pinMode(ioSelect, OUTPUT);
  pinMode(clockPulse, OUTPUT);
  pinMode(dataOut, INPUT);
  pinMode(clearPin, OUTPUT);
  pinMode(shiftClock, OUTPUT);
  pinMode(latchClock, OUTPUT);
  pinMode(serialData, OUTPUT);  

///////////////
// clears old data on register. good for start up
  digitalWrite(clearPin, LOW); //Pin is active-low, this clears the shift register 
  digitalWrite(clearPin, HIGH); //Clear pin is inactive
//////////////

//////////////
// Set baud rate
/////////////
  Serial.begin(9600);  //setting baud rate
}

void loop() {
  byte  dataIn = 0;       //Swap out byte for uint16_t or uint32_t
  digitalWrite(ioSelect, 0);    // enables parallel inputs
  digitalWrite(clockPulse, 0);  // start clock pin low
  digitalWrite(clockPulse, 1);  // set clock pin high, data loaded into SR
  digitalWrite(ioSelect, 1);    // disable parallel inputs and enable serial output 


 for(j = 0; j < 8; j++) {         //sets integer to values 0 through 7 for all 8 bits
    value = digitalRead(dataOut); //reads data from SR serial data out pin

    if (value) {
      int a = (1 << j);       // shifts bit to its proper place in sequence. 
                              /*for more information see Arduino "BitShift" */
      dataIn = dataIn | a;    //combines data from shifted bits to form a single 8-bit number
                              /*for more information see Arduino "Bitwise operators" */
      }
      digitalWrite(clockPulse, LOW);  //after each bit is logged, 
      digitalWrite(clockPulse, HIGH); //pulses clock to get next bit
    }
  

/////////////////////
// Transfer data to 595
///////////////////// 
 digitalWrite(latchClock, LOW);    // take the latchClock low so 
 shiftOut(serialData, shiftClock, MSBFIRST, dataIn); //shift out the bits 
 digitalWrite(latchClock, HIGH);  // take the latch pin high so the LEDs will light up  
  
//  delay(5000); //short delay added for debugging
} 

Lets start the troubleshooting from the software side did you check the output of the shiftin registers and the output that are sending to shiftout registers are in the format you want

Well, your switches are a direct short circuit from 5V to GND and SSR inputs and outputs are reversed, that's as far as I got. Good luck

If I remove all of the SSR's and put LED's in their place, everything works correctly. It took quite a few attempts but I believe the code is doing what I want or at least I get the desired results.

Maybe I'm not showing it correctly in the diagram.

The switches are connected correctly. The one side is connected to 5V positive. Once closed, the switch goes directly to the 166. Then there is a leg on that wire that the resistor is connected to and goes to ground.

I went in and fixed the schematic to reflect the actual wring. Sorry about that.

The SSR's are wired correctly. The positive sides goes to the 12v power and the negative goes to the MOSFET for ground. I checked with a meter and also the SSR's are marked + and -.

Question, I don't have the V+ or the V- hooked up on the MOSFET. Do I need them and if so, which power source? Do they use the 12V of the SSR or do they use the 5V of the Arduino?

I baby stepped my way to where I'm at now. When I was just using the 595 register and a single NPN MOSFET everything seemed to work fine, except the light would flicker. So, I added a capacitor in the circuit between the 595 and the MOSFET to keep the circuit active. Now that I'm using two registers, and this quad MOSFET, adding a capacitor doesn't do anything. So, I swapped out the quad MOSFET and went back to a single NPN MOSFET. When I did, the SSR still would open or blink. So, I don't think this is anything to do with the quad MOSFET but I just don't know.

Also, does resister sizes matter?

Please post your latest schematic revision. Is this the SSR you are using?
https://www.amazon.com/KERWINN-DA-Solid-State-Relay/dp/B0BYYZXJTX

Yes, those are the SSR's I'm currently using and my source.

Here is the complete updated diagram.

Thank you for your time in helping me. I appreciate it.

On a side note, I'm not married to any part or specific design of the system. So, if there is a better way or different components that would accomplish the same thing, I'm happy to go another way. I would like to continue down the road of creating a PCB and discussing why maybe a different circuit design is better. There is so much to learn.

The symbol you are using is an opto coupler or opto isolator. Does Kicad not have a DC / AC SSR symbol?

I'm brand new to KiCAD (this is the first time). I only see one solid state relay that mentions VAC. I'm not sure I understand how to read the diodes. Is A1/A2 the DC (activate side) or is 11/14?

image

Better, the DC input is A1(+) and A2(-) so for U6, 12V+ to A1, DN4 to A2, AC output is 11 and 14, VAC to 11, lamp to 14. You will have to flip the symbol horizontally, does that make sense?

On the actual SSR the terminals are:
A1 = 3 (+)
A2 = 4 (-)
11 = 1
14 = 2

I think so. I only changed that one. Is this correct? (U6 is now called U3)

Looks good to me as long as the MOSFET module can handle the SSR trigger current.

ok, so I fixed the schematic now.

As far as the MOSFET's, what do I do with pin 1,5,12 and 16?

In regards to the amperage, the SSR is rated at less than 5mA "break-state leakage current." Is that the amperage required to activate the SSR's MOSFET or what is that number?

image

If it requires 5mA, should I put a resistor inline between A2 and the MOSFET?

No decoupling caps are shown so -

This is very interesting. If I'm reading all of the posts correctly, I would add one or two (have to run the numbers) in the following locations:

SN74HC166N
Pins 16 and 8

SN74HC595N
Pins 16 and 9

I would not run between any of the MOSFETS.

I read a post stating I should have a diode between pins A1 and A2 to limit induction as well. Is that needed?

I will crunch some numbers here and see what I can come up with for capacitors.

"Is that the amperage required to activate the SSR's MOSFET"?

No:

The ALD210808 datasheet claims output current of 50mA, the SSR info does not specify input current @ 12V, so, measure the SSR's input current with your DMM. If less than about 30mA, should be OK.

Ok, so this is a little embarrassing, but I appreciate all of y'all help. After probing and looking at everything, adding the capacitors, it turned out to be the 12v source. I have a very poor test setup and I keep tearing it down to work, then re-connecting everything to perform the next development step after I get off (I work from home). Somewhere along the line, I connected the 12v incorrectly and it wasn't grounding correctly. So, it would measure 12v, but then drop as soon as a load higher than a LED would turn on. I fixed that and now everything is working properly.

So for historical reference for anyone else looking at doing this, here is where the project currently sits.

Schematic:

Code:

////////////////////////////////
// Identify pins on Arduino Mega that are being used
////////////////////////////////
int ioSelect = 2;     // SR Pin 15.
int clockPulse = 3;   //SR Pin 7. 
int dataOut = 4;      //SR Pin 13.

int clearPin = 5; //Arduino pin 5 connected to Pin 10, SRCLR(Clear/Reset) of 74HC595
int serialData = 6;  //Arduino pin 6 connected to Pin 14, SER(serial input) of 74HC595 --- Serial in
int shiftClock = 7;  //Arduino pin 7 connected to Pin 11, SRCLK(shift clock) of 74HC595 -- this lets the register know when to accept a new input
int latchClock = 8;  //Arduino pin 8 connected to Pin 12, RCLK(storage/latch clock) of 74HC595 -- high pulse shifts data from rgister to latch

/////////////////////////////////
/// Identify variables
////////////////////////////////

int j;               //used in a for loop to declare which bit is set to 1
int value;           //stores the digital read value of the data pin 
                     //(0 if no button is pressed, 1 if a button is pressed)

byte switchVar = 0;  //stores a byte array to show which button was pressed


void setup() {
  //////////////////////////////////
  // Identify how pins are used //
  /////////////////////////////////
  pinMode(ioSelect, OUTPUT);
  pinMode(clockPulse, OUTPUT);
  pinMode(dataOut, INPUT);
  pinMode(clearPin, OUTPUT);
  pinMode(shiftClock, OUTPUT);
  pinMode(latchClock, OUTPUT);
  pinMode(serialData, OUTPUT);  

///////////////
// clears old data on register. good for start up
  digitalWrite(clearPin, LOW); //Pin is active-low, this clears the shift register 
  digitalWrite(clearPin, HIGH); //Clear pin is inactive
//////////////

//////////////
// Set baud rate
/////////////
  Serial.begin(9600);  //setting baud rate
}

void loop() {
  byte  dataIn = 0;       //Swap out byte for uint16_t or uint32_t
  digitalWrite(ioSelect, 0);    // enables parallel inputs
  digitalWrite(clockPulse, 0);  // start clock pin low
  digitalWrite(clockPulse, 1);  // set clock pin high, data loaded into SR
  digitalWrite(ioSelect, 1);    // disable parallel inputs and enable serial output 


 for(j = 0; j < 8; j++) {         //sets integer to values 0 through 7 for all 8 bits
    value = digitalRead(dataOut); //reads data from SR serial data out pin

    if (value) {
      int a = (1 << j);       // shifts bit to its proper place in sequence. 
                              /*for more information see Arduino "BitShift" */
      dataIn = dataIn | a;    //combines data from shifted bits to form a single 8-bit number
                              /*for more information see Arduino "Bitwise operators" */
      }
      digitalWrite(clockPulse, LOW);  //after each bit is logged, 
      digitalWrite(clockPulse, HIGH); //pulses clock to get next bit
    }
  

/////////////////////
// Transfer data to 595
///////////////////// 
 digitalWrite(latchClock, LOW);    // take the latchClock low so 
 shiftOut(serialData, shiftClock, MSBFIRST, dataIn); //shift out the bits 
 digitalWrite(latchClock, HIGH);  // take the latch pin high so the LEDs will light up  
  
//  delay(5000); //short delay added for debugging
} 

Where to from here? I will continue to develop this project. Expand the registers to 16 bits, add a CAN Bus, and touch screen controls. Then print my first PCB!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.