Stepper motor connected to the arduino

Playing with a stepper motor that I found on the dump (actually, it controlled the hot water valve in our former heating unit, the gear box assembly was removed, but the stepper motor still works fine)

The schematics for controlling a stepper motor with a H-bridge is like this:

The only thing I modified was to use the enable lines of the L298N driver IC, and to pull them high whenever you need to run the motor. If you leave them high all the time then there is a continuous current even if you don’t run the motor, it is this current that unnecessarily heats up the 12V regulator. The library to use is in the arduino examples and works fine. Not a very complicated project so far, so I modified it into something else.

Embedding a stepper motor in a toy project

So, lets do something more complicated, go to the Meccano box and build something that is controlled by the stepper motor, and that generates a feedback signal so that the project gets more “brains”. Motor control projects without a feedback mechanism are usually no fun. A robot should for instance drive to a wall, think about what happened, and then turn around do to something else. What I came up with was a toy crane where the problem is to hoist a load until it reaches the table height, and then to lower it so that it gently reaches the floor, but that it does not touch it. So here it is, the crane project where I count with a detector (an EE-SY310 from lowpowerlabs) the number of turns of the hoist wheel. By doing it this way you avoid the problem of hysteresis that is caused from the pulley that runs from the stepper motor axis to the hoist mechanism. The project could have used a timing belt and a gear box for the stepper motor, but I didn’t have them at hand so that I ended up with this solution.

All instructions are in the project video, the arduino code is actually rather short, and it looks like this:

#include <Stepper.h>

const int SPR = 48;  // change this to fit the number of steps per revolution for your motor                              ;
const int led = 13;
const int motor1 = 3;
const int motor2 = 4; 
const int motor3 = 5;
const int motor4 = 6;
const int counter = 2;    // goes high when the white tab passes the sensorhead 
const int enable = 7;
const int maxturns = 6;  // when the counter reaches 6 we switch direction;
volatile int turns = 0;  // counts the turns of the hoist wheel of the crane
long int nsteps = SPR;

// initialize the stepper library 
Stepper myStepper(SPR, motor1, motor2, motor3, motor4 );            

void setup() {
  // initialize the on motor (it is standard in the Arduino libraries), tune the speed so that 
  // you dissipate the least amount of heat
  myStepper.setSpeed( SPR * 4 );  
  pinMode(enable,OUTPUT);  // Enables the motor driver
  pinMode(counter,INPUT);  // output of the optical counter
  pinMode(led,OUTPUT);     // we love that LED for debugging
  turns = 0;
  // so, when the detector sees the white mark and interrupt is generated on port 2, (this is 
  // an int.0, so the first argument should be zero) the updatecounter function is then called
  attachInterrupt( 0, updatecounter, RISING ); 

void Blink(int length, int ntimes)
  for (int i=0; i<ntimes; i++) {

void updatecounter()
  turns = turns + 1;

void loop() {
  for (int j=0; j<2; j++) {  
    if (j==0) { 
      Blink(1000,1);               // one long blink means we are here
      while (turns < maxturns) {
        Blink(3,1);               // blips for every nstep counts (we need about 70 or so)                          
      myStepper.step(+nsteps*2);  // you want the mark to pass  
      digitalWrite(enable,LOW);   // so we turn a little further
      turns = 0;
    if (j==1) { 
      Blink(1000,2);              // two long blinks means we are here
      while (turns < maxturns) {
      turns = 0;   
      myStepper.step(-nsteps*2);  // you want the mark to pass 
      digitalWrite(enable,LOW);   // so we turn a little further

Last update: 24-dec-2014

A little bit of everything

Top panel: cloud detector output (red en green) and outdoor temperature above a window (blue), middle panel: airpressure, bottom panel: light curve.


There is a little bit of everything in the upper plot obtained from the clouddetector. Up to 50 hours ago we had the November December grey, around -45 to -38 there were some openings in the cloud deck, and soon it closed again until -25 hours when occasionally there were cloud bands until -10 hours. Then we had blue skies until 8 o’çlock this morning when the rains started.

This is a nice website to consider, it shows the results of radiosonde measurements at the KNMI in de Bilt.

Update: 15:00 on 7-dec-2014.

30 Amusing Dutch Words

Fantastische verhaal over eigenlijk rare maar dagelijkse woorden in het Nederlands


Learning a new language can be hard, frustrating even… but it can also be fun. You just have to know where to look.

Luckily for me, you don’t have to look too far to find funny sounding words and phrases in Dutch. Here are some I’ve learnt so far…

1. Apetrots 

My first Dutch WTF moment was watching a film with subtitles when the screen flashed up “Ik ben apetrots op je” literally meaning “I am monkey proud on you.” (The correct translation in English is “I’m really proud of you”.) A brilliant Dutchism… and it’s now one of my favourite Dutch sayings 😀

2. Boterham

Boterham, courtesy of Laura Frame Illustration Boterham, courtesy of Laura Frame Illustration

Literally translated as “butter ham” – it actually means sandwich!

3. Eekhoorntjesbrood

While we’re on the food theme… let’s go with the word for Porcini mushrooms, which literally translates as “little squirrels’ bread”.

4. Eekhoorn

Sounds like…

View original post 607 more words

Putting the melexis 90614 in sleep mode

The answer is, you can’t, or at least, I can not. Already ran circles around the garden, dug a hole, but the thing still consumes happily its 2 point whatever milliamperes whatever you do. And it is a 3.3v version. So, back to the drawing board for the cloud detector and put it behind a timer unit that does allow a low current mode. The timer unit turns the modem plus the i2c melexis on every 5 minutes for 3 seconds, and this improves the battery life by a factor 5 approximately.

This shows the outdoor non-contact thermometer, the timer unit is up north. The battery is the yellow part (a 3.6v cell phone replacement part consisting of three AAA’s), the radio modem #arduino combination from LowPowerLab is the red PCB, and the metal TO-39 pill is the melexis thermopile that sticks through the Hammond box cover.

By cutting the PCB for the timer unit in this shape you can squeeze it in the existing design which is in a Hammond standard box. All control goes via a n-channel mosfet, which is over dimensioned because you could theoretically switch the microwave oven in your kitchen on and off with this one. But I had it unused on the shelves somewhere.

Backside of the timer unit, should be a standard thing if you ask me on a experimenters board. I’m in general not happy with timer units, but I saw no other solution for this experiment.

Upper left: outdoor temperatures (blue is NTC above a window, red is NTC furhter away, green is IR temperature) Upper right: light outside Lower left: IR temperature living room, Lower right: air pressure
Upper left: outdoor temperatures (blue is NTC above a window, red is NTC further away, green is IR temperature)
Upper right: light outside
Lower left: IR temperature living room,
Lower right: air pressure

And as we write the weather starts to improve, because, the green line in the upper left plot shows that we are getting clearer skies (a delta temperature greater than 3 degrees indicates this). Occasionally some clouds are passing by.