Introduction: Arduino UNO(creating Menus and Functions)

In this instructable we will be exploring how to create menus, read temperature from a TC74A0 sensor and display "values"(in this case cellphone numbers) in a manner which is infinite, but limited to the arduino's on board memory.

We will be using

-Arrays

-Liquid crystal display

-Keypad

User guide included in the final step.

Step 1: Components

Arduino Uno

· 4x4 keypad

· TC74A0 digital temperature sensor

· I2c 16x2 LCD Module

· 16x2 liquid crystal display

· Jumper wires

· Breadboard

· Personal computer

· Arduino IDE

· Transfer cable

Step 2: Component Wiring

TEMP SENSOR AND LCD CONNECTED ON SAME LINE TO SDA AND SCL (A4,A5)

LCD (I2c Module)

o SDA to A5 on Arduino

o SCL to A4 on Arduino

o VCC to 5V on Arduino

o GND to GND on Arduino

· 4 x 4 Keypad

o Pin 1 – 8 on Keypad connected to pin 9 – 2 on Arduino respectively

TC74A0 temp sensor

o TC74A0 pin 2 to SDA on Arduino

o TC74A0 pin 3 to GND on Arduino

o TC74A0 pin 4 to SCL on Arduino

o TC74A0 pin 5 to 5V on Arduino

Step 3: Code

#include //Includes libraries when compiling

#include

#include

#define Password_Lenght 5

#define Command_Lenght 3

#define CellNumber 10

int users = 0;

int Display = 0;

int address= 72; //tc74a0 ADDRESS

int I = 0 ;

int USER ;

int X = 0;

int XY = 0 ;

int temp;

int tempPre = 0;

char userNum[10][10] = {{}, {}, {}};

char Data[Password_Lenght];

char Master[Password_Lenght] = "5466"; //PASSWORD

char ExitData[Command_Lenght]; //

char Master1[Command_Lenght] = "**" ;//

char MenuItem;

char CELLArrayA[10] ;

char CELLArrayB[10] ;

char CELLArrayC[10] ;

const byte ROWS = 4; //four rows

const byte COLS = 4; //four columns

byte rowPins[ROWS] = {5, 4, 3, 2};

byte colPins[COLS] = {9, 8, 7, 6};

byte data_count = 0, master_count = 0;

bool Pass_is_good;

LiquidCrystal_I2C lcd(0x26,16,2);

char hexaKeys[ROWS][COLS] = //INITIATING KEYPAD

{

{'1','2','3','A'},

{'4','5','6','B'},

{'7','8','9','C'},

{'*','0','#','D'}

};

Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup()

{

Serial.begin(9600); //this creates the Serial Monitor

Wire.begin(); //this creates a Wire object

lcd.begin(16,2);

lcd.backlight();

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Please Wait 3"); //LOADING SCREEN

delay(1000);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Please Wait 2");

delay(1000);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Please Wait 1");

delay(300);

lcd.clear();

String myString = "ARDUINO INSTRUCTABLE";

lcd.setCursor(2,2);

lcd.print(myString);

delay(2500);

for(int scrollCounter=0;scrollCounter<24;scrollCounter++)

{

lcd.scrollDisplayLeft();

delay(300);

}

lcd.clear();

lcd.print("Enter Password");

}

void loop()

