Advertisement
safwan092

Untitled

Nov 23rd, 2023
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #include <Servo.h>
  2. #include <SoftwareSerial.h>
  3. SoftwareSerial SIM900(12, 13);
  4. String incomingData;
  5. String message = "";
  6. Servo myservo;
  7. #include <Keypad.h>
  8. #define sensor 10 //الحساس
  9. int val;
  10. int oldvalue = 1;
  11. const int Password_Length = 4;
  12. String Data;
  13. String Master = "1234";
  14. int lockOutput = 11;
  15. byte data_count = 0;
  16. char customKey;
  17. const byte ROWS = 4;
  18. const byte COLS = 4;
  19.  
  20. char hexaKeys[ROWS][COLS] = {
  21. { '1', '2', '3', 'A' },
  22. { '4', '5', '6', 'B' },
  23. { '7', '8', '9', 'C' },
  24. { '*', '0', '#', 'D' }
  25. };
  26.  
  27. byte rowPins[ROWS] = { 9, 8, 7, 6 };
  28. byte colPins[COLS] = { 5, 4, 3, 2 };
  29. Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
  30.  
  31. void setup() {
  32. myservo.attach(11); //السيرفو
  33. pinMode(sensor, INPUT);
  34. myservo.write(0);
  35. SIM900.begin(9600);
  36. Serial.begin(9600);
  37. }
  38.  
  39. void loop() {
  40.  
  41. val = digitalRead(sensor);
  42. if (val == 0 && oldvalue == 1) {
  43. message = "Test"; //الرساله
  44. send_message(message);
  45. delay(200);
  46. oldvalue = 0;
  47. } else if (val == 1 && oldvalue == 0) {
  48. oldvalue = 1;
  49. }
  50. customKey = customKeypad.getKey();
  51. if (customKey) {
  52. Data += customKey;
  53. data_count++;
  54. }
  55.  
  56.  
  57. if (data_count == Password_Length) {
  58.  
  59. if (Data == Master) {
  60. myservo.write(180);
  61. delay(5000);
  62. myservo.write(0);
  63. } else {
  64. delay(500);
  65. }
  66.  
  67. clearData();
  68. }
  69. }
  70.  
  71. void receive_message() {
  72. if (SIM900.available() > 0) {
  73. incomingData = SIM900.readString();
  74. Serial.print(incomingData);
  75. delay(10);
  76. }
  77. }
  78.  
  79. void send_message(String message) {
  80. Serial.println ("Sending Message");
  81. SIM900.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
  82. delay(1000);
  83. Serial.println ("Set SMS Number");
  84. SIM900.println("AT+CMGS=\"+966567070153\"\r"); //Mobile phone number to send message
  85. delay(1000);
  86. Serial.println ("Set SMS Content");
  87. SIM900.println(message);// Messsage content
  88. delay(100);
  89. Serial.println ("Finish");
  90. SIM900.println((char)26);// ASCII code of CTRL+Z
  91. delay(1000);
  92. }
  93. void clearData() {
  94. data_count = 0;
  95. Data = "";
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement