🛠 Faire clignoter la LED embarquée et lire la batterie
Objectives
Get started with the Arduino MKR GSM 1400 without using the cellular module: blink the onboard LED (pin D6, LED_BUILTIN) and read the LiPo battery voltage via the analog channel ADC_BATTERY (channel 32, 12-bit ADC). This tutorial validates the USB port, the SAM-BA bootloader, and the serial console before any GSM manipulation, where power supply issues are frequent.
Hardware
- Arduino MKR GSM 1400 board (ATSAMD21G18A, Cortex-M0+ 48 MHz)
- LiPo battery 3.7 V of at least 1500 mAh on the battery pads (Arduino declares it mandatory as soon as the radio module is used; here it is recommended to develop the right habit)
- Micro-USB data cable (not just a charging cable)
- Arduino IDE with the "Arduino SAMD Boards" core and the "Arduino MKR GSM 1400" board selected
Complete code
// LED embarquee D6 + lecture brute de la batterie (module GSM inutilise)
void setup {
pinMode(LED_BUILTIN, OUTPUT); // LED_BUILTIN = broche 6 (variant.h du core)
Serial.begin(9600); // Sur SAMD21, Serial == SerialUSB (CDC)
}
void loop {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // bascule a chaque tour
int raw = analogRead(ADC_BATTERY); // canal 32, ADC 12 bits
Serial.print("VBAT raw: ");
Serial.println(raw);
delay(500);
}
Expected verification
After double-clicking the RST button and then uploading (using the bossac tool), the onboard LED blinks approximately every 500 ms and the USB console (9600 baud) displays a raw value that follows the battery charge. Without a battery, the reading changes or falls to a fixed value: this is normal, as the voltage sensor (ADC_BATTERY) depends on the actual board power supply.
Common errors
- Wrong board selected in the IDE: you must select "Arduino MKR GSM 1400", not "MKR WiFi 1010" or "Zero".
- Charging-only USB cable: the port never appears; try another cable and another port.
- Confusing the raw value with volts: the VBAT divider before the ADC is not reliably documented. >
- The Power LED remains on when running on battery: known and unresolved behavior (ArduinoCore-samd #515), not critical.
Serialsilent: is the board properly powered? Is the serial monitor opened AFTER the upload, on the correct port?
Other tutorials for this board
Code examples for this board
gsm-connexion.inoArduinoenvoi-sms.inoArduinohttp-get.inoArduinohttp-post-capteur.inoArduinoheure-gsm.inoArduinoappels.inoArduino