Arduino access code protected 4 channel relay

Hello world! This Arduino access code protected 4 channel relay code is made to put a access code/password protection on your “dangerous” machines in the garage/workplace (For example). To protect your kids from the danger that might lurk in your garage, without the code power cannot be turned on. Hide it in a box that you can lock, put it on the wall and add a little safety to your garage. Of course it can be used to turn on/off anything! Very simple but i’m sure it is useful for many of you.

Usage of the Device.

Pressing: * will turn off everything and go back into NoAccess mode.
A turns on/off relay 1
B turns on/off relay 2
C turns on/off relay 3
D turns on/off relay 4

Default code is: 3241

PS:
The red led is to notify you that nobody can turn on/off machines. You could reverse this and switch it to pin 10 where the green light is to notify that the devices are still able to be put on by anyone, so the red led warns you the power is still on. While in NoAccess state the Green Led notifies you everything is safe! (Just an idea)

Schematic:
Arduino access code protected 4 channel relay

Wire it up like the Schematic and it should work after uploading the code.
If not…
You need the following Libraries.
Keypad.h
Password.h

Parts list:
Arduino uno, I used the RobotDyn uno.
4 Channel Relay.
4×4 Keypad
Jumper wire set MM/FF/MF
buzzer.
2 x Leds / 1 green / 1 red.

Code:

/*
 Author: Danny van den Brande. Arduinosensors.nl. BlueCore Tech.
 Hello world! This code is made to put a 
 access code/password protection on your dangerous machines in the garage/work place for example.
 To protect your kids from the danger that might lurk in your garage, without the code.
 power cannot be turned on. Hide it in a box with that you can lock on the wall
 and add a little safety to your garage. Of course it can be used to turn on/off anything.
 */
#include <Keypad.h> 
#include <Password.h> 
 
int relay1 = 2; 
int relay2 = 3; 
int relay3 = 4;
int relay4 = 5; 
int buzzer = 11;

int noAccesled = 9; 
int AccesLed = 10; 
 
int noAcces = 1;
int passinput = 0;
 
long flashvarled = 0; 
long flashtimeled = 300;  
 
const byte ROWS = 4;
const byte COLS = 4;
 
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}};
byte rowPins[ROWS] = {
  12, 13, A5, A4};
byte colPins[COLS] = {
  A3, A2, A1, A0};
 
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
Password password = Password("4345"); // change the access code here
 
void setup(){
  Serial.begin(9600);
  pinMode(relay1, OUTPUT);
  digitalWrite(relay1, 255);
  pinMode(relay2, OUTPUT);
  digitalWrite(relay2, 255);
  pinMode(relay3, OUTPUT);
  digitalWrite(relay3, 255);
  pinMode(relay4, OUTPUT);
  digitalWrite(relay4, 255);
  pinMode(noAccesled, OUTPUT);
  digitalWrite(noAccesled, 255);
  pinMode(AccesLed, OUTPUT);
  digitalWrite(AccesLed, 0);
  pinMode(buzzer, OUTPUT);
}
 
void loop(){
  char key = keypad.getKey();
  if(noAcces){
    if(passinput){
      unsigned long currentvarled = millis();
      if(currentvarled - flashvarled > flashtimeled) {
        flashvarled = currentvarled;
        digitalWrite(noAccesled, !digitalRead(noAccesled));
      }
    }
    else{
      digitalWrite(noAccesled, 255);
    }
    digitalWrite(AccesLed, 0);
  }
  if (key != NO_KEY){
    Serial.println(key);
    password.append(key);
    passinput = 1;
    digitalWrite(buzzer, HIGH);
    delay(100);
    digitalWrite(buzzer, LOW);
    if(key == '*'){
      password.reset();
      passinput = 0;
      noAcces = 1;
      digitalWrite(relay1, 1);
      digitalWrite(relay2, 1);
      digitalWrite(relay3, 1);
      digitalWrite(relay4, 1);
    }
    if(password.evaluate()) {
      noAcces = !noAcces; 
      password.reset();
      passinput = 0;
    }
    if(!noAcces) {
      passinput = 0;
      digitalWrite(noAccesled, 0);
      digitalWrite(AccesLed, 255);
      switch (key) {
        case 'A':
          digitalWrite(relay1, !digitalRead(relay1));
          break;
        case 'B':
          digitalWrite(relay2, !digitalRead(relay2));
          break;
        case 'C':
          digitalWrite(relay3, !digitalRead(relay3));
          break;
        case 'D':
          digitalWrite(relay4, !digitalRead(relay4));
          break;
      }
      password.reset();
    }
  }
}
Danny van den Brande

http://www.arduinosensors.nl

Programmer, Game Designer, 3D Designer, Web Designer, Graphic Designer. Jup this website looks crappy.. :) But enjoy the projects! Everything you need is here.

Leave a Reply

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