Advertisement
safwan092

SIM GSM

Feb 3rd, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. /*
  2. #include <SoftwareSerial.h>
  3. SoftwareSerial SIM900A(2,3); // RX | TX
  4. // Connect the SIM900A TX to Arduino pin 2 RX.
  5. // Connect the SIM900A RX to Arduino pin 3 TX.
  6. char c = ' ';
  7. void setup()
  8. {
  9. // start th serial communication with the host computer
  10. Serial.begin(9600);
  11. while(!Serial);
  12. Serial.println("Arduino with SIM900A is ready");
  13.  
  14. // start communication with the SIM900A in 9600
  15. SIM900A.begin(9600);
  16. Serial.println("SIM900A started at 9600");
  17. delay(1000);
  18. Serial.println("Setup Complete! SIM900A is Ready!");
  19. }
  20.  
  21. void loop()
  22. {
  23.  
  24. // Keep reading from SIM800 and send to Arduino Serial Monitor
  25. if (SIM900A.available())
  26. { c = SIM900A.read();
  27. Serial.write(c);}
  28.  
  29. // Keep reading from Arduino Serial Monitor and send to SIM900A
  30. if (Serial.available())
  31. { c = Serial.read();
  32. SIM900A.write(c);
  33. }
  34.  
  35. }
  36.  
  37. */
  38. #include <Wire.h>
  39. #include <LiquidCrystal_I2C.h>
  40. #include <SoftwareSerial.h>
  41. LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);
  42. SoftwareSerial SIM900A(10, 11);
  43. int analogValue;
  44. int LED_Pin = 13; // Set up the LED indicator
  45. int Sound_Pin = A0;
  46. int t = 548 ;
  47.  
  48. void setup()
  49. {
  50. SIM900A.begin(9600); // Setting the baud rate of GSM Module
  51. Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
  52. Serial.println ("SIM900A Ready");
  53. delay(100);
  54. Serial.println ("Type s to send message or r to receive message");
  55. pinMode(LED_Pin, OUTPUT);
  56. SendMessage();
  57. lcd.begin();
  58. lcd.backlight();
  59. lcd.clear();
  60. }
  61. void loop()
  62. {
  63. analogValue = analogRead(Sound_Pin);
  64. Serial.println(analogValue);
  65. lcd.setCursor(3, 0);
  66. lcd.print("Sound level ");
  67. lcd.setCursor(8, 1);
  68. lcd.print(analogValue);
  69. delay(50);
  70.  
  71. if (analogValue > t) // If higher than 8 is returned, then change state of boolean "toggle" to true, display analogValue to serial monitor and wait 200ms.
  72. // The higher the value in the above "if" statement, the less sensitive your clapper will be. Use the serial monitor to calibrate to your wanted sensitivity =D
  73. {
  74. SendMessage();
  75. Serial.println(analogValue);
  76. delay(200);
  77. }
  78.  
  79. }
  80. void SendMessage()
  81. {
  82. Serial.println ("Sending Message");
  83. SIM900A.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
  84. delay(1000);
  85. Serial.println ("Set SMS Number");
  86. SIM900A.println("AT+CMGS=\"+966554418546\"\r"); //Mobile phone number to send message
  87. //540538259 SAFWAN 2
  88. //554418546 SAFWAN 1
  89. delay(1000);
  90. Serial.println ("Set SMS Content");
  91. SIM900A.println("Be quiet");// Messsage content
  92. delay(100);
  93. Serial.println ("Finish");
  94. SIM900A.println((char)26);// ASCII code of CTRL+Z
  95. delay(1000);
  96. Serial.println ("Message has been sent ->SMS Selesai dikirim");
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement