Simple Circuit to test Solid State Relays

solid-state-relay

Solid State Relays can be purchased mounted on boards from one to eight mounted on boards for the Arduino. I purchased a two relay board, like this one here. Currently they cost around two to three times a conventional relay mounted on a PCB. The advantages are that they are smaller, have no moving parts and are silent in operation.

I put together a simple circuit to test a two channel SSR, but it could be expand as required. The relay board  has a Ground Connection and a 5 volt supply pin. Each relay has a trigger pin. The Relay is switched on with a logic HIGH (5 volts).

The circuit I used is shown here:

solid-state-relay-circuit-diagram

And here is the sketch I used:

/***************************************************
*
* Solid State Relay, Simple Test Circuit
*
* Connections:
* DC_ to Arduino 5 volts
* DC- to Arduino Gnd
* CH1 toArduino pin 2
* CH2 to Arduino pin 3
*
* Chris Rouse December 2016
*
***************************************************/
#define CH1pin 2
#define CH2pin 3

void setup() {
Serial.begin(9600);
pinMode(CH1pin, OUTPUT);
pinMode(CH2pin, OUTPUT);
digitalWrite(CH1pin, LOW); // turn CH1 OFF
digitalWrite(CH2pin, LOW); // turn CH2 OFF

}

void loop() {
digitalWrite(CH1pin, HIGH); // turn CH1 ON
digitalWrite(CH2pin, LOW); // turn CH2 OFF
delay(1000);
digitalWrite(CH1pin, LOW); // turn CH1 OFF
digitalWrite(CH2pin, HIGH); // turn CH2 ON
delay(1000);

}

The two relays are simply turned off and on and the LEDs light to show the relays are operational.

Capacitance Switch controls a Relay on Arduino

The sketch was updated Nov 2015. It can be downloaded from my GitHub page here. For a sketch that will control up to five relays from five switches see my post here.

This sketch uses a small capacitance switch to control a relay. The output from the switch is normally LOW, but when touched the output goes HIGH. The relay used is a single relay made by Ywrobot, it has a single changeover switch output and needs 5 volts to operate. The relay is operated when the control input is HIGH and when this happens the onboard LED turns on and the switch output changes.


The connection diagram shows a 4 capacitance switch, but a single switch would work equally well. The Capacitance switch is powered from the digital pins.

When the sketch is first run the relay is ‘off’, when the switch is touched the relay is switched on and the LED lights, the Arduino LED on pin 13 remains alight as long as the switch is touched. The relay remains switched ON until the capacitance switched is touched for a second time and the cycle can be completed.

The WHILE loop acts as a de-bounce, waiting until the switch is released.

/* Simple sketch to show the operation of a capacitance switch

Chris Rouse Nov 2015

The switch used here is mounted on a small board
with three connections, G (Gnd) V (Vcc) ans Out ( the switch output)
The switch output goes LOW when pressed

Connect Gnd to Arduino pin 5 - supplies 0v
Connect Vcc to Arduino pin 6 - supplies 5 volts
Connect Out to Arduino pin 7

The relay used is a Ywrobot board with 1 relay
The relay is switched on by a HIGH signal

Connect the Relay board to Gnd and 5 volts
and the control pin to Arduino pin 8
*/
boolean latch = false;

# define relay 8 // this is the pin used to switch the relay
# define Gnd 5 // this is the pin used to act as Gnd for the switch
# define Vcc 6 // this is the pin used to act as +5v for the switch
# define capSwitch 7 // this is the capacitance switch output
# define LED 13 // onboard LED

void setup() {
Serial.begin(9600); // used for debugging
pinMode(relay, OUTPUT);
digitalWrite(relay,LOW); // turn OFF the relay
pinMode(capSwitch, INPUT);
pinMode(Vcc, OUTPUT);
digitalWrite(Vcc,HIGH);// this pin will supply 5 volts
pinMode(Gnd, OUTPUT);
digitalWrite(Gnd,LOW); // this pin will supply the GND to the board
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW); // turn LED off
}

void loop() {

// turn switch ON on first touch
if ((digitalRead(capSwitch) == HIGH) && (latch == false)) {
digitalWrite(relay, HIGH); // relay ON
Serial.println("Relay ON");
digitalWrite(LED, HIGH); // turn LED ON
latch = true;
// wait here until the cap switch is no longer touched
while ((digitalRead(capSwitch) == HIGH)){
digitalWrite(LED, LOW); // turn LED OFF
delay(500); // try to stop debounce
}
}

// turn relay OFF on second touch
if ((digitalRead(capSwitch) == HIGH) && (latch == true)) {
digitalWrite(relay, LOW); // relay OFF
Serial.println("Relay OFF");
digitalWrite(LED, HIGH); // turn LED ON
latch = false;
// wait here until the cap switch is no longer touched
while ((digitalRead(capSwitch) == HIGH)){
digitalWrite(LED, LOW); // turn LED OFF
delay(500); // try to stop debounce
}
}
}

Simple relay operation with Arduino

  

This is a very simple sketch to show the operation of a relay. Relays for the Arduino are available on small pcb’s and the one I am using is a single relay from Ywrobot. This relay needs 5 volts to operate and has a single changeover switch that can switch 10amps AC at 250 volts. The board has two LED indicators, one to show power is connected and the other to show the relay has been activated. There are only three pins, Gnd (connected to Gnd on the Arduino), Vcc (connected to 5 volts on the Arduino) and a control pin. This control pin connects to a digital I/O pin and a LOW on this pin will switch on the relay. This project used a push switch connected to pin 7 to operate the relay, but pin 7 could be connected as an input from another circuit.

The input pin for the switch is defined as pin 7, but could be any digital pin. The output from pin 8 is used to switch the relay, but any pin could be used.

There are two variables that change how the relay operates, HOLD and LATCH and these can easily be changed. HOLD defines how long the relay will be switched ON for after the input is switched off. In this sketch it is set to 200ms, but can be many seconds. The second variable LATCH if set to TRUE will keep the relay switched ON until RESET is pushed on the Arduino. If it is set to FALSE as it is here the relay will switch off after the time set by HOLD.

/* Simple sketch to show the operation of a push button and relay

Connect a normally open push switch to pin 7 and Gnd on the Arduino

The relay board has three pins, Gnd, Vcc and Control
Connect Gnd to Gnd on Arduino
Connect Vcc to 5 volts on Arduino
Connect Control on relay board to pin 8 on the Arduino
*/

int hold = 200; // time stays on for after button released in ms
boolean latch = false; // if true then the relay remains closed
# define relay 8 // this is the pin used to switch the relay
# define pushSwitch 7 // this is the push switch input

void setup() {
 pinMode(relay, OUTPUT);
 digitalWrite(relay,LOW);  // turn OFF the relay
 pinMode(pushSwitch, INPUT_PULLUP);  //  attaches a resistor from input to Vcc
 digitalWrite(relay, HIGH); // turn off relay

}

void loop() {

 if (digitalRead(pushSwitch) == LOW ) {  // LOW if pressed
   digitalWrite(relay, LOW);  // relay ON
   delay(hold); // leave relay ON for a short while before turning OFF
 }
 if(latch == false){
   digitalWrite(relay, HIGH);  // relay OFF
 }

}