i want to stop model train at station and then again run after 5 sec.

i have model train and i want to stop it at the train station when it arrives. i have ultrasonic sensor, dc motor, and arduino uno. plz guys help me for program it.

the motor is in train. i have battery to power the train. i am going to put arduino on train and power it with 9 volt battery. and stick ultrasonic sensor on left side of the train so that if train arrives at station then ultrasonic sensor will sense it. but i want to program it like if the train stops at station after 5 sec i want that train to run again. plz guys help me to program it.

What have you programmed so far ?

Can you read the sensor and print the value that it returns ?

How are you powering the motor ? Unless the motor is tiny do not power it from the Arduino pins directly as they cannot supply much current. Even if the motor is tiny there are other reasons to use an external power supply and switch the motor using a relay, transistor or MOSFET.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html

Can you please tell us your electronics, programming, Arduino, hardware experience?

Thanks.. Tom... :slight_smile:

rushikeshpatil:
i want to program it like if the train stops at station after 5 sec i want that train to run again.

When the train stops save the value of millis() to a variable.

Then keep checking the latest value of millis() with the saved value. When the difference is greater than 5000 millisecs it will be time to move on.

if (millis() - stationStopMillis >= stationWaitMillis) {
  // time to move on
}

Have a look at how millis() is used to manage timing in Several things at a time.

Have a look at Using millis() for timing. A beginners guide if you need more explanation.

...R

OP - my signature (see below) asks that you post questions here rather than sending private messages so I will not be answering your PMs

Can you please answer the questions in posts #1 and #2

UKHeliBob:
I will not be answering your PMs

I got one also and gave the same response.

...R