Construire une Centrale DCC Numérique pour Modélisme Ferroviaire avec Arduino – Application Android Gratuite Incluse
Composants et Fournitures
| Composant | Quantité | Notes |
|---|---|---|
| Arduino Pro Mini 328 - 5V/16 MHz (SparkFun) | 1 | |
| Driver H-Bridge LMD18200T | 1 | 2 A max, signal DCC sur pin DIR, PWM maintenu HIGH |
| PCB (disponible sur eBay) | 1 | |
| Régulateur Linéaire 7805 (5 V) | 1 | |
| Diode Zener 3,6 V 0,5 W (1N4732A) | 1 | Protection entrée Bluetooth |
| Module Bluetooth HC-06 | 1 | Esclave uniquement, liaison série |
| Résistance 0,1 Ω 2 W (Métal Film) | 1 | Détection de courant (shunt) |
| Condensateur 220 µF 16 V | 1 | Découplage alimentation |
| Condensateur 10 µF 16 V | 1 | |
| Condensateur Céramique 0,1 µF | 3 | |
| Résistance 10 kΩ | 2 | |
| Résistance 4,7 kΩ | 1 | |
| Borniers à vis 2 pôles 3,5 mm | 1 | Alimentation voie |
| Borniers à vis 6 pôles 2,54 mm | 1 | |
| Connecteur 4 pins 2,54 mm (femelle) | 1 | Pour HC-06 |
| Connecteur 12 pins 2,54 mm (femelle) | 2 | Pour Arduino Pro Mini |
Applications et Services en Ligne
- LocoMotive (version gratuite) – Android ≥ 4.1, sur Google Play Store
- LocoMotive DCC (version payante, ~6 €) – Lecture/écriture CV 1–255, jusqu'à 28 fonctions, contrôle 4 locos simultanés, noms personnalisés, etc.
À Propos du Projet
Originalité : Un circuit électronique minimaliste génère le signal DCC et alimente la voie, mais l'application smartphone fait le travail lourd : elle construit les paquets DCC complets (selon norme NMRA) et les transmet par Bluetooth. L'Arduino ne fait que les convertir en signaux d'horloge DCC.
Mises à jour majeures :
- Août 2019 : LocoMotive DCC (payant) – lecture/écriture CV 1–255.
- Mai 2019 : Version 3 € – 28 fonctions éditables, 4 locos simultanées, barres de vitesse.
- Fév 2019 : Antenne HC-06 rallongée (fil cuivre 31,2 mm = λ/4 à 2,4 GHz) pour portée accrue.
- Jan 2019 : Fonctions momentanées (F2/F3 pour corne), vitesse max par loco.
Caractéristiques Principales
- Contrôle de 1 à 20 locomotives (adresses DCC)
- Idéal pour réseaux petits à moyens
- Puissance 2 A (LMD18200) → ~16 locos HO/OO ; extensible avec H-bridge plus puissant
- Protection court-circuit et surintensité (seuil 2 A réglable dans le code)
- Fonctions : lumière, direction, F1–F8 (noms, visibilité, momentané éditables)
- Aiguillages/accessoires : jusqu'à 8 paires de sorties, noms personnalisés
- Programmation CV1 (adresse) + lecture/écriture CV 1–255 (version payante)
- Alimentation DC 12–20 V selon échelle (Z/N/HO/O/G)
- Coût total ~20 € (pièces eBay)
Étape 1 : Sketch Arduino
Le sketch complet est joint. La boucle principale reçoit les chaînes texte depuis l'application via Bluetooth (SoftwareSerial sur D8/D9), les décode et met à jour les paquets DCC.
void loop() {
if (bluetooth.available() > 0) {
inString = bluetooth.readStringUntil('\n');
}
if (inString.substring(0,1) == "D") { string(); } // Paquet DCC
delay(20);
}
La fonction string() parse la chaîne (ex. DD,3,63,12,48, → paquet 4 octets vitesse ; DD,1,129,128, → paquet 3 octets fonction) et remplit le buffer de messages DCC.
Référence NMRA : Standard S-9.2.1
Le LMD18200 reçoit le signal DCC sur sa pin DIR ; sa pin PWM est maintenue HIGH.
Étape 2 : Schéma Fritzing & Câblage
L'Arduino Pro Mini reçoit les données via HC-06 (Rx↔Rx, Tx↔Tx – attention : pas de croisement). Il génère les fronts d'horloge NMRA (58 µs / 116 µs) par interruption Timer2. La détection de courant (shunt 0,1 Ω sur A0, référence interne 1,1 V) coupe le LMD18200 (pin Brake = D13) si > 2 A.
Liste d'achats type eBay :
- PCB dédié
- Arduino Pro Mini Atmega328P 5V/16M
- LMD18200T
- HC-06
- Résistance 0,1 Ω 2 W, 3× 0,1 µF, 2× 10 kΩ, 10 µF 25 V, 220 µF 16 V, 4,7 kΩ
- Régulateur L7805CV, Diode Zener 3,6 V 0,5 W
- Borniers Phoenix Contact MKDS 1/2-3,5 + 6 pôles 2,54 mm
- Connecteurs 4 et 12 pins 2,54 mm
- Alimentation 14 V DC (ex. chargeur portable 2,5 A) pour HO/OO
Antenne HC-06 : souder un fil de cuivre rigide (âme de câble de terre) de 31,2 mm sur l'antenne PCB du module. Gainer pour éviter courts-circuits.
Détection de courant : 0,1 Ω → 200 mV à 2 A. Reference interne 1,1 V → 1,08 mV/division → ~10,8 mA/division. Précision ~50 mA. Coupure à 2 A : if (C > 2000) { digitalWrite(13,HIGH); }. Valeur envoyée à l'app chaque seconde.
Étape 3 : Application Android
- Gratuite : « LocoMotive » sur Google Play Store
- Complète (payante) : « LocoMotive DCC » – instructions jointes
Code Arduino (locomotive_dcc_sep19.ino)
Afficher le code complet (cliquer pour déplier)
// 1 Sep 2019 - Sketch pour App 'Locomotive DCC' avec LMD18200
// Lecture/écriture CV ajoutée
#include
SoftwareSerial bluetooth(8,9); // RX, TX
int C, sensorValue;
long t=0, lastmillis=0, interval=1000;
String inString;
int a[8];
int preamable_type = 0;
int Address;
float CV_VAL, cv_val, cv_val0, cv_val1, cv_val2, cv_val3, cv_val4, cv_val5, cv_val6, cv_val7;
int test_num, cv_write_val, Cs;
boolean cv_logic, ok;
int num;
#define TIMER_SHORT 0x8D // 58 µs
#define TIMER_LONG 0x1B // 116 µs
unsigned char last_timer=TIMER_SHORT, flag=0, every_second_isr=0;
#define PREAMBLE 0
#define SEPERATOR 1
#define SENDBYTE 2
unsigned char state=PREAMBLE, preamble_count=16, outbyte=0, cbit=0x80;
unsigned char xdata=0, data=0, data_f=0, data_f1=0, data_f2=0;
int locoAdr = 9;
struct Message { unsigned char data[7]; unsigned char len; };
#define MAXMSG 3
struct Message msg[MAXMSG] = {
{ {0xFF,0,0xFF,0,0,0,0}, 3 }, // Idle
{ {locoAdr,0,0,0,0,0,0}, 3 } // Loco speed 128 steps
};
int msgIndex=0, byteIndex=0;
void SetupTimer2() {
TCCR2A = 0;
TCCR2B = (0<=MAXMSG) msgIndex=0; byteIndex=0; }
break;
case SEPERATOR:
flag=0; state=SENDBYTE; cbit=0x80; outbyte=msg[msgIndex].data[byteIndex];
break;
case SENDBYTE:
flag = (outbyte & cbit) ? 1 : 0;
cbit >>= 1;
if (cbit==0) {
byteIndex++;
if (byteIndex >= msg[msgIndex].len) {
state=PREAMBLE;
preamble_count = (preamable_type==0)?16:24;
} else state=SEPERATOR;
}
break;
}
latency = TCNT2;
TCNT2 = latency + (flag ? TIMER_SHORT : TIMER_LONG);
last_timer = flag ? TIMER_SHORT : TIMER_LONG;
}
}
void setup() {
Serial.begin(115200);
analogReference(INTERNAL);
pinMode(13,OUTPUT);
bluetooth.begin(9600);
delay(500);
Serial.println("Bluetooth Started");
bluetooth.println("Bluetooth Started");
DDRD = B01100000;
SetupTimer2();
t = millis(); lastmillis = millis();
digitalWrite(6,LOW); digitalWrite(13,HIGH); // Bridge OFF
int get_cv_val = cv_calc(test_num);
}
void current() {
int value=0;
for(int i=0;i<5;i++) { value+=analogRead(A0); delay(1); }
sensorValue = value/5;
C = 10.8 * sensorValue; // mA
if (C>2000) {
Serial.println("Over Current");
bluetooth.println("Short!");
digitalWrite(6,LOW); digitalWrite(13,HIGH);
bluetooth.println(C);
}
}
void loop() {
if (bluetooth.available()) { inString = bluetooth.readStringUntil('\n'); Serial.println(inString); }
if (inString.substring(0,1)=="D") { string(); }
if (inString.substring(0,1)=="C") { digitalWrite(6,HIGH); digitalWrite(13,LOW); } // Reset surintensité
if (inString.substring(0,1)=="G") { digitalWrite(6,HIGH); digitalWrite(13,LOW); current(); bluetooth.println(C); }
if (inString.substring(0,1)=="A") { digitalWrite(6,HIGH); digitalWrite(13,LOW); get_cv_data(); cv1_prog(); digitalWrite(6,LOW); digitalWrite(13,HIGH); }
if (inString.substring(0,3)=="get") { cv_val=0; digitalWrite(6,HIGH); digitalWrite(13,LOW); get_cv_num(); cv_read(); digitalWrite(6,LOW); digitalWrite(13,HIGH); }
if (inString.substring(0,3)=="add") { cv_write_val=0; digitalWrite(6,HIGH); digitalWrite(13,LOW); get_cv_new_val(); repeat_cv_write(); digitalWrite(6,LOW); digitalWrite(13,HIGH); }
if (inString.substring(0,1)=="V") { delay(50); bluetooth.print("CV1 updated"); Serial.println(Address); }
if (inString.substring(0,1)=="E") { digitalWrite(6,LOW); digitalWrite(13,HIGH); } // E-Stop
inString="";
}
// Fonctions de parsing, assemblage paquets DCC, lecture/écriture CV...
// (voir code source original pour l'intégralité : string(), amend_len3/4(), assemble_3/4_byte(),
// cv_read(), cv_write(), cv_calc(), reset_packet(), page_preset_packet(), cv1_write_packet(),
// cv_verify0/1_packet(), valid_packet(), repeat_cv_write(), get_cv_data(), get_cv_num(), get_cv_new_val())
Boîtier & Réalisation
Schémas & Fichiers CAO
- Schéma Fritzing :
bluetooth_android_dcc_lmd18200_S8NTVsI4LY.fzz - Instructions application (PDF joint)
Ressources & Références
- Standard NMRA S-9.2.1 : PDF
- PCB sur eBay (recherche « Arduino DCC LMD18200 PCB »)
- Application gratuite : LocoMotive
- Application complète : LocoMotive DCC
Processus de fabrication
- MrRobot : Robot Rapiro piloté par mobile Ubuntu avec interaction voix, toucher et secousse
- Station de Mixage Automatique 6-Shooter Pilotée par Arduino – Construisez Votre Propre Robot Barman
- Dé numérique Arduino sur écran LCD 16x2 – Générateur aléatoire à bouton poussoir
- Manette de jeu USB Arduino DIY – Construisez votre propre gamepad haute performance
- Créer des animations et jeux sur LCD avec Arduino UNO
- Chaussures auto-laçantes intelligentes avec récupération d'énergie piézoélectrique
- Mesure de distance en temps réel par sonar Arduino et visualisation Processing
- Pixel Chaser : Jeu LED interactif à une touche avec Arduino Nano
- Contrôle fluide de la luminosité LED avec Bolt IoT et Arduino UNO