构建一个基于密码的电源ON/OFF开关电路

描述

在这篇文章中,我们将构建一个基于密码的电源ON/OFF开关电路,只有在输入正确的密码时,它才能打开和关闭交流电源。这可以防止当前可能正在使用高压线路和设备的技术人员触电的危险。

公用电源的密码保护至关重要

对于任何电工或技术人员来说,最大的噩梦是某人意外激活交流线路,这可能会在眨眼间杀死或对身体器官造成致命损害。

这种受密码保护的电源开/关开关电路可防止此类不幸事件,并允许技术人员通过输入正确的密码而不仅仅是翻转杠杆来安全地打开交流电源。

该项目提供了更改存储在Arduino微控制器EEPROM中的密码的功能。

人体甚至动物身体都有自己的电气系统,这有助于将信息从身体的一个部位发送到另一个部位。信息以具有可测量幅度和频率的电信号形式发送。它还有助于收缩和放松肌肉,例如我们的心脏。

有趣的事实:心脏有一个多谐振荡器,称为“SA节点”或“窦房”;控制心率。如果窦房衰竭,我们必须使用起搏器将外部电信号施加到心脏。

我们身体现有电信号的任何激增都会使我们失去对自己身体部位的控制。这就是为什么人们在接触开放的带电电线时会感到卡住和瘫痪的原因。

我们的身体有合理的电阻和良好的电导率。我们知道,任何有电阻的元件在电流通过时都会产生热量。

这也适用于人体;热量会损害器官,并可能导致血液沸腾。如果他/她触电的时间足够长,这个人迟早可能会死。

目前,这已经足够医疗电子产品了。让我们继续讨论技术细节。

该项目由LCD显示屏,4 x 3字母数字键盘,状态LED和继电器组成。

Arduino 和 LCD 连接的原理图:

开关电路

显示器连接到 arduino 的模拟引脚,从 A0 到 A5。显示器异常连接到模拟引脚(其功能与连接到数字引脚相同),因此键盘可以连接到数字引脚(从
2 到 9)。

使用 10 K 欧姆电位计调整显示对比度。

键盘连接:

开关电路

键盘有 8 根电缆,应连接到 Arduino,从引脚 #2 到引脚
#9。键盘最左边的电线必须转到引脚#9,并将键盘的下一个右线连接到引脚#8,7,6,5,4,3,2,键盘的最后一根或最右边的电线必须连接到引脚#2。

其余电气连接:

开关电路

您需要从以下链接下载并添加键盘库:github.com/Chris--A/Keypad 在编译代码之前。

Arduino微控制器的EEPROM最初会存储一些随机值。我们必须重置为零,这样我们的主程序就不会混淆。要将EEPROM值设置为零,请先上传以下程序,然后再上传主程序。

程序代码

重置EEPROM的程序(首先上传):

//------------------Program Developed by R.GIRISH------------------//

#include《EEPROM.h》

int address = -1;

int value = 0;

int i = 0;

int j = 0;

int k = 0;

void setup()

{

Serial.begin(9600);

Serial.println(“Reading EEPROM:”);

for(i = 0; i《10; i++)

{

Serial.println(EEPROM.read(i));

}

Serial.println(“Wrting null value:”);

for(j = 0; j《10; j++)

{

address = address + 1;

EEPROM.write(address, value);

}

for(k = 0; k《10; k++)

{

Serial.println(EEPROM.read(i));

}

Serial.println(“Done!!!”);

}

void loop()

{

// Do nothing here.

}

//------------------Program Developed by R.GIRISH------------------//

Main Program (Upload this second):

//------------------Program Developed by R.GIRISH------------------//

#include 《Keypad.h》

#include《EEPROM.h》

#include《LiquidCrystal.h》

LiquidCrystal lcd(A5, A4, A3, A2, A1, A0);

const int relay = 10;

const int LED = 11;

const byte ROWS = 4;

const byte COLS = 4;

char key1;

char key2;

char key3;

char key4;

char key5;

char key6;

char keyABCD;

char compkey1;

char compkey2;

char compkey3;

char compkey4;

char compkey5;

char compkey6;

int wordAddress1 = 0;

int wordAddress2 = 1;

int wordAddress3 = 2;

int wordAddress4 = 3;

int wordAddress5 = 4;

int wordAddress6 = 5;

int outputStatusAddress = 6;

int outputStatusValue = 0;

int passwordExistAddress = 7;

int passwordExistValue = 0;

