Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //SIM800L
- // tx pin 2
- // rx pin 3
- //Relay pin 4
- // Include the GSM library
- #include <GSM.h>
- GSM_SMS sms;
- boolean allarme = 1;
- boolean presenza = 0;
- // PIN Number
- #define PINNUMBER ""
- // initialize the library instance
- GSM gsmAccess;
- GSMVoiceCall vcs;
- // Array to hold the number for the incoming call
- char numtel[20];
- int rel1 = 4;
- void setup() {
- // initialize serial communications and wait for port to open:
- Serial.begin(9600);
- pinMode(10, INPUT_PULLUP);
- pinMode(13, OUTPUT);
- digitalWrite(13, LOW);
- while (!Serial) {
- ; // wait for serial port to connect. Needed for native USB port only
- }
- Serial.println("Receive Voice Call");
- // connection state
- boolean notConnected = true;
- // Start GSM shield
- // If your SIM has PIN, pass it as a parameter of begin() in quotes
- while (notConnected) {
- if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
- notConnected = false;
- } else {
- Serial.println("Not connected");
- delay(1000);
- }
- }
- // This makes sure the modem correctly reports incoming events
- vcs.hangCall();
- Serial.println("Waiting for a call");
- }
- void loop() {
- if (allarme == 1) {
- digitalWrite(13, HIGH);
- }
- if (allarme == 0) {
- digitalWrite(13, LOW);
- }
- if (digitalRead(10) == LOW) {
- presenza = 1;
- }
- else {
- presenza = 0;
- }
- if ( presenza ==1) {
- Serial.println("chiamo");
- Serial.println(millis()/1000);
- vcs.voiceCall("+390185xxxxxx");//qui il mio numero
- delay(10000);
- Serial.println("fine");
- Serial.println(millis()/1000);
- vcs.hangCall();
- }
- // Check the status of the voice call
- switch (vcs.getvoiceCallStatus()) {
- case IDLE_CALL: // Nothing is happening
- break;
- case RECEIVINGCALL: // Yes! Someone is calling us
- Serial.println("RECEIVING CALL");
- // Retrieve the calling number
- vcs.retrieveCallingNumber(numtel, 20);
- if ((strcmp(numtel, "+390185xxxxxx") == 0) || (strcmp(numtel, "+39338xxxxxx") == 0)) {
- Serial.println(allarme);
- allarme = !allarme;
- vcs.hangCall(); //serve per far cadere la chiamata
- }
- else
- Serial.println(" => non riconosciuto!");
- vcs.hangCall();
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement