Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- SoftwareSerial SIM900A(8, 7);
- // Define the pin numbers for push button and LED
- const int buttonPin = 2; // Change this to your button pin
- const int ledPin = 13; // Change this to your LED pin
- // Variables to store button state and timing
- int buttonState = 0;
- unsigned long buttonPressTime = 0;
- bool ledOn = false;
- bool buttonReleased = false;
- int sit_time = 15;
- int XX = 3;
- void setup() {
- pinMode(buttonPin, INPUT_PULLUP); // Use internal pull-up resistor for the button
- pinMode(ledPin, OUTPUT);
- SIM900A.begin(115200); // Setting the baud rate of GSM Module
- Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
- Serial.println ("SIM900A Ready");
- delay(100);
- Serial.println ("Type s to send message or r to receive message");
- delay(15000);
- SendMessage();
- }
- void loop() {
- sit_time = 15; // Reset sit_time
- while (digitalRead(buttonPin) == HIGH && sit_time != 0) {
- // Decrement sit_time
- sit_time--;
- delay(1000);
- while (digitalRead(buttonPin) == LOW) {
- XX--;
- delay(1000);
- }
- }
- if (sit_time == 0) {
- digitalWrite(ledPin, HIGH); // Turn on LED
- delay(2000); // Delay for 2 seconds
- digitalWrite(ledPin, LOW); // Turn off LED
- SendMessage();
- sit_time = 15; // Reset sit_time
- return;
- }
- if (digitalRead(buttonPin) == LOW) {
- return;
- // Check if button is pressed during the countdown
- }
- }
- void SendMessage()
- {
- Serial.println ("Sending Message");
- SIM900A.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
- delay(1000);
- Serial.println ("Set SMS Number");
- SIM900A.println("AT+CMGS=\"+966580224645\"\r"); //Mobile phone number to send message
- //540538259 SAFWAN 2
- //554418546 SAFWAN 1
- delay(1000);
- Serial.println ("Set SMS Content");
- SIM900A.println("Good 123?");// Messsage content
- delay(100);
- Serial.println ("Finish");
- SIM900A.println((char)26);// ASCII code of CTRL+Z
- delay(1000);
- Serial.println ("Message has been sent ->SMS Selesai dikirim");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement