🛠 Toucher capacitif : touchRead sans composant
Objectives
Use the RA4M1's capacitive touch peripheral (CTSU): 14 pins on the board can serve as capacitive touch sensors, read by a simple touchRead call from the official CapacitiveTouch library. You will calibrate a threshold by observing actual values, then trigger an LED matrix display — a button without a button, without resistors or wires other than a piece of conductor.
Hardware
- 1 Arduino UNO R4 WiFi + USB-C cable
- 1 bare connecting wire (the "pad": a piece of wire, a copper plate, or glued aluminum foil)
- Optional: a second wire to compare two touch zones.
Complete Code
#include <CapacitiveTouch.h>
const uint8_t PAD = A1; // une broche compatible toucher
const int SEUIL = 100; // à calibrer avec le Moniteur série !
void setup {
Serial.begin(115200);
}
void loop {
int v = touchRead(PAD); // ~0 au repos, monte franchement au toucher
Serial.println(v);
if (v > SEUIL) {
MatrixSmiley; // votre fonction d'affichage (voir tuto matrice)
}
delay(20);
}
Expected Verification
At rest, touchRead displays a low and stable value; as soon as a finger touches the bare wire (or the board near the relevant pin), the value rises significantly above the threshold. Fine-tune the threshold to the midpoint between your two measurements: this is THE correct calibration method, identical to that of an analog sensor.
Common Errors
- Choosing a non-touch-compatible pin:
touchReadthen returns a frozen value — consult the official schematic beforehand. - Setting the threshold "by guesswork" at 50 or 500: without prior measurement, the sensor never triggers or triggers constantly (humidity, long cable acting as an antenna).
- Touch cable too long without a finger or insulation: a 30 cm wire picking up 50 Hz interference makes the value fluctuate; keep the pad short or surround it with adhesive tape.
- Confusing it with an analog reading:
touchReaddoes not measure voltage, but the variation in capacitance caused by the finger; a voltage divider on the pin is unnecessary. - Forgetting
#include <CapacitiveTouch.h>: the library is not included by default in all sketches.
Other tutorials for this board
- Premier Blink sur la UNO R4 WiFi : la première UNO 32 bits
- Apprivoiser la matrice LED 12x8 intégrée
- Se connecter au WiFi et lire l'heure NTP (WiFiS3)
- Inclinomètre sur la matrice : l'IMU LSM6DSV16X en I²C
- Serveur web embarqué : piloter la matrice depuis le navigateur
- Horloge persistante : RTC à pile + resynchronisation NTP
Code examples for this board
clignotante.inoArduinobouton-poussoir.inoArduinodac-analogique.inoArduinoentree-analogique.inoArduinopwm-respiration.inoArduinoservo-balayage.inoArduino