Skip to content

Instantly share code, notes, and snippets.

@arn-ob
Last active April 3, 2019 12:25
Show Gist options
  • Save arn-ob/128b9cfe3ad18b6eb301c02516a64d33 to your computer and use it in GitHub Desktop.
Save arn-ob/128b9cfe3ad18b6eb301c02516a64d33 to your computer and use it in GitHub Desktop.
Abeer Working Code
#include <SoftwareSerial.h>
SoftwareSerial BT(5, 4);
String readvoice;
#define fan1 9
#define light1 10
#define light2 11
#define fan2 12
void setup() {
BT.begin(9600);
Serial.begin(9600);
pinMode(fan2, OUTPUT); // fan 2
pinMode(light2, OUTPUT); // Light 2
pinMode(light1, OUTPUT); // Light 1
pinMode(fan1, OUTPUT); // fan 1
digitalWrite(fan2, HIGH);
digitalWrite (light2, HIGH);
digitalWrite(light1, HIGH);
digitalWrite(fan1, HIGH);
}
void loop() {
while (BT.available()) {
//Check if there is an available byte to read
delay(10);
char c = BT.read(); //Conduct a serial read
readvoice += c; //build the string- "forward", "reverse", "left" and "right" }
if (readvoice.length() > 0) {
Serial.println(readvoice);
}
}
Serial.println(readvoice);
if (readvoice == "fan" || readvoice == "FAN") {
digitalWrite(fan1, LOW);
delay(100);
}
if (readvoice == "fan off" || readvoice == "FAN OFF" || readvoice == "FAN OF" || readvoice == "fan of") {
digitalWrite(fan1, HIGH);
delay(100);
}
if (readvoice == "light" || readvoice == "LIGHT") {
digitalWrite(light1, LOW);
delay(100);
}
if (readvoice == "light off" || readvoice == "LIGHT OFF" || readvoice == "light of" || readvoice == "LIGHT OF") {
digitalWrite(light1, HIGH);
delay(100);
}
if (readvoice == "light light" || readvoice == "LIGHT LIGHT") {
digitalWrite (light2, LOW);
delay(100);
}
if (readvoice == "light light off" || readvoice == "LIGHT LIGHT OFF" || readvoice == "light light off" || readvoice == "LIGHT LIGHT OF") {
digitalWrite (light2, HIGH);
delay(100);
}
if (readvoice == "fan fan" || readvoice == "FAN FAN") {
digitalWrite(fan2, LOW);
delay(100);
}
if (readvoice == "fan fan off" || readvoice == "FAN FAN OFF" || readvoice == "fan fan of" || readvoice == "FAN FAN OF") {
digitalWrite(fan2, HIGH);
delay(100);
}
if (readvoice == "all off" || readvoice == "ALL OFF" || readvoice == "all of" || readvoice == "ALL OF") {
digitalWrite(fan2, HIGH);
digitalWrite (light2, HIGH);
digitalWrite(light1, HIGH);
digitalWrite(fan1, HIGH);
delay(100);
}
if (readvoice == "all" || readvoice == "ALL") {
digitalWrite(fan2, LOW);
digitalWrite (light2, LOW);
digitalWrite(light1, LOW);
digitalWrite(fan1, LOW);
delay(100);
}
readvoice = "";
}
//Test
#include <Keypad.h>
#include <SoftwareSerial.h>
const byte ROWS = 4;
const byte COLS = 3;
boolean outs = true;
int LED = 7;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {0, 1, 2, 3};
byte colPins[COLS] = {4, 5, 6};
String password = "123#";
String pass;
String passWorng;
int index_number;
int count = 0;
int mypass = 4;
int arr[10] = { 1, 2, 3, 2, 3, 2, 1, 3, 4, 3};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
const byte rxPin = 10;
const byte txPin = 11;
const int smokepin = 9;
boolean sendSms = false;
int inputPin = 8; // choose the input pin (for PIR sensor)
int val = 0; // variable for reading the pin status
int v = 0;
SoftwareSerial SIM900(rxPin, txPin);
char msg;
int countpress = 0;
void setup() {
// pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
pinMode(LED, OUTPUT);
// put your setup code here, to run once:
Serial.begin(9600);
SIM900.begin(9600);
//Serial.println("Smoke Detector Console");
SIM900.print("AT+CMGF=1\r");
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
// input
pinMode(smokepin, INPUT);
// output
}
void loop() {
char customKey = customKeypad.getKey();
if (outs) {
digitalWrite(LED, HIGH);
} else {
digitalWrite(LED, LOW);
}
if (customKey) {
Serial.println(customKey);
countpress++;
}
pass += String(customKey);
String temp = String(customKey);
if (temp == "1") { //set pass=1 by temp
Serial.println("in Pass ");
Serial.println(pass);
pass = "";
pass = "1";
}
if (countpress == 10) {
Serial.println("To much press");
pass = "";
countpress = 0;
SendMessage("Security Breach");
}
if (password == pass) {
pass = "";
outs = false;
Serial.println("pass");
}
if (customKey) {
passWorng += String(customKey);
if (password == pass) {
Serial.println("wng");
pass = "";
if (outs) {
// SendMessage();
delay(1000);
sendSms = true;
Serial.println("SMS Send");
}
}
}
//-------------------------------------Reset System---------------------------
if (temp == "*") {
outs = true;
pass = "";
countpress = 0;
Serial.println("reset");
sendSms = false;
}
//------------------------------Motion-----------------------------------------
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
Serial.println("Motion detected!");
delay(5000);
if (outs) {
SendMessage("Abnormal Activity");
delay(50);
sendSms = true;
Serial.println("SMS Send");
}
}
//-------------------------------Smoke-----------------------------------------
v = digitalRead(smokepin);
if (!digitalRead(smokepin)) {
if (v == HIGH) {
Serial.println("Smoke is High");
Serial.println("Sms Send");
SendMessage("Smoke alarm");
delay(500);
sendSms = true;
}
} else {
if (v == LOW) {
Serial.println("Smoke is LOW");
sendSms = false;
}
}
}
void SendMessage(String msg)
{
Serial.println("Sending Message ");
Serial.print(msg);
Serial.println(" ");
SIM900.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
SIM900.println("AT+CMGS=\"+8801920871929\"\r"); // Replace x with mobile number
delay(1000);
SIM900.println(msg);// The SMS text you want to send
delay(100);
SIM900.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment