0% found this document useful (0 votes)
64 views

Submitt Ed By: Student ID: Subject: ECE2551

This lab report describes creating a simple token authentication device using an Arduino, LCD display, and button. The device generates random numbers between 10000-100000, stores them in EEPROM addresses, and displays the number from the current address when the button is pressed. It initializes the LCD and button pins, writes random numbers to EEPROM every 10 seconds, reads and displays the number from the current address when the button is pressed, and can clear the EEPROM contents.

Uploaded by

GhulamMahyyudin
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Submitt Ed By: Student ID: Subject: ECE2551

This lab report describes creating a simple token authentication device using an Arduino, LCD display, and button. The device generates random numbers between 10000-100000, stores them in EEPROM addresses, and displays the number from the current address when the button is pressed. It initializes the LCD and button pins, writes random numbers to EEPROM every 10 seconds, reads and displays the number from the current address when the button is pressed, and can clear the EEPROM contents.

Uploaded by

GhulamMahyyudin
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Lab – 2

Submitt ed By:
Student ID:
Subject: ECE2551
Table of Contents
List of Figures............................................................................................................................................2
Objective:..................................................................................................................................................3
Learning Outcomes:..................................................................................................................................3
Equipment:...............................................................................................................................................3
Introduction:.............................................................................................................................................3
Description:...............................................................................................................................................5
Procedure:................................................................................................................................................5
Analysis and Discussion:............................................................................................................................5
Conclusion:...............................................................................................................................................6
References................................................................................................................................................6
Appendix A................................................................................................................................................7

List of Figures
Figure 1: EEPROM memory on the microcontroller in Arduino................................................................3
Figure 2: an LCD display............................................................................................................................4
Figure 3: Schematic...................................................................................................................................5

2
Objective:
 The ultimate purpose of this activity is to construct a very simple token device for
authentication.
 This interface is composed of an Arduino framework with an LCD panel and a click button.
 It produces code for authentication at set intervals and displays it after pressing the pushbutton.

Learning Outcomes:
 Able to interface LCD with Arduino.
 Learn to generate an authentication token.
 Interface the pushbutton with Arduino.
 Read data from EEPROM.
 Write data to EEPROM.

Equipment:
In this lab, we need the following hardware.

 1 Button
 A computer
 Arduino UNO, Breadboard and wires

Introduction:
EEPROM:
Electrically erasable Read-only memory (EEPROM) is a sort of memory that holds its values even if a
microcontroller is disabled. A microcontroller in its heart relies on the amount of EEPROM on an Arduino
surface.

Figure 1: EEPROM memory on microcontrollers used on Arduino boards.

EEPROM's survival is infinite. In Arduino, the EEPROM is set to manage any role for 100,000 writes/erase
cycles. The readings, though, are infinite. You will thus read EEPROM as many times as you want without
endangering the life expectancy.

Write in EEPROM:
The EEPROM.write() is used to write data, which requires two arguments, to transfer data to the
EEPROM. The first is the EEPROM location, and the second is the value we want to save:

3
Read from EEPROM:
The EEPROM.read() is used to read a byte from the EEPROM. This function takes an argument to the
address of the byte.

LCD:
The LCD comprises the Order and Data registers. The LCD command instructions can be stored in the
registry command. A command is an instruction for LCD to execute a predefined task such as start, clear
its screen, cursor location, monitor power, etc. The data registry saves the data on the LCD. The data is
the ASCII value of the LCD-shown character. 

Figure 2: an LCD display.

Description:
In this task, we connect the LCD with the Arduino and make a token generating device. When the device
turns on, it will generate ten numbers between 10000. These numbers are stored in EEPROM. A timer is

4
added. After every ten seconds, a new number will be taken from EEPROM. The number only displays
for three seconds when the button is pressed.

Figure 3: Schematic

Procedure:
 Connect the LCD and button with Arduino.
 Upload the code in the Arduino.

Analysis and Discussion


 In the coding, we start by adding the necessary libraries for the LCD display. Also adding a
library for accessing the EEPROM.

 Initializing pin number of the LCD and button, which is used to print the token when
required.
 Creating void loops for Write the EEPROM, Read the EEPROM, and Erase the EEPROM.
 In void setup, the Serial Monitor is activated and set the LCD.
 In the Void loop, we call the write function to generate the Random number and store in
EEPROM.
 When the button is pressed, the Read function will be called, and it will access the desired
location and show the value for 3 seconds. See coding in the appendix.

Conclusion:
In this lab, we learned about saving data in EEPROM and technique to generate random data. Also, we
learned to print the data from EEPROM when the button is being pressed. The LCD is easy to use. And
the function of EEPROM is very useful for many industrial aspects.

5
References:
Clary, M., 2015. Interfacing an LCD Screen Using an Arduino.

Evans, B., 2011. Beginning Arduino Programming (Vol. 6). New York, NY, USA:: Apress.

Kurniawan, A., 2015. Arduino Uno: A Hands-On Guide for Beginner. PE Press.

Monk, S., 2018. Programming Arduino next steps: going further with sketches. McGraw-Hill Education.

6
Appendix A

#include <EEPROM.h>
#include <LiquidCrystal.h>
#include <limits.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#define SAMPLE_TIME 2000 //The time between each EEPROM write function call in ms
const unsigned short EEPROM_START_ADDRESS = 0;
const unsigned short MAX = USHRT_MAX;
const unsigned short MIN = 10000;
long randNumber;
int press = 0;
int printPin = 1; //show on lcd
int erasePin = 5; //the erase button pin
int address = 0; //EEPROM address counter

unsigned long timer;

void clearEEPROM();
void writeT();
void readT();

void setup(){
Serial.begin(115200); //start the serial connection as always
timer = millis(); //millis() returns the time since program start in ms
lcd.begin(16,2);
}

void loop(){
writeT();
timer = millis();
lcd.clear();
press=digitalRead(printPin);
if (press==HIGH)
{
readT();

7
}

if(!digitalRead(erasePin)) //check if erase button is pressed


{
clearEEPROM();
delay(500);
}

delay(1);
}

void clearEEPROM()
{
for (int i = 0 ; i < EEPROM.length() ; i++) {
if(EEPROM.read(i) != 0) //skip already "empty" addresses
{
EEPROM.write(i, 0); //write 0 to address i
}
}
Serial.println("EEPROM erased");
address = 0; //reset address counter
}

void writeT()
{

randNumber = random(10000, 100000);

EEPROM.write(address, randNumber); //write value to current address counter address


Serial.print(randNumber);
Serial.print(" is stored at adress ");
Serial.println(address);
address++; //increment address counter

if(address == EEPROM.length()) //check if address counter has reached the end of EEPROM
{
address = 0; //if yes: reset address counter
}
}

void readT()

8
{

EEPROM.read(address); //write value to current address counter address


Serial.print(randNumber);
Serial.print(" is stored at adress ");
Serial.println(address);
lcd.setCursor(1,1);
lcd.print("Hardware Token");
lcd.setCursor(2,1);
lcd.print(randNumber);
delay(3000);
lcd.clear();
address++; //increment address counter
if(address == EEPROM.length()) //check if address counter has reached the end of EEPROM
{
address = 0; //if yes: reset address counter
}
}

You might also like