please I need a program using Arduino IDE by impliminting the uno board: EEPROM
ID: 3752336 • Letter: P
Question
please I need a program using Arduino IDE by impliminting the uno board:
EEPROM Password
• On power-up, check to see if the EEPROM has a specific value (e.g., 128) at a specific address (e.g., address 0 of EEPROM)
• If so, then this is NOT the first time powered up – prompt the user for a 4 or more digit/character password and compare that password to the stored password. (can use ‘char’ or “string” for password)
• If they match, enter loop() and notify user of success
• If this is the first time powered up, as indicated by the specific value not being present in EEPROM, prompt user to enter a 4 or more digit/character password, store it, mark as NOT first time run
•You also want a method to reset the system, e.g., by pressing a button
Read and Write EEPROM
• Connecting the Uno board to the laptop
• Find out how many addresses are available on the EEPROM of Arduino Uno
• Check (and display using serial monitor) the values at address 10—20 of the EEPROM, one pair of per line
• Change these values to {0, 1, 2, ..., 10} and display them
•Change these values to 256(?)
using these commands
•EEPROM.read()
•EEPROM.write()
•EEPROM.length()
•Serial.begin()
•Serial.print()
•Serial.println()
Explanation / Answer
#include <EEPROM.h>
#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Servo.h>
//EEPROM
int address = 0;
byte value;
Servo myservo;
//constants for LEDs
int greenLED = 22;
int redLED = 23;
LiquidCrystal lcd(13, 12, 11, 10, 9, 8, 7);
Password password = Password( "4155" );
int currentPosition = 0; //servo
//keypad part
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
// Define the Keymap
char keys[ROWS][COLS] = {
{
'1','2','3','A', }
,
{
'4','5','6','B', }
,
{
'7','8','9','C', }
,
{
'*','0','#','D', }
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {
47, 46, 45, 44}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
51, 50, 49, 48}; //connect to the column pinouts of the keypad
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
lcd.begin(16, 2);
Serial.begin(9600);
keypad.setDebounceTime(50);
displayCodeEntryScreen();
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
//setup and turn off both LEDs
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, LOW);
}
void displayCodeEntryScreen(){
password.reset();
lcd.clear();
lcd.print("Enter Password:");
lcd.setCursor(0,1);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
//setup and turn off both LEDs
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, LOW);
}
void loop(){
keypad.getKey();
value = EEPROM.read(address);
}
//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
lcd.print(eKey);
switch (eKey){
case '#':
checkPassword();
break;
case 'C':
changepassword();
break;
case 'D':
lockdoor();
break;
case '*':
displayCodeEntryScreen(); break;
default:
password.append(eKey);
}
}
}
void checkPassword(){ //checks if the password is correct
if (password.evaluate()){
digitalWrite(greenLED, HIGH);
lcd.clear();
delay(30);
lcd.setCursor(1, 0);
lcd.print("Acces Granted");
lcd.setCursor(4, 1);
lcd.print("Welcome");
unlockdoor();
delay(2500);
displayCodeEntryScreen();
}
else{
loop(); {
redlight();
}
lcd.clear();
delay(10);
lcd.setCursor(2, 0);
lcd.print("Acces Denied");
delay(2500);
lcd.clear();
displayCodeEntryScreen();
}
}
void unlockdoor(){ //controls servo that locks the door
myservo.attach(2);
myservo.write(90);
digitalWrite(greenLED, HIGH);
delay(5000);
myservo.detach();
}
void redlight(){ //flashes the red LED when password is wrong
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
delay(100);
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
delay(100);
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
delay(100);
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
delay(100);
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
delay(100);
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
delay(100);
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
delay(100);
digitalWrite(redLED, HIGH);
delay(100);
}
void changepassword() {
if (password.evaluate()){
lcd.print("Enter New");
lcd.setCursor(0, 1);
lcd.print("Password:");
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("Password");
lcd.setCursor(4, 1);
lcd.print("Changed");
delay(3000);
}
else{
loop(); {
redlight();
}
lcd.clear();
delay(10);
lcd.print("Wrong Password");
delay(2500);
lcd.clear();
displayCodeEntryScreen();
}
}
void lockdoor(){ //locks the door again
myservo.attach(2);
myservo.write(180);
delay(2000);
myservo.detach();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.