#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <SoftwareSerial.h>
#include <String.h>
SoftwareSerial mySerial(7, 8);
int fallalert = LOW;
LiquidCrystal lcd(22, 24, 26, 28, 30, 32);
Password password = Password( "4321" );
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3','F'},
{'4','5','6','E'},
{'7','8','9','D'},
{'A','0','B','C'},
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {39, 41, 43, 45}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {31, 33, 35, 37}; //connect to the column pinouts of the keypad
const int buttonPin = 2;
int buttonState = 0;
int count=0;
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
const int ledPin = 13;
void setup(){
pinMode(buttonPin, INPUT);
lcd.begin(16, 2);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // sets the LED OFF
Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
keypad.setDebounceTime(250);
mySerial.begin(19200); // the GPRS baud rate
Serial.begin(19200); // the GPRS baud rate
delay(500);
pinMode(12, INPUT);
}
void loop(){
char key = keypad.getKey();
fallalert = digitalRead(12);
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
lcd.clear();
}
if(fallalert == HIGH)
{
SendTextMessage();
Serial.println("t");
fallalert = LOW;
delay(2000);
}
if (Serial.available())
switch(Serial.read())
{
case 't':
SendTextMessage();
break;
}
if (mySerial.available())
Serial.write(mySerial.read());
}
///SendTextMessage()
///this function is to send a sms message
void SendTextMessage()
{
mySerial.print("AT+CMGF=1\r"); //Because we want to send the SMS in text mode
delay(100);
mySerial.println("AT + CMGS = \"+6583989586\"");//send sms message, be careful need to add a country code before the cellphone number
delay(100);
mySerial.println("SUCCESSFULLY SEND FROM GPRS");//the content of the message
delay(100);
mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
delay(100);
mySerial.println();
}
//take care of some special events
void keypadEvent(KeypadEvent eKey)
{
switch (keypad.getState())
{
case PRESSED:
lcd.print(eKey);
switch (eKey)
{
case 'E': guessPassword(); break;
default:
password.append(eKey);
}
}
}
void guessPassword(){
if (password.evaluate()){
digitalWrite(ledPin,HIGH); //activates garaged door relay
delay(500);
digitalWrite(ledPin,LOW); //turns off door relay after .5 sec
lcd.setCursor(0, 1);
lcd.print("PASS "); //
password.reset(); //resets password after correct entry
delay(1000);
lcd.print("Welcome");
delay(2000);
lcd.clear();
}
else{
digitalWrite(ledPin,LOW);
lcd.setCursor(0, 1);
lcd.print("WRONG ");
password.reset(); //resets password after INCORRECT entry
delay(1000);
lcd.clear();
}
}
My project is use arduino uno and sim900. I want make a keypad control and also need send message.
This my code , if I remove char key = keypad.getKey(); command , sms function can work but the keypad function can not work.