2

*****1st code

int sensoroutput = 3; // the analog pin connected to the sensor
int sensorinput = A0;
int THRESHOLD = 100;

void setup() { pinMode(3, OUTPUT); pinMode(A0, INPUT); // this function is used to declare gsm connected pin as output }

void loop() { int value = analogRead(sensorinput); // function to read analog voltage from sensor if (value >= THRESHOLD) // function to check voltage level from sensor { digitalWrite(3, HIGH); delay(100); } else digitalWrite(3, LOW); }

2nd code****

#include <SoftwareSerial.h>

SoftwareSerial sim800l(0, 1); // RX,TX for Arduino and for the module it's TXD RXD, they should be inverted

#define button1 7 //Button pin, on the other pin it's wired with GND

bool button_State; //Button state

void setup() { pinMode(button1, INPUT_PULLUP); //The button is always on HIGH level, when pressed it goes LOW sim800l.begin(9600); //Module baude rate, this is on max, it depends on the version Serial.begin(9600); delay(1000); }

void loop() { button_State = digitalRead(button1); //We are constantly reading the button State

if (button_State == LOW) {            //And if it's pressed
    Serial.println(&quot;Button pressed&quot;);   //Shows this message on the serial monitor
    delay(200);                         //Small delay to avoid detecting the button press many times

    SendSMS();                          //And this function is called
}

if (sim800l.available()) {            //Displays on the serial monitor if there's a communication from the module
    Serial.write(sim800l.read());
}

}

void SendSMS() { Serial.println("Sending SMS..."); //Show this message on serial monitor sim800l.print("AT+CMGF=1\r"); //Set the module to SMS mode delay(100); sim800l.print("AT+CMGS=&quot;+918707578617&quot;\r"); //Your phone number don't forget to include your country code, example +212123456789" delay(500); sim800l.print("SIM800l is working"); //This is the text to send to the phone number, don't make it too long or you have to modify the SoftwareSerial buffer delay(500); sim800l.print((char)26);// (required according to the datasheet) delay(500); sim800l.println(); Serial.println("Text Sent."); delay(500);

}

tim
  • 699
  • 6
  • 15

0 Answers0