All of my previous posts on this forum have been my Automatic Chicken Coop Door project. This is a continuation of that project. Essentially I wanted to have the chicken coop send a message to a hub in the house, telling the hub if it's closed or open. Originally I used a led that would turn on and off and that worked fine, but I decided to do something a little fancier.
For this project I want to display the Chicken Coop Door's state on an LCD, but I also want to create a security system. I have the Arduino Uno attached to a keypad (1,2,3,4,5,6,7,8.9.0,#,*), 2x16 LCD, and a nRF module. Right now I'm struggling to create a menu or some type of layout for the LCD. I want to have different screens. For the time being I'd like to focus on displaying the signal I'm getting from the Chicken Coop, since my motion senor is en route.
So on screen 1 I'd like to have a menu that allows you to go to either the security system's screen or the chicken coop door's screen. ( press * for Coop, and press # for security). After you press * we would go to screen 2, where I'd like to display "the door is" on the top line of the LCD and on the bottom line I'd like to display the Door's state, open/closed.
I don't know how to make the door's state dynamic. I tried to create a function that would spew out a result and include that under screen 2. The problem I'm having is that when I click * I only get to the screen 2 if the Coop Door's Arduino isn't transmitting. When I turn off the chicken coop door and click * I can get to screen 2 and it displays the coop's door as being open. So I have no idea how to display the coop's state live.
Thanks for the Help!
The Keypad pins-
Row pins = 3, 5, 6, 7
Column pins = 8, 9, 10
LCD pins-
A0 - RS
A1 - E
A2 - D4
A3 - D5
A4 - D6
A5 - D7
The rest of the pins are attached to the the 5v pins and ground as necessary.
nRF Pins-
13 - SCK
12 - MISC
11 - MOSI
2 - CE
4 - CS
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
boolean doorState = LOW;
//Radio
int msg[1];
RF24 radio(2, 4);
const uint64_t pipes[2] = {
0xF0F0F0F000LL, 0xF0F0F0F0FFLL
};
//LCD
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
//Keypad
const byte ROWS = 4;
const byte COLS = 3;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {3, 5, 6, 7};
byte colPins[COLS] = {8, 9, 10};
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup() {
radio.begin();
radio.setDataRate(RF24_250KBPS);
radio.setChannel(100);
radio.setRetries(15, 15);
radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1, pipes[1]);
radio.setPALevel(RF24_PA_MAX);
radio.startListening();
//Screen 1
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("* for Coop");
lcd.setCursor(0, 1);
lcd.print("# for Security");
Serial.begin(9600);
}
void loop() {
char customKey = customKeypad.getKey();
if (customKey) {
Serial.println(customKey);
}
//Radio Code
if (radio.available()) {
bool done = false;
while (!done) {
done = radio.read(msg, 1);
if (msg[0] == 111) {
delay(10);
doorState = HIGH;
}
else if (msg[0] == 112) {
doorState = HIGH;
}
}
}
// Screen 2
if (customKey == '*' ) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Door Is ");
CoopDoor();
}
}
void CoopDoor() {
if (doorState = HIGH) {
lcd.setCursor(0, 1);
lcd.print("Open");
delay(1000);
}
else if (doorState = LOW) {
lcd.setCursor(0, 1);
lcd.print("Closed");
delay(1000);
}
}