appels.ino

Arduino MKR GSM 1400 · File : appels.ino · Language : Arduino · Use case : Recevoir un appel et déclencher une action

The GSM modem as a remote control: a call from an authorised number toggles the alarm state of the MKR GSM 1400, which answers then hangs up immediately. LED 6 blinks while the alarm is on, without spending SMS credit.

Hardware

An Arduino MKR GSM 1400 (SAMD21 microcontroller, 2G/GPRS cellular modem, external antenna, powered by a LiPo battery on the J6 connector or over USB). SIM with an active number, 2G antenna, one LED with a 330 Ω resistor on pin 6.

Wiring

LED (+) through a 330 Ω resistor to pin 6, cathode to GND; nothing else to wire.

How it works

call.onRinging() registers a callback fired on incoming call. returnCaller() reads the caller number; if it matches the list, pickUp/hangUp end the call cleanly and a state boolean toggles.

Running it

In the Arduino IDE, install the Arduino SAMD Boards package, select the MKR GSM 1400 board, then upload. Network examples assume an active data SIM is inserted, the antenna is screwed on, and 2G coverage still exists in your area.

Variants

Keep several numbers in an array, send a confirmation SMS after toggling, or use in-call DTMF to choose among several commands.

appels.ino

// Appel entrant = declencheur : la LED 6 clignote si numero connu.
#include <MKRGSM.h>

const char PIN_SIM[] = "0000";
const char NUMERO_AUTORISE[] = "+33612345678";

GSM gsm;
GSMCall call;

const int LED = 6;
bool alarme = false;

void setup() {
  Serial.begin(9600);
  pinMode(LED, OUTPUT);
  if (gsm.begin(PIN_SIM) != GSM_READY) while (true);
  call.begin();
  call.onRinging(appelEntrant);
  Serial.println(F("En attente d'appel..."));
}

void loop() {
  unsigned long t = millis();
  if (alarme && (t / 500) % 2 == 0) digitalWrite(LED, HIGH);
  else digitalWrite(LED, LOW);
}

void appelEntrant() {
  String emetteur = call.returnCaller();
  Serial.println("Appel de : " + emetteur);
  if (emetteur == NUMERO_AUTORISE) {
    alarme = !alarme; // bascule l'etat a chaque appel du numero autorise
    Serial.println(alarme ? F("ALARME ACTIVEE") : F("ALARME COUPEE"));
    call.pickUp();
    delay(500);
    call.hangUp();
  } else {
    Serial.println(F("Numero inconnu, ignore"));
    call.hangUp();
  }
}

← Back to the board