commande-serie.ino
The board becomes a mini serial server: each character received in the monitor runs a command (toggle LED, raise/lower PWM, print state). An ideal base to script tests from a PC.
Hardware
An Arduino Pro Mini (ATmega328P, 5 V/16 MHz or 3.3 V/8 MHz variants) wired to a USB-serial adapter (FTDI) or an ICSP programmer. No extra component to test; LED and PWM load of your choice.
Wiring
LED on 13 and PWM load on 9 (with 330 Ω resistor). The IDE serial monitor at 9600 baud, line ending "none".
How it works
Serial.available() tests without blocking, Serial.read() reads one byte, a switch runs the action. Replies are printed for visual feedback.
Running it
Select « Arduino Pro Mini » in the IDE (5 V/16 MHz or 3.3 V/8 MHz per your model), ATmega328P processor, the right port, then Upload. The adapter must be wired DTR-DTR, RX-TX, TX-RX, VCC-VCC, GND-GND.
Variants
Replace the switch with Serial.readStringUntil(\n) for multi-word commands, or attach an HC-05 Bluetooth module on SoftwareSerial.
commande-serie.ino
// Mini-serveur de commandes : 'l' LED, 'b' buzzer, 'u'/'d' PWM, 's' etat.
const int LED = 13;
const int PWM = 9;
int niveau = 128;
bool ledOn = false;
void setup() {
pinMode(LED, OUTPUT);
pinMode(PWM, OUTPUT);
Serial.begin(9600);
Serial.println(F("Commandes: l=LED b=buzzer u/d=pwm s=etat"));
}
void loop() {
if (!Serial.available()) return;
char c = Serial.read();
switch (c) {
case 'l':
ledOn = !ledOn;
digitalWrite(LED, ledOn ? HIGH : LOW);
Serial.println(ledOn ? F("LED ON") : F("LED OFF"));
break;
case 'u':
niveau = min(255, niveau + 16);
analogWrite(PWM, niveau);
Serial.println(niveau);
break;
case 'd':
niveau = max(0, niveau - 16);
analogWrite(PWM, niveau);
Serial.println(niveau);
break;
case 's':
Serial.print(F("LED=")); Serial.print(ledOn);
Serial.print(F(" PWM=")); Serial.println(niveau);
break;
}
}