Advertisement
safwan092

Untitled

May 11th, 2022
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. /*
  2. #include <SoftwareSerial.h>
  3. SoftwareSerial SIM900A(10,11); // 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.  
  39. #include <SoftwareSerial.h>
  40. SoftwareSerial SIM900A(10,11);
  41. void setup()
  42. {
  43. SIM900A.begin(9600); // Setting the baud rate of GSM Module
  44. Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
  45. Serial.println ("SIM900A Ready");
  46. delay(100);
  47. Serial.println ("Type s to send message or r to receive message");
  48. delay(15000);
  49. SendMessage();
  50. }
  51. void loop()
  52. {
  53. /*
  54. if (Serial.available()>0)
  55. switch(Serial.read())
  56. {
  57. case 's':
  58. SendMessage();
  59. break;
  60. case 'r':
  61. // RecieveMessage();
  62. break;
  63. }
  64. */
  65. if (SIM900A.available()>0)
  66. Serial.write(SIM900A.read());
  67.  
  68. }
  69. void SendMessage()
  70. {
  71. Serial.println ("Sending Message");
  72. SIM900A.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
  73. delay(1000);
  74. Serial.println ("Set SMS Number");
  75. // *********
  76. SIM900A.println("AT+CMGS=\"+966*********\"\r"); //Mobile phone number to send message
  77. delay(1000);
  78. Serial.println ("Set SMS Content");
  79. SIM900A.println("Good 123?");// Messsage content
  80. delay(100);
  81. Serial.println ("Finish");
  82. SIM900A.println((char)26);// ASCII code of CTRL+Z
  83. delay(1000);
  84. Serial.println ("Message has been sent ->SMS Selesai dikirim");
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement