I am currently working on an elevator for my examsproject in school. It's a quite simple simulation of a lifesize elevator. I'm currently using a steppermotor for the elevatorchair and it's set with a certain speed.

However, in a real elevator, the speed would slowly decrease as it's progressing towards it's destination for a more pleasant ride for the passengers. I'd like to make the same simulation. I was thinking of using the millis to periodically increase the delays over time, but I don't know whether alternative methods could be used for better results.


millis() sound like a good way to go.

Check the estimated time until arrival (stopping), and in steps (you define yourself) you changen the (PWM) speed of the stepper motor.

Note, also for accelerating you can use the same step schema but reversed.

There are other ways, but I think those will be too complicated, like setting a (hardware) timer for the next speed change. Changing the speed in ms-accuracy will be more than enough.

Do not use delay, since you still want to be responsive for pressed buttons, and (safety) sensors.

  • Response to your answer that is a comment and will be deleted high likely: Hello Soren, this is not an answer, so you have to put it either as comment, or update your question (the latter is best). I understand the for loop (and I kind of understand, being Dutch). In principle the delay is possible, but it will get you in trouble when wanting to read button states/sensor states (imagine a safety sensor is activated exactly in those 5 ms, you either miss it or have a 5 ms delay). It's better to use millis() over delay, unless you don't have anything else that needs to be responsive. – Michel Keijzers Apr 4 '18 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.