Arduino code and Video for Dual Channel 5V Relay
This is the Arduino code for Dual Channel 5V Relay
This video shows you how to use control or connect 2 AC or DC load using Arduino and relay.http://robojax.com/learn/arduino/
We have two codes in this page. Please see below
/*
* This is the Arduino code for Dual Channel 5V Relay
* to control turn ON or OFF AC or DC load. You can control 2 different loads such as bulbs, or heater or other machine
watch video instruction for this code https://youtu.be/EclIomn_3dI
* *
* Written by Ahmad Shamshiri for Robojax Video
* Date: Dec 26, 2017, in Ajax, Ontario, Canada
* Permission granted to share this code given that this
* note is kept with the code.
* Disclaimer: this code is "AS IS" and for educational purpose only.
Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in structured course with all material, wiring diagram and library
all in once place. Purchase My course on Udemy.com http://robojax.com/L/?id=62
If you found this tutorial helpful, please support me so I can continue creating
content like this. You can support me on Patreon http://robojax.com/L/?id=63
or make donation using PayPal http://robojax.com/L/?id=64
*
* This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been download from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
void setup() {
Serial.begin(9600);// setup Serial Monitor to display information
pinMode(7, OUTPUT);// connected to Relay 1
pinMode(8, OUTPUT);// connected to Relay 2
}
void loop() {
digitalWrite(8, LOW); // turn relay 2 OFF
Serial.print("Pin 8 LOW");
digitalWrite(7,HIGH);// turn relay 1 ON
Serial.println(" Pin 7 HIGH");
delay(3000);// keep in relay 2 OFF and relay 1 On for 3 seconds
digitalWrite(7, LOW);// turn relay 1 OFF
digitalWrite(8,HIGH);// turn relay 2 ON
Serial.print("Pin 7 LOW");
Serial.println(" Pin 8 HIGH");
delay(3000);// keep in relay 1 OFF and relay 2 On for 3 seconds
}
Control AC load using 2 channel relay and Arduino
This code is a little cleaner with each pin have been defined at the top of the code to make it eqasy to chage the pins. Just change the pin at top and all the pins will be changed
/*
* This is the Arduino code for Dual Channel 5V Relay
* to control turn ON or OFF AC or DC load. You can control 2 different loads such as bulbs, or heater or other machine
watch video instruction for this code https://youtu.be/EclIomn_3dI
* *
* Written by Ahmad Shamshiri for Robojax Video
* Date: Dec 26, 2017, in Ajax, Ontario, Canada
* Permission granted to share this code given that this
* note is kept with the code.
* Disclaimer: this code is "AS IS" and for educational purpose only.
Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in structured course with all material, wiring diagram and library
all in once place. Purchase My course on Udemy.com http://robojax.com/L/?id=62
If you found this tutorial helpful, please support me so I can continue creating
content like this. You can support me on Patreon http://robojax.com/L/?id=63
or make donation using PayPal http://robojax.com/L/?id=64
*
* This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been download from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const int relay1Pin =7;// define pin for relay 1
const int relay2Pin =8; // define pin for relay 2
void setup() {
Serial.begin(9600);// setup Serial Monitor to display information
pinMode(relay1Pin, OUTPUT);// connected to Relay 1
pinMode(relay2Pin, OUTPUT);// connected to Relay 2
}
void loop() {
digitalWrite(relay2Pin, LOW); // turn relay 2 OFF
Serial.print("Pin 8 LOW");
digitalWrite(relay1Pin,HIGH);// turn relay 1 ON
Serial.println(" Pin 7 HIGH");
delay(3000);// keep in relay 2 OFF and relay 1 On for 3 seconds
digitalWrite(relay1Pin, LOW);// turn relay 1 OFF
digitalWrite(relay2Pin,HIGH);// turn relay 2 ON
Serial.print("Pin 7 LOW");
Serial.println(" Pin 8 HIGH");
delay(3000);// keep in relay 1 OFF and relay 2 On for 3 seconds
}
?>