Arduino - ACCESS CODE PROTECTED 4 CHANNEL RELAY With 4x4 Keypad

9.5K4711

Intro: Arduino - ACCESS CODE PROTECTED 4 CHANNEL RELAY With 4x4 Keypad

Hello world! This 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

Follow the next step for the schematic code & Parts list.

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 NoAcces state the Green Led notifys you everything is safe! (Just an idea)

STEP 1: Schematic Code & Parts List.

Wire it up like the Schematic and it should work after uploading the code.

If not...

You need the following Librarys.

Keypad.h

Password.h

Parts list:

  1. Arduino uno, I used the RobotDyn uno.
  2. 4 Channel Relay.
  3. 4x4 Keypad
  4. Jumper wire set MM/FF/MF
  5. buzzer.
  6. 2 x Leds / 1 green / 1 red.

Good luck!

4 Comments

Hi i was wonder if you could help me implement two push buttons into code. Basically the push button bypasses the password and activates relay 1. One push button to activate the relay and the other push button to deactivate the relay.


Push button code:

if (digitalRead(switchPin))

{

digitalWrite(relay1, HIGH);

activated = 2;

}



if (digitalRead(switchPin))

{

digitalWrite(relay1, LOW);


}


Your 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 safery to your garage. Of course it can be used to turn on/off anything.
*/
#include <Keypad.h>
#include <Password.h>

int relay1 = 12;
int external = 11;
int internal = 13;
int noAccess = 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] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
Password password = Password("1234"); // change the access code here

void setup(){
Serial.begin(9600);
pinMode(relay1, OUTPUT);
digitalWrite(relay1, 255);


}

void loop(){

char key = keypad.getKey();
if(noAccess){
if(passinput){
unsigned long currentvarled = millis();
if(currentvarled - flashvarled > flashtimeled) {
flashvarled = currentvarled;

}
}

}
if (key != NO_KEY){
Serial.println(key);
password.append(key);
passinput = 1;
if(key == '*'){
password.reset();
passinput = 0;
noAccess = 1;
digitalWrite(relay1, 1);

}
if(password.evaluate()) {
noAccess = !noAccess;
password.reset();
passinput = 0;
}
if(!noAccess) {
passinput = 0;

switch (key) {
case 'A':
digitalWrite(relay1, !digitalRead(relay1));

break;
}

password.reset();
}
}
}


Works perfect...now, if I can learn more of "how-to-code", I think I can add a little to it. Thanks again, great work!

Given code showing error .

exit status 1

Error compiling for board Arduino/Genuino Uno.

buon giorno ho scaricato lo sketch e ho verificato con arduino ma mi da questo errore:

C:\Users\franco\Desktop\FJVXMJBION6N81E\FJVXMJBION6N81E.ino:41:36: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

Password password = Password("3241"); // change the access code here

come risolvo

grazie mille