Saturday, March 10, 2018

DC PMW remote train controller by bluetooth with arduino on a phone !

1 - Introduction

This page is describing the construction of an Arduino-based electric device and program i created. I could not find a proper/cheap solution that fitted my needs to remotely control speed and direction of a G-scale train pulling my 10 month old on a homemade G-scale flat car (picture below).

It is perfect too for any type of mobile control of a DC train outside or inside  (range +/-100m).

 The flat car with dolls enjoying the ride.

This is based on special ball bearings mounted wheels and homemade steel trucks to accomodate the always heavier baby. Note the truck-car attachment s also made with ball bearings to limit side wiggeling.

2- the device

Parts needed:

- Pcb board with holes ready to solder
- Female plugs : 2.54mm single row female pitch header socket connector (ebay) (for arduino nano on pcb)
- 2 position switch for invertion of track power (manual toggle, the software also inverts it!)
- Arduino nano (or uno or mega)(ebay)
- Md10c (Cytron 13A, 5-30V Single DC Motor Controller) (14$ ebay)
- Bluetooth Modem - BlueSMiRF Silver (silver or gold)  (25$ amazon or ebay)
- 5vdc regulator 7805 (ebay) + heat sink (or piece of metal and a screw)
- 6A diode (A6A)
- 1 A diode 1n 4007 (ebay by 100pcs)
- 470uf capacitor
- Terminals for pcb (ebay)
- 100nf capacitor
- LED of your choice
- 470 ohm 1/4 W resistor
- plastic box  (Lowes)
- soldering iron
- 4h of your time


-how to program the bluetooth module on arduino:

-How to configure ROBOREMO on android phone:

Arduino Nano and Bluesmirf power board:

Note: the only PMW compatible pins of the arduino nano are the following 3, 5, 6, 9, 10, 11. If changes are done to the pin output, make sure you use those pins for PMW. 

This PCB board connects 3 modules : the arduino nano, the Sparkfun Bluesmirf modules and the DC motor controller module MD10C
This board can also be used to configure the Bluesmirf with the arduino using the program present on the sparkfun link above (the Tx and RX ports common to the USB ports are not used here).


3- The program

Beta version of the arduino program is below.
A version with inertial support is not yet ready. Make the below text " .ino" and load it in Arduino IDE program.

Arduino program v0.002 (speed+ direction only):

//created by M. Cuy. on 23-fev-2018 for J. s train control by bluetooth with roboremo
//Contributions from L.P. Bot.
//adaptated from MD10c sketches to control pmw
//bluetooth module Bluesmirf gold
 * AUTHOR   : Maxime Cuypers
 * COMPANY  : private
 * REVISION : 0.0002
 * DATE     : 23/02/2018


 * IO DEFINITION                                                                *
//setup bluetooth bluesmirf port
int bluetoothTx = 2; // TX-O pin of BT module to Arduino pin2
int bluetoothRx = 3; // RX-I pin of B module to Arduino pin3

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

//const = variable "read-only".
// PWM is connected to pin 5.
const int pinPwm = 5;

// DIR is connected to pin 6.
//controle de direction
const int forwardPin = 6;
const int backwardPin = 7;

int val=0;

 * PRIVATE GLOBAL VARIABLES                                                     *

// Speed of the motor at startup (only created and initialized the first time a function is called.(static)
//static int iSpeed = 0;

// Acceleration of the motor.
//static int iAcc = 1;

char cmd[1000];
int cmdIndex;

