Advertisement
safwan092

Untitled

Apr 24th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2. SoftwareSerial SIM900A(8, 7);
  3. // Define the pin numbers for push button and LED
  4. const int buttonPin = 2; // Change this to your button pin
  5. const int ledPin = 13; // Change this to your LED pin
  6.  
  7. // Variables to store button state and timing
  8. int buttonState = 0;
  9. unsigned long buttonPressTime = 0;
  10. bool ledOn = false;
  11. bool buttonReleased = false;
  12. int sit_time = 15;
  13. int XX = 3;
  14.  
  15. void setup() {
  16. pinMode(buttonPin, INPUT_PULLUP); // Use internal pull-up resistor for the button
  17. pinMode(ledPin, OUTPUT);
  18. SIM900A.begin(115200); // Setting the baud rate of GSM Module
  19. Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
  20. Serial.println ("SIM900A Ready");
  21. delay(100);
  22. Serial.println ("Type s to send message or r to receive message");
  23. delay(15000);
  24. SendMessage();
  25. }
  26.  
  27. void loop() {
  28. sit_time = 15; // Reset sit_time
  29. while (digitalRead(buttonPin) == HIGH && sit_time != 0) {
  30. // Decrement sit_time
  31. sit_time--;
  32.  
  33. delay(1000);
  34. while (digitalRead(buttonPin) == LOW) {
  35. XX--;
  36. delay(1000);
  37. }
  38. }
  39.  
  40. if (sit_time == 0) {
  41. digitalWrite(ledPin, HIGH); // Turn on LED
  42. delay(2000); // Delay for 2 seconds
  43. digitalWrite(ledPin, LOW); // Turn off LED
  44. SendMessage();
  45. sit_time = 15; // Reset sit_time
  46. return;
  47. }
  48. if (digitalRead(buttonPin) == LOW) {
  49. return;
  50. // Check if button is pressed during the countdown
  51.  
  52. }
  53. }
  54.  
  55.  
  56. void SendMessage()
  57. {
  58. Serial.println ("Sending Message");
  59. SIM900A.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
  60. delay(1000);
  61. Serial.println ("Set SMS Number");
  62. SIM900A.println("AT+CMGS=\"+966580224645\"\r"); //Mobile phone number to send message
  63. //540538259 SAFWAN 2
  64. //554418546 SAFWAN 1
  65. delay(1000);
  66. Serial.println ("Set SMS Content");
  67. SIM900A.println("Good 123?");// Messsage content
  68. delay(100);
  69. Serial.println ("Finish");
  70. SIM900A.println((char)26);// ASCII code of CTRL+Z
  71. delay(1000);
  72. Serial.println ("Message has been sent ->SMS Selesai dikirim");
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement