Froggy World 4 the Train
by MikeTheMaker in Workshop > 3D Printing
6843 Views, 19 Favorites, 0 Comments
Froggy World 4 the Train
Connect wire wrap wire across the relay contacts--the relay will close when the magnet is near.
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;
}}}
Now, enable the arm and the train WILL stop at the stop sign!