mikroavr

sim800_sms

Jun 16th, 2021
765
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Sim800l.h"
  2. Sim800l Sim800l;
  3.  
  4. #define RST 4
  5. #define SEN 8
  6. bool hold = false;
  7. bool dt_sensor;
  8. unsigned cur_time, old_time;
  9.  
  10. void setup() {
  11.   // put your setup code here, to run once:
  12.   pinMode(RST, OUTPUT);
  13.   pinMode(SEN,INPUT_PULLUP);
  14.   digitalWrite(RST, LOW); delay(1000);
  15.   digitalWrite(RST, HIGH); delay(1000);
  16.  
  17.   Serial.begin(115200);
  18.   Sim800l.begin();
  19.   delay(10000);
  20.   //Sim800l.sendSms("081263920524", "system bekerja dengan baik");
  21.   Serial.println("system mulai");
  22. }
  23.  
  24. void loop() {
  25.   // put your main code here, to run repeatedly:
  26.   cur_time = millis();
  27.   if(cur_time - old_time >= 1000){
  28.     baca_sensor();
  29.     Sim800l.signalQuality();
  30.     old_time = cur_time;
  31.   }
  32. }
  33.  
  34. void baca_sensor(){
  35.   dt_sensor = digitalRead(SEN);
  36.   Serial.print("sensor= ");
  37.   Serial.println(dt_sensor);
  38.  
  39.   if(dt_sensor == true){
  40.     if(hold == false){
  41.     hold = true;
  42.     kirim_sms();
  43.     }
  44.   }else{
  45.     hold = false;
  46.   }
  47. }
  48.  
  49. void kirim_sms(){
  50.   Serial.println("kirim sms");
  51.   Sim800l.sendSms("081263920524", "Ada tindakan pencurian,\n SEGERA CHECK!!!");
  52.   delay(3000);
  53. }
RAW Paste Data