Serial baud rate detector
A Nano listens on a serial wire, measures the shortest pulse it sees and works out which standard baud rate the sender is using. Test it with a second Nano that sends at different speeds.
Build it step by step
0 of 7 doneUpload the sender to board one
It starts at 1200 baud.
Upload the detector to board two
Open the serial monitor at 9600.
Join D3 on the sender to D2 on the detector
And join the grounds.
Watch the detector
It reports about 1200 baud.
Wait for the sender to change speed
Every six seconds.
Write down the five readings
Compare with the sender's list.
Unplug the data wire
The detector says No signal.
How do you build a serial baud rate detector?
A Nano listens on a serial wire, measures the shortest pulse it sees and works out which standard baud rate the sender is using. Test it with a second Nano that sends at different speeds. You need Arduino Nano × 2, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 80 minutes.
- Level
- Intermediate
- Time
- About 80 min
- Parts
- 3
Parts list
- Development BoardsBuyArduino Nano × 2
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Sender board D3 | Detector board D2 | The serial data wire |
| Sender board GND | Detector board GND | Shared ground |
Code
A serial signal sends each bit for a fixed time, so the shortest pulse on the wire is one bit long, and the baud rate is one million divided by that length in microseconds. The sender sketch repeats the letter U, whose binary pattern 01010101 flips on every bit, so every pulse on the wire is exactly one bit wide. It changes speed every six seconds through 1200, 2400, 4800, 9600 and 19200 baud. The detector times forty pulses with pulseIn, takes the shortest, converts it to a baud rate and rounds to the nearest standard speed. Watch it follow the sender as the speed changes. When you point it at an unknown board in real life, it needs a signal that includes some single-bit pulses, and ordinary text usually has them. Only connect it to signals at 5 volt or 3.3 volt logic levels, never to RS-232 voltages from an old computer port.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// ===== SENDER (board one) : cycles through five baud rates =====
#include <SoftwareSerial.h>
SoftwareSerial tx(4, 3); // RX pin 4 unused, TX pin 3
const long RATES[5] = {1200, 2400, 4800, 9600, 19200};
int idx = 0;
unsigned long lastSwitch = 0;
void setup() {
tx.begin(RATES[0]);
}
void loop() {
if (millis() - lastSwitch > 6000) { // new rate every six seconds
lastSwitch = millis();
idx = (idx + 1) % 5;
tx.begin(RATES[idx]);
}
tx.write('U'); // 0x55: every bit is exactly one bit time wide
delay(5);
}
/* ===== DETECTOR (board two, a separate sketch) =====
Copy everything below into a new sketch for the second board. */
/*
const uint8_t RX_PIN = 2;
const long STANDARD[] = {1200, 2400, 4800, 9600, 19200, 38400, 57600};
const int COUNT = 7;
void setup() {
pinMode(RX_PIN, INPUT);
Serial.begin(9600);
Serial.println("Listening for a serial signal...");
}
void loop() {
unsigned long shortest = 100000UL;
int seen = 0;
for (int i = 0; i < 40; i++) {
unsigned long us = pulseIn(RX_PIN, LOW, 20000); // low pulses of the data wire
if (us > 0) {
seen++;
if (us < shortest) shortest = us;
}
}
if (seen < 5) {
Serial.println("No signal");
} else {
float raw = 1000000.0 / shortest; // baud from the shortest pulse
int best = 0;
float bestErr = 1e9;
for (int i = 0; i < COUNT; i++) {
float err = fabs(raw - STANDARD[i]) / STANDARD[i];
if (err < bestErr) { bestErr = err; best = i; }
}
Serial.print("Shortest pulse ");
Serial.print(shortest);
Serial.print(" us, about ");
Serial.print(STANDARD[best]);
Serial.println(" baud");
}
delay(500);
}
*/Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Sender at 1200 | Shortest pulse near 833 microseconds |
| Sender at 9600 | Shortest pulse near 104 microseconds |
| Sender at 19200 | Shortest pulse near 52 microseconds |
| Data wire unplugged | No signal |
| Detector output | The nearest standard baud rate |
If it does not work
Always No signal
Check the data wire and the shared ground.
Wrong rate reported
Make sure the sender sketch is running and the pin is D3.
Sender garbles at high rates
SoftwareSerial is best at 19200 baud and below.
Numbers jump about
Wait for the sender to settle after a speed change.
Upload fails
Choose the Old Bootloader option.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the serial baud rate detector?
Arduino Nano × 2, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the serial baud rate detector take to build?
About 80 minutes for a intermediate maker, in 7 steps.
How do I know the serial baud rate detector works?
Sender at 1200: Shortest pulse near 833 microseconds. Sender at 9600: Shortest pulse near 104 microseconds. Sender at 19200: Shortest pulse near 52 microseconds.
Always No signal: what should I check?
Check the data wire and the shared ground.
Wrong rate reported: what should I check?
Make sure the sender sketch is running and the pin is D3.
Sender garbles at high rates: what should I check?
SoftwareSerial is best at 19200 baud and below.
Numbers jump about: what should I check?
Wait for the sender to settle after a speed change.