{

switch(Display) //WHERE IN THE MAIN MENU ARE WE

{ //DID THE USER PRESS A,B,C,D

case 0:

{

Password();

}

break;

case 1:

{

lcd.clear();

lcd.setCursor(0,1);

lcd.print("A B C D");

lcd.setCursor(0,0);

lcd.print("Main Menu");

Display = 2 ;

delay(100);

break;

}

case 2:

{

char customKey = customKeypad.getKey();

switch(customKey)

{

case 'A':

{

Serial.println("A was pressed");

StoreUser();

break;

}

case 'B':

{

Serial.println("B was pressed");

if (users == 0) {

lcd.clear();

lcd.print("NO SAVED USERS");

delay(3000);

lcd.clear();

Display = 1 ;

break;

}

DisplayUsers(); break;

}

case 'C':

{

Serial.println("C was pressed"); //USED DURING TESTING

int ext = 0;

while (!ext) {

char ch;

temp = TempMenu();

if (temp != tempPre) {

lcd.clear();

lcd.print("Temparature");

lcd.setCursor(0, 1);

lcd.print(temp);

lcd.print(" C");

tempPre = temp;

delay(500);

}

ch = customKeypad.getKey();

if (ch == '*') //EXIT TEMPERATURE MENU (if * PRESSED)

{

ext = 1;

lcd.clear();

Display = 1 ;

}

}

break;

TempMenu();

break;

}

case 'D':

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print("NUA PRAC");

lcd.setCursor(0,1);

lcd.print("JB SCHOEMAN");

delay(3000);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("MAY 2019");

lcd.setCursor(0,1);

lcd.print("CC OOSTHUIZEN");

delay(3000);

lcd.clear();

Display = 1 ;

}

}

}

}

}

// CUSTOM FUNCTIONS TO CALL VALUES OR PROCEDURES

void Password()

{

char customKey = customKeypad.getKey();

if (customKey) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)

{

Data[data_count] = customKey; // store char into data array

lcd.setCursor(data_count,1); // move cursor to show each new char

lcd.print("*"); // print char at said cursor

data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered

}

if(data_count == Password_Lenght-1) // if the array index is equal to the number of expected chars, compare data to master

{

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Password is ");

if(!strcmp(Data, Master)) // equal to (strcmp(Data, Master) == 0)

{

lcd.print("Good");

lcd.clear();

Display = 1 ;

}

else

lcd.print("Bad");

delay(1000);// added 1 second delay to make sure the password is completely shown on screen before it gets cleared.

lcd.clear();

clearData();

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Enter Password");

}

}

int TempMenu()

{

Wire.beginTransmission(address);

Wire.write(0);

Wire.endTransmission();

Wire.requestFrom(address, 1);

while (Wire.available() == 0);

int c = Wire.read();

return c;

}

void clearData()

{

while(data_count !=0)

{ // This can be used for any array size,

Data[data_count--] = 0; //clear array for new data

}

}

void StoreUser()

{

int ext = 0;

int user;

char ch;

while (!ext) {

lcd.clear();

lcd.print("Enter User");

user = users + 1;

lcd.print(user);

int x = 0;

while (!x) {

for (int i = 0; i < 10; i++) {

ch = customKeypad.waitForKey();

lcd.setCursor(i, 1);

lcd.print(ch);

userNum[user - 1][i] = ch;

}

delay(500);

lcd.clear();

lcd.print("Continue");

lcd.setCursor(0, 1);

lcd.print("* yes # no");

ch = customKeypad.waitForKey();

if (ch == '*') {

x = 1;

}

if (ch == '#') {

x = 1;

ext = 1;

lcd.clear();

Display = 1 ;

}

}

users++;

}

}

void DisplayUsers()

{

lcd.clear();

for (int i = 0; i < users; i++) {

lcd.print("Saved User");

lcd.print(i + 1);

for (int u = 0; u < 10; u++) {

lcd.setCursor(u, 1);

lcd.print(userNum[i][u]);

}

delay(2000);

lcd.clear();

Display = 1 ;

}

}

Step 4: USER GUIDE

1. Upon switching on the project, a loading or welcome screen will appear.

2. An “Enter Password” screen will appear, this screen allows you to enter 4 characters, letters or numbers, the correct password is: 5466, this will grant you access to the main menu.

3. Upon entering the correct password, the main menu will appear with 4 possible options to navigate the different available functions.

· A – Enter user cell phone numbers.

o Enter 10 digits to save a user to the system

o After 10 digits have been entered press “ * “ to add more users, or press “#” to exit back to the main menu

· B – Display saved users

o The users will scroll past the screen, they are displayed for 3 seconds each, as soon as all users are displayed the page will close and return to the main menu.

o If no users were added in menu option A, it will display “ NO SAVED USERS”.

· C – Displays live temperature

o Press “ * “ to exit back to main menu

· D – Display short text

o Displays the creator’s name and the subject it was compiled for with a date.