Friday, November 5, 2021

Cheat on your pedometer

For an index to all my stories click this text

Autumn is here. It is getting cold and rainy outside. Not really inviting to do your dayly portion of running. Nevertheless you need to keep your moyenne up. So how about a way to have your pedometer count numberous steps without getting away from the cozy warmth of your fireplace.

Last year when a friend visited me he had one of those stupid health watches with a pedometer. They cost a fortune and it is (for me) unimaginable how many people have them and don't know how they are fooled. To demonstrate this I asked for his watch, took it in my hand and shook it several times. "Hey look, you just did 20 steps while sitting on the couch"

And a bit later my girlfriend got a cheap health watch as a present from some marketing company. And then a few months ago I saw a so called smart watch with pedometer for just a few dollar at a shop. I had an idea and just could not resist.

What if I could build a device that would automate the steps.

In 2014 I wrote a story about some cardboard tubes I collected from my job. I used them as a storage and as piggy-bank. I kept some of these. http://lucstechblog.blogspot.com/2014/11/spacers-also-to-be-used-as-piggybank-at.html

I cut of a piece of about 4 cm and put the watch on that. Then I started rotating the tube and presto steps being made !!! Now the only thing to do is to put a motor on it.



So I started by designing a cilinder with a bottom in Tinkercad. The height is 3 cm and the circumfence is 6 cm. The wall is 3mm thick which is sufficient for holding a watch.



I sliced the watch and 3D printed it. Then I put a horn on the servo and glued it with my hot glue gun.

I decided to use a Raspberry Pi Pico for this project and wrote some test software in MicroPython. The software just made the servo step from 1 to 176 degrees, wait a second and then loop backwards. I held the servo in my hand an started the software. That did the trick !! Steps were made !!



Next a prototype of a frame was made in cardboard and the servo was mounted on it.



This is how it looks from the front.



And here is how the watch is mounted.


And when the prototype worked I reproduced the frame in Tinkercad so it would look nice overall


For those who want to download the frame for their own purposes above is the Tinkercad Link.

The electronics.

For this project I used a Raspberry Pi Pico. The setup is just simple.



A servo is connected to the Raspberry Pi Pico's GP13 and a button with a pull-up resistor is attached to pin GP14. For the servo I used a simple SG90. There is not a lot of weight

As the pico can not supply enough power to run the servo I attached a seperate power supply through an USB adapter.

You can find more information on the Raspberry Pi Pico in my book which is world-wide available through Amazon. The details about this hardware setup (not the actual project though) can be found in this book.


 

https://www.amazon.com/Raspberry-Pico-Simplified-Luc-Volders/dp/1329449533/ref=sr_1_1?dchild=1&keywords=raspberry+pi+pico+simplified&qid=1631477904&sr=8-1

The software

The first program is just a simple program written in MicroPython that has the servo constantly turn from 3 degrees to 176 degrees and back. The button is not needed as you can only start and stop this program by applying or cutting the power.

import machine
import time

servopin = machine.Pin(13)
servo = machine.PWM(servopin)
servo.freq(50)

min = 1400 # Tweak this
max = 7500 # Tweak this

diff = max - min
degrees = int(diff / 179)

while True:
    
    angle = 3
    step = min + (angle * degrees)
    servo.duty_u16(step)
    time.sleep(1)

    angle = 176
    step = min + (angle * degrees)
    servo.duty_u16(step)
    time.sleep(1) 

This program works and is enough to get you as many steps as you want. However you cant stop to have a look at the watch to see how many steps it registrated.
So I build a bit more advanced program.

import machine
import time

pushstart = machine.Pin(14, machine.Pin.IN)

pinstart = 0;

servopin = machine.Pin(13)
servo = machine.PWM(servopin)
servo.freq(50)

min = 1400 #tweak this
max = 7500 #tweak this

diff = max - min
degrees = int(diff / 176)

def keypress(dummy):
    global pushstart
    global pinstart
    if pushstart.value() == 0 :
        print ("button start")
        pinstart = 1 - pinstart
        time.sleep(0.2)
        
pushstart.irq(trigger=machine.Pin.IRQ_FALLING, handler=keypress)        

while True:
     
    if pinstart == 0:
       angle = 3
       step = min + (angle * degrees)
       servo.duty_u16(step)
       
    if pinstart == 1 :   
       angle = 3
       step = min + (angle * degrees)
       servo.duty_u16(step)
       time.sleep(1)

       angle = 176
       step = min + (angle * degrees)
       servo.duty_u16(step)
       time.sleep(1)   


This program uses the button to start and stop turning the watch. Pressing the button starts the sequence and pressing the button again stops it. The detection of the button is done by using an interrupt. This way you can stop the servo, have a look at the pedometer, and if needed start the servo again by pressing the button.



https://www.amazon.com/Raspberry-Pico-Simplified-Luc-Volders/dp/1329449533/ref=sr_1_1?dchild=1&keywords=raspberry+pi+pico+simplified&qid=1631477904&sr=8-1


If you want more information on programming the Raspberry Pi Pico with MicroPython have a look at my book. It starts with a course on programming with MicroPython and has information and examples on how to use many different sensors and actuators.

Using different watches.

I tested this setup with several watches with a buid-in pedometer. Some watches needed to be attached on top of the cilinder like in the photo. Others needed to have the watch start at a horizontal position. But all had the pedometer working while I was sitting after my desk. Before building this, test what works best for you.

You cheating devil.

Put the watch on the contraption. Go sit in the garden with a good book and a drink, or visit your local pub or whatever, and after an hour or brag to your friends or partner on how many steps you made !!!!

I had great fun in designing and building this project and even more when I demonstrated it to some friends.

Till next time
Have fun.

Luc Volders