potentiomete-plot.ino

Arduino Nano (Classic, ATmega328P) · File : potentiomete-plot.ino · Language : Arduino · Use case : Visualiser un capteur analogique dans le moniteur série

The Arduino IDE serial monitor can plot curves: if a single value leaves per line, the Nano becomes a pocket oscilloscope. This sketch averages 16 samples of the A0 potentiometer and adds an ASCII bar for terminal fans.

Hardware

An Arduino Nano classic (ATmega328P at 16 MHz, 30-pin DIL breadboard footprint, mini-B USB, 5 V logic, RESET pin at the lower-left corner). Arduino Nano, 10 kΩ potentiometer (wiper on A0, the other two legs on 5 V and GND).

Wiring

Wiper→A0, one end→5 V, other end→GND; any 0-5 V sensor follows the same wiring.

How it works

Averaging 16 readings divides noise by four; analogRead uses the 328P 10-bit ADC with the 5 V reference. The Plotter tab shows the live curve.

Running it

In the Arduino IDE, select the Arduino Nano board and ATmega328P processor, pick the serial port, then upload. The board's 5 V rail suits 5 V sensors; otherwise use 3.3 V on compatible pins.

Variants

Switch analogReference to INTERNAL (1.1 V) for small signals, or ship everything to the Python plotter for multiple scales.

potentiomete-plot.ino

// Potentiometre sur A0 : trace ASCII + format "trace" du plotter.
// Le moniteur serie 2.x d l'IDE affiche la valeur si une seule sort.
const int CANAL = A0;
const int MOYENNE = 16;

unsigned long dernier = 0;

void setup() {
  Serial.begin(115200);
  analogReference(DEFAULT); // 0-5 V par defaut sur le Nano
}

void loop() {
  if (millis() - dernier < 50) return; // 20 Hz
  dernier = millis();

  long somme = 0;
  for (int i = 0; i < MOYENNE; i++) somme += analogRead(CANAL);
  int brut = somme / MOYENNE; // moyenne glissante anti-bruit

  float tension = brut * (5.0 / 1023.0);
  Serial.print(tension, 3);      // <- seule valeur : plotter IDE
  Serial.print("	");
  int barreau = map(brut, 0, 1023, 0, 40);
  for (int i = 0; i < barreau; i++) Serial.print('#');
  Serial.println();
}

← Back to the board