Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- #include <SoftwareSerial.h>
- SoftwareSerial SIM900(12, 13);
- String incomingData;
- String message = "";
- Servo myservo;
- #include <Keypad.h>
- #define sensor 10 //الحساس
- int val;
- int oldvalue = 1;
- const int Password_Length = 4;
- String Data;
- String Master = "1234";
- int lockOutput = 11;
- byte data_count = 0;
- char customKey;
- const byte ROWS = 4;
- const byte COLS = 4;
- char hexaKeys[ROWS][COLS] = {
- { '1', '2', '3', 'A' },
- { '4', '5', '6', 'B' },
- { '7', '8', '9', 'C' },
- { '*', '0', '#', 'D' }
- };
- byte rowPins[ROWS] = { 9, 8, 7, 6 };
- byte colPins[COLS] = { 5, 4, 3, 2 };
- Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
- void setup() {
- myservo.attach(11); //السيرفو
- pinMode(sensor, INPUT);
- myservo.write(0);
- SIM900.begin(9600);
- Serial.begin(9600);
- }
- void loop() {
- val = digitalRead(sensor);
- if (val == 0 && oldvalue == 1) {
- message = "Test"; //الرساله
- send_message(message);
- delay(200);
- oldvalue = 0;
- } else if (val == 1 && oldvalue == 0) {
- oldvalue = 1;
- }
- customKey = customKeypad.getKey();
- if (customKey) {
- Data += customKey;
- data_count++;
- }
- if (data_count == Password_Length) {
- if (Data == Master) {
- myservo.write(180);
- delay(5000);
- myservo.write(0);
- } else {
- delay(500);
- }
- clearData();
- }
- }
- void receive_message() {
- if (SIM900.available() > 0) {
- incomingData = SIM900.readString();
- Serial.print(incomingData);
- delay(10);
- }
- }
- void send_message(String message) {
- Serial.println ("Sending Message");
- SIM900.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
- delay(1000);
- Serial.println ("Set SMS Number");
- SIM900.println("AT+CMGS=\"+966567070153\"\r"); //Mobile phone number to send message
- delay(1000);
- Serial.println ("Set SMS Content");
- SIM900.println(message);// Messsage content
- delay(100);
- Serial.println ("Finish");
- SIM900.println((char)26);// ASCII code of CTRL+Z
- delay(1000);
- }
- void clearData() {
- data_count = 0;
- Data = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement