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 Uno R3 (ATmega328P, 5 V, 16 MHz) powered over USB or a 7-12 V barrel jack. 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
In the Arduino IDE, select the « Arduino Uno » board and the matching serial port, then click Upload. Open the serial monitor at 9600 baud to follow the messages.
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;
}
}