Building a Speedometer for my Dog

TL;DR: I built a Persistence of Vision speed indicator for my dog, using an Arduino, a few LEDs and resistors, and less than 40 lines of code. This is the story of the process and results.

The beginning

I’ve had an arduino for ages, but didn’t really have a project that I wanted to build. Then, at the end of 2012, I had an idea: Why not build something interesting and a little bit crazy? Thus, the dog speedometer was born.

Pippi being enthusiastic about squirrels

Our dog, Pippi, a Jack Russell of sorts, is always brimming over with enthusiasm and happiness. One day, watching her tearing through the garden, I started thinking about how to measure how fast she runs.

There are many ways to measure speed, but I wanted something very simple with a visual indication. I’ve always liked Persistence Of Vision displays, and thought that showing her speed using a POV display would be cool. Since a POV display has to be attached to something that’s moving, it would work well if the display could show how fast it’s going.

The idea

I’m always looking for ways to get functionality out of the minimum amount of hardware, so options like gps and inertial measurement were right out.

Slowly the idea formed that the display itself could be the speed measurement.

Hi spelled out in sweeties in a POV way

A POV display works by moving a line of LEDs and lighting them up with exact timings so that they leave an after-image in your sight. The stop-motion example above shows the white line of sweets representing the LEDs and the blue ones showing the after-image if they are lit up in sequence.

Since it’s a POV display, could I skew the line of leds and time the signals so that they only line up at specific speeds?

Same light sequence, different speeds

This stop-motion sequence shows the basic idea: Skew the line of LEDs to an arrow shape. All the arrows are flashing the same pattern with the same timing, but they are moving at different speeds. The middle line is moving at a speed that results in a perfectly straight line. The top line is moving at half that speed, and the bottom line is moving at 1.5x the speed.

Experimentation

There was a regular weekly maker meetup at the local university. At one of these nights, I implemented a simple version of the board to demonstrate the idea.

Breadboard build

The initial build was very crude, built on a breadboard.

Google is a great calculator

I programmed it to show the numbers 1-9 in sequence. Each number is shown at a slightly different rate, so that the undistorted number would be the speed I was moving at. Breadboard spacing is 1/10th of an inch and the LEDs are placed 2 holes apart, so an 18ms delay is roughly equivalent to 1 km/h.

# The binary sequence to output to the port for each number.

byte one[] = {B0, B10001, B1010, B100, B0};
byte two[] = {B10001, B10011, B10101, B01100, B100};
byte three[] = {B100, B100, B10101, B11011, B10001};
byte four[] = {B100, B1100, B10100, B1010, B10001};
byte five[] = {B10001, B11001, B10101, B110, B100};
byte six[] = {B100, B1110, B10101, B10011, B10001};
byte seven[] = {B0, B0, B10100, B11010, B10001};
byte eight[] = {B100, B1110, B10101, B11011, B10001};
byte nine[] = {B100, B1100, B10101, B11011, B10001};
byte zero[] = {B100, B1010, B10101, B11011, B10001};

int i = 0;

# Prep the output port

void setup() {
  DDRD = 0xff;
};