int toggleAddress = 8;

int toggleValue = 0;

int check = 0;

char keys[ROWS][COLS] =

{

{‘D’,‘#’,‘0’,‘*’},

{‘C’,‘9’,‘8’,‘7’},

{‘B’,‘6’,‘5’,‘4’},

{‘A’,‘3’,‘2’,‘1’}

};

byte rowPins[ROWS] = {6,7,8,9};

byte colPins[COLS] = {2,3,4,5};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS
);

void setup()

{

lcd.begin(16,2);

pinMode(relay, OUTPUT);

digitalWrite(relay, LOW);

pinMode(LED, OUTPUT);

digitalWrite(LED, LOW);

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“ WELCOME”);

lcd.setCursor(0,1);

lcd.print(“****************”);

delay(2000);

}

void loop()

{

apex:

passwordExistValue = EEPROM.read(passwordExistAddress);

if(passwordExistValue == 1) {goto normal;}

if(passwordExistValue != 1)

{

top:

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Set new 6 digit”);

lcd.setCursor(0,1);

lcd.print(“pin numer:”);

key1 = keypad.waitForKey();

if((key1 == ‘*’) || (key1 == ‘#’) || (key1 == ‘A’) || (key1 == ‘B’) ||
(key1 == ‘C’) || (key1 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto top;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“*”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

key2 = keypad.waitForKey();

if((key2 == ‘*’) || (key2 == ‘#’) || (key2 == ‘A’) || (key2 == ‘B’) ||
(key2 == ‘C’) || (key2 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto top;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“**”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

key3 = keypad.waitForKey();

if((key3 == ‘*’) || (key3 == ‘#’) || (key3 == ‘A’) || (key3 == ‘B’) ||
(key3 == ‘C’) || (key3 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto top;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“***”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

key4 = keypad.waitForKey();

if((key4 == ‘*’) || (key4 == ‘#’) || (key4 == ‘A’) || (key4 == ‘B’) ||
(key4 == ‘C’) || (key4 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto top;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“****”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

key5 = keypad.waitForKey();

if((key5 == ‘*’) || (key5 == ‘#’) || (key5 == ‘A’) || (key5 == ‘B’) ||
(key5 == ‘C’) || (key5 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto top;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“*****”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

key6 = keypad.waitForKey();

if((key6 == ‘*’) || (key6 == ‘#’) || (key6 == ‘A’) || (key6 == ‘B’) ||
(key6 == ‘C’) || (key6 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto top;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“******”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

}

keyABCD = keypad.waitForKey();

if(keyABCD == ‘A’)

{

wrong:

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Re-type PIN NO:”);

lcd.setCursor(0,1);

lcd.print(“----------------”);

compkey1 = keypad.waitForKey();

if((compkey1 == ‘*’) || (compkey1 == ‘#’) || (compkey1 == ‘A’) || (compkey1
== ‘B’) || (compkey1 == ‘C’) || (compkey1 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto wrong;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“*”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

compkey2 = keypad.waitForKey();

if((compkey2 == ‘*’) || (compkey2 == ‘#’) || (compkey2 == ‘A’) || (compkey2
== ‘B’) || (compkey2 == ‘C’) || (compkey2 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto wrong;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“**”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

compkey3 = keypad.waitForKey();

if((compkey3 == ‘*’) || (compkey3 == ‘#’) || (compkey3 == ‘A’) || (compkey3
== ‘B’) || (compkey3 == ‘C’) || (compkey3 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto wrong;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“***”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

compkey4 = keypad.waitForKey();

if((compkey4 == ‘*’) || (compkey4 == ‘#’) || (compkey4 == ‘A’) || (compkey4
== ‘B’) || (compkey4 == ‘C’) || (compkey4 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto wrong;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“****”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

compkey5 = keypad.waitForKey();

if((compkey5 == ‘*’) || (compkey5 == ‘#’) || (compkey5 == ‘A’) || (compkey5
== ‘B’) || (compkey5 == ‘C’) || (compkey5 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto wrong;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“*****”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

compkey6 = keypad.waitForKey();

if((compkey6 == ‘*’) || (compkey6 == ‘#’) || (compkey6 == ‘A’) || (compkey6
== ‘B’) || (compkey6 == ‘C’) || (compkey6 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto wrong;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“******”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

keyABCD = keypad.waitForKey();

if(keyABCD == ‘A’)

{

if(key1 == compkey1)

{

check = check + 1;

}

if(key2 == compkey2)

{

check = check + 1;

}

if(key3 == compkey3)

{

check = check + 1;

}

if(key4 == compkey4)

{

check = check + 1;

}

if(key5 == compkey5)

{

check = check + 1;

}

if(key6 == compkey6)

{

check = check + 1;

}

if(check == 6)

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Password has”);

lcd.setCursor(0,1);

lcd.print(“been saved.”);

delay(2000);

passwordExistValue = 1;

EEPROM.write(passwordExistAddress,passwordExistValue);

EEPROM.write(wordAddress1, key1);

EEPROM.write(wordAddress2, key2);

EEPROM.write(wordAddress3, key3);

EEPROM.write(wordAddress4, key4);

EEPROM.write(wordAddress5, key5);

EEPROM.write(wordAddress6, key6);

if(EEPROM.read(outputStatusAddress) == 1)

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“STATUS:”);

lcd.print(“MAINS ON”);

lcd.setCursor(0,1);

lcd.print(“----------------”);

digitalWrite(LED, HIGH);

digitalWrite(relay, HIGH);

toggleValue = 0;

EEPROM.write(toggleAddress,toggleValue);

}

if(EEPROM.read(outputStatusAddress) == 0)

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“STATUS:”);

lcd.print(“MAINS OFF”);

lcd.setCursor(0,1);

lcd.print(“----------------”);

digitalWrite(LED, LOW);

digitalWrite(relay, LOW);

toggleValue = 1;

EEPROM.write(toggleAddress,toggleValue);

}

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Password”);

lcd.setCursor(0,1);

lcd.print(“Mismatched !!!”);

delay(2000);

goto top;

}

if(keyABCD == ‘B’)

{

goto wrong;

}

}

}

if(keyABCD == ‘B’)

{

goto top;

}

normal:

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“STATUS:”);

if(EEPROM.read(outputStatusAddress) == 1)

{

lcd.print(“MAINS ON”);

lcd.setCursor(0,1);

lcd.print(“----------------”);

digitalWrite(LED, HIGH);

digitalWrite(relay, HIGH);

toggleValue = 0;

EEPROM.write(toggleAddress,toggleValue);

}

if(EEPROM.read(outputStatusAddress) == 0)

{

lcd.print(“MAINS OFF”);

lcd.setCursor(0,1);

lcd.print(“----------------”);

digitalWrite(LED, LOW);

digitalWrite(relay, LOW);

toggleValue = 1;

EEPROM.write(toggleAddress,toggleValue);

}

keyABCD = keypad.waitForKey();

if(keyABCD == ‘C’)

{

pass:

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter current”);

lcd.setCursor(0,1);

lcd.print(“PIN:”);

key1 = keypad.waitForKey();

if((key1 == ‘*’) || (key1 == ‘#’) || (key1 == ‘A’) || (key1 == ‘B’) ||
(key1 == ‘C’) || (key1 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto pass;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“*”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

key2 = keypad.waitForKey();

if((key2 == ‘*’) || (key2 == ‘#’) || (key2 == ‘A’) || (key2 == ‘B’) ||
(key2 == ‘C’) || (key2 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto pass;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“**”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

key3 = keypad.waitForKey();

if((key3 == ‘*’) || (key3 == ‘#’) || (key3 == ‘A’) || (key3 == ‘B’) ||
(key3 == ‘C’) || (key3 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto pass;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“***”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

key4 = keypad.waitForKey();

if((key4 == ‘*’) || (key4 == ‘#’) || (key4 == ‘A’) || (key4 == ‘B’) ||
(key4 == ‘C’) || (key4 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto pass;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“****”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

key5 = keypad.waitForKey();

if((key5 == ‘*’) || (key5 == ‘#’) || (key5 == ‘A’) || (key5 == ‘B’) ||
(key5 == ‘C’) || (key5 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto pass;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“*****”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

key6 = keypad.waitForKey();

if((key6 == ‘*’) || (key6 == ‘#’) || (key6 == ‘A’) || (key6 == ‘B’) ||
(key6 == ‘C’) || (key6 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto pass;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“******”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

keyABCD = keypad.waitForKey();

if(keyABCD == ‘A’)

{

check = 0;

char readkey1 = EEPROM.read(wordAddress1);

char readkey2 = EEPROM.read(wordAddress2);

char readkey3 = EEPROM.read(wordAddress3);

char readkey4 = EEPROM.read(wordAddress4);

char readkey5 = EEPROM.read(wordAddress5);

char readkey6 = EEPROM.read(wordAddress6);

if(key1 == readkey1) {check = check + 1;}

if(key2 == readkey2) {check = check + 1;}

if(key3 == readkey3) {check = check + 1;}

if(key4 == readkey4) {check = check + 1;}

if(key5 == readkey5) {check = check + 1;}

if(key6 == readkey6) {check = check + 1;}

if(check == 6)

{

passwordExistValue = 0;

EEPROM.write(passwordExistAddress,passwordExistValue);

check = 0;

goto apex;

}

else if(check != 6)

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Incorrect”);

lcd.setCursor(0,1);

lcd.print(“Pasword !!!”);

delay(2000);

goto normal;

}

if(keyABCD == ‘B’) {goto normal;}

}

}

if(keyABCD == ‘D’)

{

toggle:

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter the PIN:”);

lcd.setCursor(0,1);

key1 = keypad.waitForKey();

if((key1 == ‘*’) || (key1 == ‘#’) || (key1 == ‘A’) || (key1 == ‘B’) ||
(key1 == ‘C’) || (key1 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto toggle;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“*”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

key2 = keypad.waitForKey();

if((key2 == ‘*’) || (key2 == ‘#’) || (key2 == ‘A’) || (key2 == ‘B’) ||
(key2 == ‘C’) || (key2 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto toggle;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“**”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

key3 = keypad.waitForKey();

if((key3 == ‘*’) || (key3 == ‘#’) || (key3 == ‘A’) || (key3 == ‘B’) ||
(key3 == ‘C’) || (key3 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto toggle;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“***”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

key4 = keypad.waitForKey();

if((key4 == ‘*’) || (key4 == ‘#’) || (key4 == ‘A’) || (key4 == ‘B’) ||
(key4 == ‘C’) || (key4 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto toggle;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“****”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

key5 = keypad.waitForKey();

if((key5 == ‘*’) || (key5 == ‘#’) || (key5 == ‘A’) || (key5 == ‘B’) ||
(key5 == ‘C’) || (key5 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto toggle;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“*****”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

key6 = keypad.waitForKey();

if((key6 == ‘*’) || (key6 == ‘#’) || (key6 == ‘A’) || (key6 == ‘B’) ||
(key6 == ‘C’) || (key6 == ‘D’))

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Enter 6 digit,”);

lcd.setCursor(0,1);

lcd.print(“then press ‘A/B’。”);

delay(2500);

goto toggle;

}

else

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“******”);

lcd.setCursor(0,1);

lcd.print(“YES ‘A’ NO ‘B’”);

}

check = 0;

if(EEPROM.read(wordAddress1) == key1)

{

check = check + 1;

}

if(EEPROM.read(wordAddress2) == key2)

{

check = check + 1;

}

if(EEPROM.read(wordAddress3) == key3)

{

check = check + 1;

}

if(EEPROM.read(wordAddress4) == key4)

{

check = check + 1;

}

if(EEPROM.read(wordAddress5) == key5)

{

check = check + 1;

}

if(EEPROM.read(wordAddress6) == key6)

{

check = check + 1;

}

keyABCD = keypad.waitForKey();

if(keyABCD == ‘B’)

{

goto normal;

}

if(keyABCD == ‘A’)

{

if(check == 6 && EEPROM.read(toggleAddress) == 1)

{

outputStatusValue = 1;

EEPROM.write(outputStatusAddress, outputStatusValue);

goto normal;

}

if(check == 6 && EEPROM.read(toggleAddress) == 0)

{

outputStatusValue = 0;

EEPROM.write(outputStatusAddress, outputStatusValue);

goto normal;

}

if(check != 6)

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“Incorrect”);

lcd.setCursor(0,1);

lcd.print(“Password !!!”);

delay(1500);

goto normal;

}

}

}

}

如何操作此基于密码的电源ON/OFF开关项目:

·完成硬件设置后,上传EEPROM重置代码。

·现在,上传主程序代码。

·它会要求您在LCD上创建6位数字密码(不少于或更多),创建密码并按“ A”。

·再次重新输入密码,然后按“A”。您的密码已保存。

·您可以通过按“C”更改密码。输入当前密码并输入新密码。

·要打开或关闭交流电源,请按“D”并输入密码并按“A”。

按键 A、B、C 和 D 的功能:

A – 输入/是

B – 取消/否

C – 更改密码

D – 切换交流电源

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分