Electronic Components
- Home|
- Switch Control|
- 5V Relay Single Channel
5V Relay Single Channel
This single channel 5v relay module can be used in projects, such as smart home implementation and other automated applications, including switching LED's, Motors, Lamps, Pumps, Roller blinds, etc... It can be controlled directly with 3.3v or 5v logic signals from a micro-controller or TTL drivers. Comes with 2 LEDs: Red for power and Green to indicate when the Relay is ON
- Code
- Questions & Answers
- Specifications
basic Arduino Code for Single Relay Module
The Arduino LED (connected to pin 13)will flash briefly to indicate the relay is on, at the same time the relay will turn ON. After aproximatley 1 sec the relay will turn OFF for about 1 sec then the cycle will repeat. If you open the Serial Port at 9600 Baud: You will see a text confirmation of when the relay is ON / OFF You will also see the TX Led flash briefly when the serial lines are sent.
/* BASIC RELAY TIMER *************************************************** * WIRING: * 5v pin on the Arduino to VCC on the relay board * GND pin on the Arduino to GND on the relay board * Pin 7 on the Arduino to IN on the relay board *************************************************** * FUNCTION: * The Arduino LED (connected to pin 13)will flash briefly * to indicate the relay is on, at the same time the relay * will turn ON. * * After aproximatley 1 sec the relay will turn OFF * for about 1 sec then the cycle will repeat. * * If you open the Serial Port at 9600 Baud: * You will see a text confirmation of when the relay is ON / OFF * You will also see the TX Led flash briefly when the serial lines are sent. */ // Declare Pins int relayPin = 7; int ledPin = 13; // the setup function runs once when you press reset or power the board void setup() { // Open the Serial port to (9600 Baud) Serial.begin(9600); // initialize digital pin 13 (ledPin) as an output. pinMode(relayPin, OUTPUT); pinMode(ledPin, OUTPUT); // Set the relay pin to HIGH which holds the relay OFF digitalWrite(relayPin, HIGH); } // The loop runs over and over again until the arduino is re-programmed void loop() { digitalWrite(ledPin, HIGH); // The LED is On digitalWrite(relayPin, LOW); // The Relay is On Serial.println("The Relay is ON"); delay(350); // Led delay digitalWrite(ledPin, LOW); // The LED is Off delay(650); // Relay interval digitalWrite(relayPin, HIGH); // The Relay is Off Serial.println("The Relay is OFF"); delay(1000); // wait for a second }
intermediate Arduino Code for Single Relay Module
The Arduino LED (connected to pin 13)will flash briefly when the Relay is on. Open the Serial monitor (9600 baud) Type 1 to turn the relay ON Type 0 to turn the relay OFF You will see a text confirmation of when the relay is ON / OFF You will also see the TX Led flash briefly when the serial lines are sent.
/* INTERMEDIATE RELAY PROGRAM *************************************************** * WIRING: * 5v pin on the Arduino to VCC on the relay board * GND pin on the Arduino to GND on the relay board * Pin 7 on the Arduino to IN on the relay board *************************************************** * FUNCTION: * The Arduino LED (connected to pin 13)will flash briefly * when the Relay is on. * * Open the Serial monitor (9600 baud) * Type 1 to turn the relay ON * Type 0 to turn the relay OFF * * You will see a text confirmation of when the relay is ON / OFF * You will also see the TX Led flash briefly when the serial lines are sent. */ // Declare Pins int relayPin = 7; int ledPin = 13; void setup() { // Start Serial at 9600 baud Serial.begin(9600); // Set the relayPin as an OUTPUT pinMode(relayPin, OUTPUT); pinMode(ledPin, OUTPUT); // Set the relayPin HIGH to hold the relay OFF digitalWrite(relayPin, HIGH); // Acknowledge the program Serial.println("PROGRAM READY"); Serial.println(""); } // The loop runs over and over again until the arduino is re-programmed void loop() { while (Serial.available()) { char inChar = (char)Serial.read(); if (inChar == '1') { digitalWrite(relayPin, LOW); // Turn the Relay ON Serial.println("RELAY ON"); } else if (inChar == '0') { digitalWrite(relayPin, HIGH); // Turn the Relay OFF Serial.println("RELAY OFF"); } else if (inChar != 1 && inChar != 0){ Serial.println ("Command not recognised"); } } }
5V Relay Single Channel
It can be controlled directly with 3.3v or 5v logic signals from a micro-controller or TTL drivers. 3 Pins: VCC / GND / IN (Connection instructions are in the comments at the top of the example code). Active LOW Low = On / Less than 1 volt at the IN pin will turn the relay ON High = Off / Greater than 3 volts at the IN pin will turn the relay OFF