body, html {font-family: 'Open Sans', sans-serif;} #nav a, #nav{font-family: 'Open Sans', sans-serif;} #title #tagline {font-family: 'Open Sans', sans-serif;} #main .gridItem h3 {font-family: 'Open Sans', sans-serif;}

About Motors


You asked me to include a motor part into the sketch of the Dancing Cacher. During the weekend I was quite successful, but also confused about the motors. The one you used had three cables: Two for power and ground and a third one for the signals. Discovering my Arduino starter kit, I found such a one and a second with power and ground only. I just had bought 5 quite cheap motors and I wanted to use one of them. Unboxing them I discovered that they came together with a small breakout with many pins. I didn’t understood and so I used the one from the starter kit.

But after having finished the sketch and the hardware setup, taking a video and publishing it on the web page, I came back to the different motor types, trying to understand. Unfortunately I never built a model of a car or anything else using motors, because I would have known what I now need to google.

Here’s the result:

There’re (at least) 3 different kinds of motors

1. The „normal“ motor

  • having two cables for the power only
  • turning when powered
  • turning the other way, you must change the cables
  • result: I can’t see any usage for such motors with our caches

2. The „servo“

  • having 2 cables for the power and a 3rd one for the signals
  • usually turning 180° from -90° to +90°
  • turning done by sending the desired angle via the signal cable
  • often used for gearing in models
  • result: useable to e.g. press the baby latch as in SCBC-01 or „The Dancing Cacher“

3. The „stepper“ (or step motor)

  • having 5 or more cables
  • usually driven by a breakout like „ULN2003“
  • 1 rounding of the motor is defined by a certain amount of steps (steps_per_round)
  • to turn the motor, you’re telling him, how many steps to go
  • the direction is given by the sign of the steps
    • if steps_per_round is 100 and you tell the motor to go +50 steps, it will turn 180°
    • if you will tell -25 steps to go, it will turn 90° into the other direction
  • result: useable e.g. to turn a spindle to release a cache fixed with a thread

And here’s my first prototype:

15.12.2015 - again Arduino cheated me

One thing made me crazy… When I told the sketch to turn 360°, I discovered that the motor stopped some few degrees too early. I tried this and that, but without any success. At the end I discovered, Arduino cheated me again:

Schnappschuss (2015-12-15 10.41.35)

Have a look to line 94. Step_Angle is the variable telling how much to turn in degrees. I’m deviding that by 360 for a full turn of the motor and multiplying with the amount of steps the motor is offering for a full turn. The value for the motor I used is 2176.

When Step_Angle is 360, the calculation is 360 / 360 * 2176. The result should be 2176, or? By controlling the value with the serial monitor, I discovered the result was 2160. Hmmmm.

The reason for that is again the silly calculation with integer values the Arduino is performing. By splitting line 94 to two (lines 96 and 97) the result is fine…

16.12.2015 - I’ve optimized the sketch

While working on the sketch I realized a strange behavior: When giving a quite large angle like „ 6*360“ - meaning six full turns - into the sketch, I saw the motor doing only some few turns but counterclockwise. Maybe there’s a maximum of steps the motor can handle and if you’re giving it a value near to maximum (or more than half of the maximum) it’s turning the other way. This might be economical for the motor, but not for our sketches. Thinking about to let the motor turn a spindle with a thread to release a cache container from inside the housing and to keep it back, this never should happen.

So I reworked the subroutine (void) of the sketch like this:


  • First there’s a check (lines 97 - 103) if the speed is within a defined minimum and maximum. If not, it will be adjusted.
  • In lines 105 - 109 the amount of steps is calculated. Because of the strange calculation behavior of the Arduino IDE a logical single line command is split to 3 (lines 106 - 108)
  • In lines 113 - 118 a negative angle is transferred to a negative constant and than the angle is switched to positive. That’s making the following calculations much easier.
  • In lines 119 - 129 first is calculated, if the angle is more than a full turn. 
    • If not, the amount of full turns is set to „0“.
    • If yes, 
      • the amount of full turns is caclculated (line 122) 
      • the amount of remaining steps of the last, not full turn is also calculated (lines 123 - 124)
      • and in the for loop the stepper turns as often as full turns have been calculated
  • Finally the stepper is turning the amount of steps of the non-full turn.
  • At the beginning the angle was made positive. You can see that in line 126 and 130 the also always positive value of the steps is multiplied by the direction, which is „+1“ or „-1“.

