How to use a relay module with Arduino

Posted on by
4-Channel relay module

4-Channel relay module

To control voltage fed else than we can use Arduino devices most common method is by relays. The relays provide us with electrical isolation between Arduino and the device in question we want to control such a lighting system, an engine AC or DC. Thus by means of Arduino digital pins we put on and off electrical appliances with a 0 or a 1.

The module we will use consists of 4 relays SRD-05VDC-SL-C, is powered to 5 volts and closes the circuit when we put it to 0. This is not always that way, depends on the relay we use. To use connect VCC (5V) and GND Arduino and 4 digital outputs, in this case we use the pins 2,3,4 and 5.

Code

#define RELAY_ON 0    
#define RELAY_OFF 1
 
 
void setup () {
  digitalWrite (2, RELAY_OFF);
  digitalWrite (3, RELAY_OFF);
  digitalWrite (4, RELAY_OFF);
  digitalWrite (5, RELAY_OFF);
  
  pinMode (2, OUTPUT);
  pinMode (3, OUTPUT);
  pinMode (4, OUTPUT);
  pinMode (5, OUTPUT);
  
}
 
void loop () {
  
  digitalWrite (2, RELAY_ON);
  delay (2000);
  digitalWrite (2, RELAY_OFF);
  delay (2000);  
}

And only it depends on your imagination use that you can give to this module from an automated irrigation pump, a lighting system or for example a temperature and humidification system.

Comments are disabled