Build it step by step
0 of 7 doneRecord the stop names
And save them as 0001, 0002, 0003 mp3 plus a ding as 0004.
Copy them to the SD card
Formatted as FAT32.
Wire the player
TX to D10, D9 through 1 kilohm to RX, 5V and GND, speaker on SPK1 and SPK2.
Wire the two buttons
D2 and D3, each other leg to GND.
Upload the sketch
It plays the ding and the first stop.
Press NEXT and BACK
It announces the next or previous stop.
Check the serial monitor
It prints the stop name.
How do you build a model tram stop announcer?
A model tram line has three stops, and a button moves to the next one while a recorded voice announces its name through a small speaker. You record the stop names yourself. A good way to try a sound-player module with a Nano. You need Arduino Nano, DFPlayer Mini MP3 module, Speaker 8 Ω 0.5 W, Tactile push button 6 mm × 2, Resistor 1 kΩ, 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
- 7
Parts list
- Development BoardsBuyArduino Nano × 1
- InterfacesBuy
- Motors & ActuatorsBuy
- SwitchesBuy
- PassivesBuyResistor 1 kΩ × 1
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| DFPlayer TX | Nano D10 | Player to Nano |
| Nano D9 | 1 kilohm resistor to DFPlayer RX | Nano to player, through a resistor |
| DFPlayer VCC and GND | Nano 5V and GND | Power |
| DFPlayer SPK1 and SPK2 | Small 8 ohm speaker | The voice |
| Next stop button | Nano D2 and GND | Moves forward one stop |
| Previous stop button | Nano D3 and GND | Moves back one stop |
Code
The DFPlayer Mini plays MP3 files from a micro SD card and is controlled by simple serial messages. Format the card as FAT32 and copy on four files named 0001.mp3 to 0004.mp3: the three stop names, which you record yourself with a phone, and a short ding. The Nano talks to the player with a software serial port on D10 and D9, and the D9 line goes through a 1 kilohm resistor because the player's RX pin is happier with a gentler signal. Each button press moves to the next or previous stop, plays the ding, waits a moment and then plays the stop name, and the serial monitor prints the name as well. The player's power wire carries bursts of current, so if you hear clicking or the Nano resets, add a 100 microfarad capacitor across the player's power pins. Install "DFRobotDFPlayerMini" by DFRobot from the Library Manager. Keep the volume moderate for a desk model, and use a small speaker with the player's own amplifier, not a large speaker. Try adding a line map drawn on card with three LEDs that light at the current stop.
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).
// Libraries: DFRobotDFPlayerMini.
// Put these files on the FAT32 SD card: 0001.mp3, 0002.mp3 and 0003.mp3 (the three stop names)
// and 0004.mp3 (a short ding).
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
SoftwareSerial dfSerial(10, 9); // Nano RX = D10, TX = D9
DFRobotDFPlayerMini player;
const uint8_t BTN_NEXT = 2;
const uint8_t BTN_BACK = 3;
const uint8_t STOPS = 3;
const char *NAMES[STOPS] = {"Market Square", "Library", "Station"}; // the words you recorded
uint8_t stopNo = 0; // 0 to 2
bool prevNext = false, prevBack = false;
void announce() {
Serial.print(F("Next stop: "));
Serial.println(NAMES[stopNo]);
player.play(4); // the ding
delay(1200);
player.play(stopNo + 1); // the stop name
}
void setup() {
pinMode(BTN_NEXT, INPUT_PULLUP);
pinMode(BTN_BACK, INPUT_PULLUP);
Serial.begin(9600);
dfSerial.begin(9600);
delay(1000);
if (!player.begin(dfSerial)) {
Serial.println(F("Player not found: check wiring and the SD card."));
while (true) {}
}
player.volume(15); // 0 to 30, keep it moderate
Serial.println(F("Tram ready. Press NEXT or BACK."));
announce();
}
void loop() {
bool n = (digitalRead(BTN_NEXT) == LOW);
bool b = (digitalRead(BTN_BACK) == LOW);
if (n && !prevNext) { stopNo = (stopNo + 1) % STOPS; announce(); }
if (b && !prevBack) { stopNo = (stopNo + STOPS - 1) % STOPS; announce(); }
prevNext = n;
prevBack = b;
delay(20);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
Player not found: check wiring and the SD card.
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Power-up | Ding then the first stop name |
| NEXT | Ding then the next stop |
| BACK | Ding then the previous stop |
| After the last stop | NEXT wraps to the first |
| Serial monitor | Prints the stop name |
If it does not work
Player not found message
Check TX and RX, the SD card and its format.
Wrong stop plays
Check the file names start with four digits.
Clicks or resets
Add a 100 microfarad capacitor across the player's power.
Too loud
Lower the volume number in the code.
Buttons do nothing
Check they go to D2 or D3 and GND.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the model tram stop announcer?
Arduino Nano, DFPlayer Mini MP3 module, Speaker 8 Ω 0.5 W, Tactile push button 6 mm × 2, Resistor 1 kΩ, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the model tram stop announcer take to build?
About 80 minutes for a intermediate maker, in 7 steps.
How do I know the model tram stop announcer works?
Power-up: Ding then the first stop name. NEXT: Ding then the next stop. BACK: Ding then the previous stop.
Player not found message: what should I check?
Check TX and RX, the SD card and its format.
Wrong stop plays: what should I check?
Check the file names start with four digits.
Clicks or resets: what should I check?
Add a 100 microfarad capacitor across the player's power.
Too loud: what should I check?
Lower the volume number in the code.