I tried is with an angle of 50*360 + 90. The motor became a little bit warm after 50 and a quarter turns, but it worked fine…

29.12.2015 - Starting to think about mechanics

I’m starting to think about the mechanics of building the stepper motor into the housing. I have 6 of them in my „local stock“:

71Lm+gcbZJL. SL1500

step motor 28BYJ-48 with ULN2003 break out


Attached to the motor will be a cardan coupling. Inside the coupling there will be sleeves. On the one side with a 5mm coupling for the motor, on the other side with 3mm for a stainless steel stick:

cardan coupling


sleves (3mm for the stick, 5mm for the motor)


cardan coupling with sleeves inside

51dSulTQXwL. SL1447

stainless steel sticks (3mm, 300 mm long)

The stick will be fixed on the other side by a primitive mount:



 More pictures, especially of the spindle you can find here (at the bottom) ...

4.1.2016 - Some new experiences on powering the motor (1)

While building the „Flame and Water“ cache, I discovered something strange. When the motor should start turning, the LCD became dark for less than a second and the sketch started over from the beginning. Due to the fact that the Arduino IDE already gave a memory warning when compiling, I thought, I need to reduce the memory consumption. So I skipped 2 welcome screens, no warning when compiling and everything worked fine. I put all the electonic stuff back into the housing, closed the rear and invited Tina for a demonstration. But the same shit happened again.

After some thinking I became aware, that with USB connected, everything was fine, but on the batterie (9V block) not. So I checked with a new batterie and everything was fine.

Root cause: If the batterie isn’t fresh and the motor should start, the power goes so low, that it’s like a power off for the Arduino. 

So today I played with a different powering of the motor, which can be used between 5V and 12V. I only connected the 4 pins to the Arduino, while the power came from a separate power supply. This is working fine. No need to think about a common ground. 

With the 5V from the Arduino the maximum speed of the motor is near to 800. This is why I’m using 700 in my sketches. With 12V the maximum is at 1,750 and the motor is really turning quicker. But on the other hand it became so hot that I don’t think the motor would stay alive for long.

With my next cache I won’t use the power out of the Arduino for the motor, but I won’t even not use a second batterie. I’ll try to connect the motor directly to the 9V batterie. Maybe I’ll increase the speed a little bit, maybe not.

12.1.2016 - Some new experiences on powering the motor (2)

My Fire & Flame cache is published since last Saturday and already earned some favourite points. But I discovered a more worse situation as discribed above. Referring to the power of the battery there aren’t 2 but 3 cases and the last one is the worst one:

  • battery is ok = all working fine
  • battery has not enough power for the motor = sketch is restarting instead the motor is working
  • battery a little bet better than above = the motor is starting and releasing the cache. But when the motor should lift the cache back into the housing, it’s not working.

While the second case means, that the next cacher with a good battery is able to log the cache, he’s not with case three. The cache (the thread) isn’t at the start position, so everything would go wrong.

This is why I just looked for an alternate power supply for the motor. Some restrictions I set as a must:

  • should be rechargeable
  • must fit into the housing (only small space available)
  • should give > 5 V (the motor is running with 5 up to 12 V)
  • should have some power (mAh)

At the end I bought for this one:

81digRNiCuL. SL1500

To be honest „one“ is misleading. To be able to have the cache unavailable only for some few minutes when the battery will be down, I ordered two. One will be inside the cache, the other one in „hot stand by“ in my cellar...

To recharge it, I also bought this charger:

71ZFqlxF9fL. SL1500

At the end of the cable of the battery and the charger as well there’re special plugs called „Tamiya connector“. To be able to use them in future I will need to have this connectors also at the cable I’ll use from the battery to the motor. So in addition I bought this adapters.

51YYGRiXh8L. SL1000

I hope, I’ll be able to change the cache to this power setup next weekend...

©  Olaf Goette 2008 - 2022