void exeCmd() {
  if(cmd[0]=='f') {  // forward
    digitalWrite(backwardPin, LOW);  // disable backward
    digitalWrite(forwardPin, HIGH);  // enable forward
  if(cmd[0]=='b') {  // backward
    digitalWrite(forwardPin, LOW);
    digitalWrite(backwardPin, HIGH); 
  if(cmd[0]=='s') {  // stop
    analogWrite(pinPwm, 0);
  if( cmd[0]=='v' &&
      cmd[1]=='i' &&
      cmd[2]=='t' &&
      cmd[3]=='e' &&
      cmd[4]=='s' &&
      cmd[5]=='s' &&
      cmd[6]=='e' &&
      cmd[7]==' ') {
        String cmdStr;
        String valueStr;  
        cmdStr = String(cmd);
        valueStr = cmdStr.substring(8);
        val = valueStr.toInt();
  analogWrite(pinPwm, val);

 * FUNCTIONS                                                                    *

void setup() {   // at power on
  delay(500); // wait for bluetooth module to start
  pinMode(forwardPin, OUTPUT);
  digitalWrite(forwardPin, LOW);
  pinMode(backwardPin, OUTPUT);
  digitalWrite(backwardPin, LOW);
// Initialize the PWM and DIR pins as digital outputs.(upon reset)
  pinMode(pinPwm, OUTPUT);
//  pinMode(pinDir, OUTPUT); 

  // change Bluetooth module baud rate to 9600:
  bluetooth.begin(115200); // Bluetooth default baud is 115200
  bluetooth.print("$"); // enter cmd mode
  bluetooth.println("U,9600,N"); // change baud to 9600
  cmdIndex = 0;


void loop() {
  if(bluetooth.available()) {

    char c = (char);
    cmd[cmdIndex] = c; 
    if(cmdIndex<99 br="" cmdindex="">     
    if(c=='\n') {   // each command ends with '\n'
      cmdIndex = 0;


Saturday, February 25, 2017

N-scale convertion to dcc: sd-35, kato F3-B, kato F3-A

1- sd-35
2- Kato F3-B
3- in progress

1- SD-35-atlas N-scale

-TCS amd4 dcc board clips in easily.

-Ditch lights - The edges of the metal cast frame were drilled with a dremel to accomodate Led lights. SMD Leds (no resistor as already on TCS board.) are engulfed into a shrinking plastic case and glued on the frame depressions with epoxy resin.

-2x 220 uF smd capacitor added with discharge resistor of 4.7k ohm. Tight fit.

-Why a 440 uF cacapitor? to help with bad connections passing switches and limiting the high voltage peaks originating in the solenoids in the motor from power cuts/dirty track.

-Why a resistor in parallel with the capacitor ? I observed a funny bug with the TCS board with the capacitor only connected: if power is cut for 3-4 sec, the board is unresponsive. The capacitor maintined the board under ~0.5V - 0.2V for a long time. adding the discharge resistor of 4.7k ohm makes the TCS board able to resume from the issue after 10 sec only.

- Since the big capacitors hide the led on the board from the case light holes, i added 3 short 0.8mm optic fibers to let the light get on the other side of the obstruction.

- The plastic case was painted inside at the level of the super bright LEDs

Capacitor side with the 3 optic fibers taped on capacitors passing enough light...

Ditch lights in action, cabin side


2- Kato F3-B

- I wanted to add capacitors to the dcc decoder, a TCS M1, so that the run is smoother. Despite the fact that it could only have a limited impact on performance passing switches (capacitor size is limited in N-scale...), it could help get the rails and wheels dirty less quick by limiting motor peak currents.
The decoder does not offer a wire for the negative polarity. I found it opposite to the smd capacitor connected to the blue (+ accessories) wire. Soldering a black wire on the tiny capacitor (-) is tricky. If solder is applied on the top of the capacitor, it will break and pull out like it did with me at first. i had to resolder on the side of the capacitor for it to hold (contact with the PCB board more likely to be brute force resistant).
So the new black (-) and blue wires can be connected directly to the homemade smd 2x 220 uF capacitor board. Since the + pole is available on the board, i also added the contacts for the smd yellow Led light.

picture shows how i checked the correct polarity on the M1 board with a multimeter and without altering the insulator protection.

Opposite to the pseudocabin in the frame, a cavity must be dremelled to accomodate the opposite direction smd led. it is a smd led with 1k ohm resistor engulfed in a thermoplastic sleeve.

the fit is tight but works

The smd light and a 1k ohm smd resistor on the capacitor board, docked into the carved space of the frame.

the light in rule 17 mode (dimmable)

The F3-B diesel locomotive craws even slower than the sd-35...

The carved frame with the motor already hooked to the TCS M4 decoder
-front (left): space for the ditch lights
-rear (right): cuvette for the decoder, then deeper carved edge for the capacitors

front view with the board hole

The homemade ditch lights board, basically, resistors and Leds.
and a closed view to the space on the frame carved for the 2 x 220uF capacitors. As for TCS M1 DCC decoder, an additionnal wire needs to be soldered on the board to collect the ground for the additionnal capacitors.

The final results :) (+/- 16 h work later) with ditch lights as small bits of optic fiber glued on the body. PS: the inside of the body was painted in black matte to avoid reflections all over the place.


Tuesday, December 27, 2016

Musee du train de Schaerbeek, Bruxelles, Belgium

La locomotive historique!

 Locomotive a vapeur qui tractait des voiture de passagers et reliait Bruxelles a Ostende en 1 h 30 a grande vitesse.

 La locomotive du trans europ express...TEE

Saturday, November 19, 2016

basic astrophotography - short exposure/ no rotation synchronisation

basic setup:
nikon d5300 on gorillapod
Lens: 135mm nikkor f/2.8 MF
exposition: 3-5s
sensitivity: iso8000
raw (nikon's fake raw) recording of 50-100 images
moon phase : gibbeuse 60%
flats ~15 and dark ~40
Bias images (1/4000s - dark): ~40
merging progra: Regim (on Linux)
editing levels and noise: Darktable (on Linux)

andromede (centre?)

cassiopee (not totally centred)