void loop() {

  # One is shown at 18ms delay.

  for (i=0; i<5; i++) {
    PORTD = one[i];
    delay(18);
  };

  # Two is shown at 9ms delay.

  for (i=0; i<5; i++) {
    PORTD = two[i];
    delay(9);
  };

# ------------------- etc.

The program above is shortened for clarity. Note that those binary sequences are the reversed ones (see the inverted arrow of the next build).

Walking at different speeds in a corridor

I took it out to a dark corridor and did a few tests. I walked along at different speeds, with the result showing in the separate lines. The top one shows a faster walk.

Note that in all these lines, the flashing sequence is exactly the same. What you see depends on the walking speed.

Also, at this point I did not know about the Arduino microseconds timer, so it was all milliseconds.

More permanent build

Having proved that it worked in principle, it was time for a bit more robust build.

Some things I noticed from the test build:

  • The arrow idea works, but it points the wrong way. I would like the skewing to point towards the correct value, not away from it.
  • The arrow shape needs to be more pronounced, otherwise the result is very skewed in the slow direction, but almost straight in the fast direction.
  • Since a slow speed indication takes up a lot of space, it’s best to pick a range of expected speeds so that the slowest speed does not take up several meters to render.

For the final run I chose a speed range of 10 to 30 km/h. Showing every value in that range would also take up too much space, so I picked a simple scheme: I would show a vertical line representing 10km/h, the number 15 to represent 15km/h, another vertical line for 20km/h, 25km/h as a number, and a line for 30km/h.

It should look something like this:

1 15 1 25 1

(but skewed, of course)

Business end of the board

The build itself was done on a simple piece of veroboard. The hole spacing is 1/10th inch, and the build is simple enough for an out-of-practice solderer like me. The button is actually not needed.

Soldering horror

If the veroboard build uses only a few pins, you can leave out the weirdly-spaced ones on the one row of the Arduino, so you don’t even have to bend any pins.

I have larger photos and v2 code up on github:

https://github.com/jbeyers/speevo

Test run

She did not like this

Pippi was not crazy about wearing the harness. We had real trouble getting her to run while wearing it.

Going for a run

Success! Running at about 20 km/h.

Results

  • It works! You can get a good speed indication to within 1 km/h.
  • You need a camera to really see the result clearly. The speed shown is too slow for a good POV effect.
  • If you want to use a normal camera, you have to shoot in low light so you get a long exposure. I used CHDK on a Canon camera to get a long enough exposure.
  • Obviously, this only works with an object moving from left to right.
  • It should work well on bicycles, rc cars, drones and merry-go-rounds.
  • Less than 40 lines of code in total. This is a really simple project.

Video

I made a demo video of the speedo in action. Not on the dog, but on a special rig I built to show the principle.

https://www.youtube.com/watch?v=dlEagnvZ-Sk

Future

I had planned to do a custom board design and some other refinements, but I got distracted with some other projects. I may still do this.

Impressions of Beijing

Our family went on a 10-day trip to Beijing at the beginning of October. I won’t give a blow-by-blow account, just note some of my impressions.

We were invited by Astrid’s parents, and stayed with them. Her father is a guest professor at the Beijing Forestry University for a few months each year. While we did all the touristy things, we had a chance to experience some aspects of Beijing city life that the typical short-term tourist does not see.

Since we stayed in Beijing except for an outing to the Great Wall, our experience is limited, so these impressions should be taken in that context.

Pollution

The first few days we had good weather. Since it was their National Day Golden Week holiday, most of the factories were closed or not running at full capacity.

Towards the end of our stay, we saw how bad the pollution could be. Levels reached heights that only happen once or twice a year. The smog was so bad that most people wore masks. Apparently the masks do not help much. Visibility was down to 50-100 meters, and the sun looked like a red, angry moon.

The Chinese are very aware of the problem, and in conversations I got the idea that they consider cycling, electric bikes and public transportation as a duty to lessen it. However, this fact alone would deter me from spending a large amount of time in big Chinese cities.

Transport

On the streets, I was immediately struck by the amount of electric bicycles, mopeds and cargo trikes. Maybe one out of several thousand mopeds are powered by internal combustion. The cargo trikes, being mostly older and probably used for a much larger part of the day, were mostly non-electric. There were also a lot of electrified bicycles, consisting of a lengthened frame with space for a battery pack and an extra seat at the back. The battery packs are removable and are plugged into mains power for charging. Altogether a great system.

Cycling is also big, helped by the fact that Beijing is pretty flat. The underground is fast and cheap (2 yuan per trip irrespective of distance), so pretty full.

Cars are only allowed on the road on alternative days, determined according to the number plate. Apparently rich people have 2 cars to enable them to drive any day.

The traffic is chaotic. People push in front of you whenever they can, and give way easily. This actually results in remarkably smooth-flowing traffic, since it’s all predictable: There is no hesitation, trying to figure out what the other person will do: They will take any gap, without hesitation. The cars, bicycles and people intermingle and flow.

People

I found the chinese people very friendly, and very curious. The fact that Caucasian people are a relative rarity, and that we were generally the tallest people in the room, probably contributed to that. People asked us where we came from, asked to pose with us for photos (mostly with my daughters), and were clearly curious.

We spent one Friday evening at the Renmin University English corner, where people come to practice their english. We were questioned about our lifestyle (do we have cars?), animals (We are from Africa, after all), and on our impressions of China. Seems that the people are very proud of their country, with a strong desire to grow China as well as themselves.

Workdays are long, and many people work 6 or 7 days a week.

Food

We ate many things, a lot of which I could not identify. Staple is rice, with usually some stew over it. There is a lot of mushrooms and tofu, and some vegetables. We actually had donkey meat once.

The custom seems to be to have enormous amounts of food. Several times I could not finish a meal, even a takeaway, and this is something that happens very seldom to me. On the occasions we were invited to a meal by Chinese people, we generally managed to eat at most half of the food on the table. This is a cultural thing: Eating all the food implies that the host is stingy...

Food in general was cheap, except for Western fast food. Coffee is hideously expensive.

Although we had stir-fried food on occasion, I got the impression that food is mostly boiled or steamed, with very little of the panfried tastes that westerners are used to.

We never saw any seasoning like salt and pepper anywhere. The food usually comes with a sauce, which is spicy/tasty enough. I did miss the pepper on fried egg, though.

I think that the food has a lot less fat than Western food. The Chinese are generally slim, and the only dangerously obese people I saw were Western tourists.

Excercise

This is not a priority. From conversations I gathered that the concept of excercise for health is very foreign to the Chinese people.

On the other hand, a lot of people use public transport or cycle, which leads to a minimum of physical activity much higher than a car-bound western lifestyle. Maybe this is another reason you don’t see fat people.

Culture and history

This was simply astounding. It is weirdly different to the feeling you get in Europe. In Europe, you see various churches and cathedrals, in all kinds of different styles that indicates their relative ages.

In China, I was struck by how similar all the palaces and temples were. This starts to feel boring for a while, until you realise the implication: These people had a very consistent culture and way of doing things for a long, long time. It seems like their history is a lot more cohesive than western history, which makes you realise that the current communist government is a mere blip in their history.

Shopping

Of course, China can be a shopping experience of note. Since I’m not into many of the typical wares available, I found the shopping not as enjoyable as I would have liked. I think it helps in bargaining to know some Mandarin.

Conclusion

This was a fascinating trip. We saw, did and experienced so much, and came back enriched by the experience. Seeing a different culture and way of life both broadens my perspective on my own life, and makes me very glad to be living where I do.