relay is an electrically operated switch. Many relays use an electromagnet to mechanically operate a switch, but other operating principles are also used, such as solid-state relays. Relays are used where it is necessary to control a circuit by a separate low-power signal, or where several circuits must be controlled by one signal. [Wikipedia]

Controlling Relay

Controlling relay is like setting a pin HIGH / LOW.

different types of relay modules are available in the market but most widely used relays are Low-level trigger Relays.

Low-level trigger means it is activated at LOW voltage and de-activated at HIGH voltage




Relay have three pins

  • NO (Normally Open)
  • Common
  • NC ( Normally Connected )

When relay is not energized connection is from Com to NC and when it is energized the connection moves from NC to NO and hence we can switch the circuits.

evive 5V Relay circuit Fritzing Diagram



Example code when relay is connected to pin 2 and a low level trigger is used

High power circuit switching

Turns on and off a high power circuit connected on relay
when pressing pushbutton on evive.

available on
modified 13 Sep 2017
by Nihar Shah

This example code is in the public domain.

//#define button 38 // use for upper button
#define button 39 // use fot lower button
#define relay 2
int state = 0; // variable for reading the pushbutton status
void setup() {
// put your setup code here, to run once:
// initialize the relay pin as an output:
pinMode(relay, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(button, INPUT);

void loop() {
// read the state of the pushbutton value:
state = digitalRead(button);
// check if the pushbutton is pressed.
// if it is, the state is HIGH:
if (state == HIGH) {
// turn relay on:
digitalWrite(relay, LOW);
} else {
// turn relay off:
digitalWrite(relay, HIGH);



This Helped
This didn't help
Close Menu


STEMpedia Starter Package is now on Indiegogo!
Get 41% OFF with Super Early Bird discounts!