🛠 Lire un capteur analogique sur l'ADC 12 bits
Objectives
Use the Photon's ADC: the board has 8 12-bit ADC inputs (A0 to A7). You will read a potentiometer wired as a voltage divider on A0 and convert the raw value (0 to 4095) into voltage.
Hardware
- 1 Particle Photon
- 1 potentiometer (e.g., 10 kΩ)
- Breadboard wires; the board's 3.3 V reference supply (3.3 V logic, ADC full scale = 3.3 V)
Complete code
// photon-capteur-adc.ino — lecture ADC 12 bits sur A0
const int CAPTEUR = A0; // 8 entrées ADC 12 bits : A0..A7
void setup {
Serial.begin(9600);
}
void loop {
int brut = analogRead(CAPTEUR); // 0..4095
float tension = brut * 3.3f / 4095.0f; // conversion en volts
Serial.print("brut=");
Serial.print(brut);
Serial.print(" tension=");
Serial.print(tension);
Serial.println(" V");
delay(200);
}
Expected verification
When turning the potentiometer, the raw value follows the wiper between 0 and 4095, and the calculated voltage remains between 0 and 3.3 V. Voltage divider schematic: potentiometer pin 1 to 3V3, pin 3 to GND, wiper to A0.
Common errors
- Powering the sensor with 5 V and reading on A0: the ADC full scale is limited to 3.3 V logic, so you saturate the measurement.
- Believing that all pins accept 5 V: A3 and the DAC are exceptions (not 5 V-tolerant, see datasheet).
- Confusing resolution: the ADC is 12 bits (0..4095), not 10 bits like on other boards.
- The 3V3 output is limited to 100 mA: do not power a power-hungry sensor chain from this pin.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-evenement.inoArduinofonction-distance.inoArduinocapteur-dht.inoArduinoruban-neopixel.inoArduinopwm-respiration.inoArduino