8 Chan relay module with arduino pro mini 3.3v

To begin with, an Arduino pro mini is capable of driving the 8 port relay with optocouplers, the power required to drive the mechanical relay is provided separately with the most common relay boards on the market, this photo (And video) should demonstrate that

8 channel relay module for arduino

In the photo above, the center connector is the COM (Common), the one to it’s left is the normally open, and the one to it’s right is normally closed

The jumper on the JD-VCC means using the same power that is powering the board for the coil, you can replace the jumper with an external power supply that doesn’t even need to have a common ground with the arduino’s power

The image above demonstrates the wiring, the power supply is a computer power supply, the relay module uses the 5V power lines from the power supply, while the Arduino uses the 3V3 line, the board’s control lines will work on logic low, hence, it will work when we are below 2V, it works perfectly fine with the 3.3V from the Arduino.

here is the source code (Very simple code, just to pull the digital lines low, then high again, the delay in the engagement is just for fun.)


// constants won't change. Used here to set a pin number:
const int ledPin =  LED_BUILTIN;// the number of the LED pin
const int relay1 = 2;
const int relay2 = 3;
const int relay3 = 4;
const int relay4 = 5;
const int relay5 = 6;
const int relay6 = 7;
const int relay7 = 8;
const int relay8 = 9;



// Variables will change:
int ledState = LOW;             // ledState used to set the LED

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change:
const long interval = 2000;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  pinMode(relay5, OUTPUT);
  pinMode(relay6, OUTPUT);
  pinMode(relay7, OUTPUT);
  pinMode(relay8, OUTPUT);
}

void loop() {
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the difference
  // between the current time and last time you blinked the LED is bigger than
  // the interval at which you want to blink the LED.
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
      digitalWrite(ledPin, ledState);
      digitalWrite(relay1, ledState);
      delay(200);
      digitalWrite(relay2, ledState);
      delay(200);
      digitalWrite(relay3, ledState);
      delay(200);
      digitalWrite(relay4, ledState);
      delay(200);
      digitalWrite(relay5, ledState);
      delay(200);
      digitalWrite(relay6, ledState);
      delay(200);
      digitalWrite(relay7, ledState);
      delay(200);
      digitalWrite(relay8, ledState);
      
      delay(400);
      ledState = LOW;
      digitalWrite(ledPin, ledState);
      delay(400);
      ledState = HIGH;
      digitalWrite(ledPin, ledState);
      digitalWrite(relay2, ledState);
    } else {
      ledState = LOW;
      digitalWrite(ledPin, ledState);
      digitalWrite(relay1, ledState);
      delay(100);
      digitalWrite(relay2, ledState);
      delay(200);
      digitalWrite(relay3, ledState);
      delay(300);
      digitalWrite(relay4, ledState);
      delay(400);
      digitalWrite(relay5, ledState);
      delay(500);
      digitalWrite(relay6, ledState);
      delay(600);
      digitalWrite(relay7, ledState);
      delay(150);
      digitalWrite(relay8, ledState);
      delay(150);
      ledState = HIGH;
      digitalWrite(relay8, ledState);
      delay(700);
      ledState = LOW;
      digitalWrite(relay8, ledState);
      delay(300);
      ledState = HIGH;
      digitalWrite(relay8, ledState);
      delay(700);
      ledState = LOW;
      digitalWrite(relay8, ledState);
      delay(300);
    }

    // set the LED with the ledState of the variable:
    //digitalWrite(ledPin, ledState);
  }
} 

Leave a Reply

Your email address will not be published. Required fields are marked *