Froggy World 4 the Train

by MikeTheMaker in Workshop > 3D Printing

6843 Views, 19 Favorites, 0 Comments

Froggy World 4 the Train

train08.jpg


In Froggy World, the amusement park for adventurous frogs, we have catapulted, booted and seesawed Froggy.  Upon departing the seesaw https://www.instructables.com/id/Froggy-World-3-The-Seesaw/ Froggy must land in a waiting train car. 

The train must be large enough to carry frogs (O scale) and must stop at precisely the right spot to receive passengers.  Stopping the train at a precise spot (not give or take an inch) is somewhat challenging.  Voltage from the supply varies throughout the day.  Voltage dips when heavy loads start in the house.  Voltage at the train engine depends upon track connections and wheel connections.  The train engine is an imprecise electromechanical device. 

The method of control I settled on requires detecting the position of the train with a magnetic switch (relay actually), then shutting the motor off and "crashing" the train into a stop sign. 

The system uses 3d printed parts:

http://www.thingiverse.com/thing:55181

and an Arduino for logic control.

train01.jpg
Let's start with something that didn't work too well.  I set up a photocell and photoresistor--and they reliably detected the train--but I had 3 to 4 inches of variance in where the train actually stopped after detection.

train02.jpg
train03.jpg
Using a reed relay (Jameco #111448) and a bar magnet glued to a train car, I was able to get my "variable stopping distance" down to about one inch.

Connect wire wrap wire across the relay contacts--the relay will close when the magnet is near.

train05.jpg
train06.jpg
The stop arm is mounted to the servo horn (HiTec HS-311 servo, amazon.com) using #4-40 machine screws.

train08.jpg
train07.jpg
train09.jpg
Using 4 x 3/4 wood screws, I mount the servo/arm assembly and support brace (opposite side of track) to the plywood base.

schematic1.jpg
train10.jpg
I wired the servo/arm, magnetic switch and relay (to control the train) in accordance with this schematic.

I put the following code into the Arduino:

#include <Servo.h>

 

Servo gate;

int start=10;

int next=7;

int dummy=0;

int train=5;

int arrival=1;

int val=0;

int val2=0;

 

void setup()

{gate.attach (3);

pinMode (next, OUTPUT);

pinMode (start, INPUT);

pinMode(arrival, INPUT);

pinMode (train, OUTPUT);

digitalWrite (next, HIGH);

digitalWrite (train, LOW);

gate.write(130);

delay(1000);

}

 

void loop()

 

{val=digitalRead(start);

if(val==LOW or dummy==1)

{

  gate.write(45);

  delay (500);

  digitalWrite(train,HIGH);

if(dummy=0)

{delay(5000);

dummy=1;}}

 

else

{val2=digitalRead(arrival);

if(val2==LOW)

{digitalWrite (train, LOW);

gate.write(130);

val2=0;

dummy=0;

val=0;

}}}


train13.jpg
train12.jpg
train11.jpg
With the servo disconnected and arm up, adjust the train speed such that the engine always rolls to a stop just beyond the arm.

Now, enable the arm and the train WILL stop at the stop sign!