///////////
const int pushButton[] ={46,45,47,53,51,49,50,48};// define push button inputs
const int relayPin[]={29,31,33,35,37,39,41,43};// output pins where 8 relays will be connected
String relayNames[] ={"CH1", "CH2","CH3","CH4","CH5", "CH6","CH7","CH8"};// Just put name for 8 relays
int pushed[] ={0,0,0,0,0,0,0,0};// status of each buttons
int relayStatus[] ={HIGH,HIGH,HIGH,HIGH,HIGH,HIGH,HIGH,HIGH};// initial status of relay
///////////////
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Servo.h>
#define Password_Length 5
Servo myservo;
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
int pos = 0;
char Data[Password_Length];
char Master[Password_Length] = "1234";
byte data_count = 0, master_count = 0;
bool Pass_is_good;
bool door = false;
char customKey;
/*---preparing keypad---*/
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {0, 1, 2, 3};
byte colPins[COLS] = {4, 5, 6, 7};
Keypad customKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
//////////////// dht temperature et hymidite/////////
#include <DHT.h>
#define DHTPIN 16
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
const int relay = 18;
//////////////////////ir remote//////////////////
#include <IRremote.h>
#include <Servo.h>
#include <FastLED.h>
CRGB leds[0];
int pin_receiver = 14;
int button_value = 21;
int bright = 20;
Servo myservo2;
Servo myservo1;
IRrecv receiver(pin_receiver);
//////////////////////pho
const int photordo = 17;
const int ledPin = 25;
int buttonState = 0;
///////////////////////// sensor // detecteur de mouvement
const int LED = 27;
const int motionSensor = 15;
/*--- Main Action ---*/
void setup()
{///////////////
// ofppt.2023 8-Relay-8-Push button MOM2023
for(int i=0; i<8; i++)
{
pinMode(pushButton[i], INPUT_PULLUP);
pinMode(relayPin[i], OUTPUT);
digitalWrite(relayPin[i], HIGH);// initial relay status to be OFF
}
// ofppt.2023 8-Relay-8-Push button MOM2023
/////////////////////ir remote///////
receiver.enableIRIn();
myservo1.attach(12);
myservo2.attach(13);
Serial.begin(9600);
FastLED.addLeds<NEOPIXEL, 19>(leds, 1);
//////////sensor////////////////////////mouvement/////////////
pinMode(LED, OUTPUT);
pinMode(motionSensor, INPUT);
///////////////////////////DHT////
dht.begin();
pinMode(relay, OUTPUT);
////////////////////// photo/////
pinMode(ledPin, OUTPUT);
pinMode(photordo, INPUT);
myservo.attach(11, 2000, 2400);
ServoClose();
lcd.begin(16, 2);
lcd.print("Protected Door");
loading("Loading");
lcd.clear();
}
/////////////remote led past//////
void translateIR()
{
button_value = receiver.decodedIRData.command;
if(button_value == 226)
{
Serial.println("Forward - Driver Door opens, Backward - Driver Door Close, 1 - Lights ON in RED, 2 - Lights ON in Green, 3 - LIGHTS ON in Blue Color, 4 - Blinking LED, Play - Control LED Glow, 9 - All stops");
}
if(button_value == 224)
{
myservo1.write(0);
myservo2.write(0);
Serial.println("Door Closed");
}
if(button_value == 144)
{
myservo1.write(180);
myservo2.write(180);
Serial.println("Door Open");
}
if(button_value == 48)
{
leds[1] = CRGB::Red;
FastLED.show();
}
if(button_value == 24)
{
leds[1] = CRGB::Green;
FastLED.show();
}
if(button_value == 122)
{
leds[1] = CRGB::Blue;
FastLED.show();
}
if(button_value == 16)
{
for (int i = 0; i<=20; i++)
{
leds[1] = CRGB(0, 255, 221);
FastLED.show();
delay(50);
leds[1] = CRGB(233, 255, 34);
FastLED.show();
delay(50);
leds[1] = CRGB(255, 0, 191);
FastLED.show();
delay(50);
}
}
if (button_value == 168)
{
bright = bright + 40;
FastLED.setBrightness(bright);
FastLED.show();
}
if(button_value == 162)
{
Serial.println("Application Stopped");
myservo1.write(90);
myservo2.write(90);
FastLED.clear();
FastLED.show();
}
}
void loop(){
/////////////////// puch////////////
// ofppt.2023 4-Relay-4-Push button MOM2023
for(int i=0; i<8; i++)
{
int val = digitalRead(pushButton[i]);
if(val == HIGH && relayStatus[i] == LOW){
pushed[i] = 1-pushed[i];
delay(100);
}// if
relayStatus[i] = val;
if(pushed[i] == HIGH){
Serial.print(relayNames[i]);
Serial.println(" ON");
digitalWrite(relayPin[i], LOW);
}else{
Serial.print(relayNames[i]);
Serial.println(" OFF");
digitalWrite(relayPin[i], HIGH);
}// else
}// for
Serial.println("==");
delay(100);
// ofppt.2023 8-Relay-8-Push button MOM2023
////////////ir remote /////////////
if (receiver.decode())
{
translateIR();
receiver.resume();
}
/////////////////////////pho///////
buttonState = digitalRead(photordo);
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
/////////////////////sensor mouvement
int sensorValue = digitalRead(motionSensor);
if (sensorValue == HIGH) {
digitalWrite(LED, HIGH);
} else {
digitalWrite(LED, LOW);
}
////////////////////////////DHT//////////
float suhu = dht.readTemperature(); //menghitung suhu
if(suhu > 30){
digitalWrite(relay, HIGH);
}else{
digitalWrite(relay, LOW);
}
delay(10);
/////////////////////////////
if (door == true)
{
customKey = customKeypad.getKey();
if (customKey == '#')
{
lcd.clear();
ServoClose();
lcd.print("Door is closed");
delay(3000);
door = false;
}
}
else
Open();
}
void loading (char msg[]) {
lcd.setCursor(0, 1);
lcd.print(msg);
for (int i = 0; i < 9; i++) {
delay(500);
lcd.print(".");
}
}
void clearData()
{
while (data_count != 0)
{
Data[data_count--] = 0;
}
return;
}
void ServoClose()
{
for (pos = 90; pos >= 0; pos -= 10) {
myservo.write(pos);
}
}
void ServoOpen()
{
for (pos = 0; pos <= 90; pos += 10) {
myservo.write(pos);
}
}
void Open()
{
lcd.setCursor(0, 0);
lcd.print("Enter Password");
customKey = customKeypad.getKey();
if (customKey)
{
Data[data_count] = customKey;
lcd.setCursor(data_count, 1);
lcd.print(Data[data_count]);
data_count++;
}
if (data_count == Password_Length - 1)
{
if (!strcmp(Data, Master))
{
lcd.clear();
ServoOpen();
lcd.print(" Door is Open ");
door = true;
delay(5000);
loading("Waiting");
lcd.clear();
lcd.print(" Time is up! ");
delay(1000);
ServoClose();
door = false;
}
else
{
lcd.clear();
lcd.print(" Wrong Password ");
door = false;
}
delay(1000);
lcd.clear();
clearData();
}
}