🛠 Lire un capteur analogique avec l'ADC du Boron

Particle Boron · debutant · Schéma : IMG-particle-boron-debutant-3-boron-capteur-analogique-adc.svg — pont diviseur photorésistance / résistance sur la broche A0 de la Boron, valeurs 0 à 4095 affichées sur la console.

Objectives

The nRF52840 in the Boron integrates an analog-to-digital converter, and the board exposes 6 analog inputs A0 to A5 (3.3 V max). You will assemble a simple analog sensor — a voltage divider with a photoresistor (LDR) — read the voltage with analogRead, convert it to a percentage, and display it on the serial console. This is the basis for any analog sensor: potentiometer, flex sensor, TMP36, etc.

Hardware

Complete code

// Boron — lecture ADC sur A0 (capteur de lumière)
const uint16_t CAPTEUR_PIN = A0;    // A0-A5 : entrées analogiques

void setup {
    Serial.begin(9600);
    pinMode(CAPTEUR_PIN, INPUT);
    delay(1000);
    Serial.println("Lecture capteur analogique (0-4095)");
}

void loop {
    uint16_t brut = analogRead(CAPTEUR_PIN);          // 0-4095 (12 bits)
    float tension = brut * 3.3f / 4095.0f;            // 0-3,3 V
    uint16_t pourcent = map(brut, 0, 4095, 0, 100);
    Serial.printf("brut=%u  U=%.2f V  lumiere=%u %%\n", brut, tension, pourcent);
    delay(250);
}

Wiring: 3V3 → LDR → pin A0 → 10 kΩ resistor → GND. The midpoint goes to A0.

Expected verification

When covering the LDR with your finger, the raw value drops or rises significantly (depending on the divider orientation); when illuminating it, it returns toward the other extreme. The calculated voltage remains between 0 and 3.3 V. By connecting A0 to 3V3, you should read approximately 4095; to GND, approximately 0 — this is your calibration test.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials