3.4.2
Odometry System Design
Odometry System Design
What to expect
In this activity, you’ll explore how a typical odometry system for bikes and scooters works, then build your own version that you can compare with the main digital control system on the e-scooter and another off-the-shelf solution.
Connections
When will I get there? How far have I gone?
You can’t answer these questions unless you can answer this one: How do you know how fast you are traveling?
To determine wheel speed, you must calculate the distance the wheel travels in a set amount of time based on its size (circumference) and how fast it rotates (Revolutions per Minute – or RPM). Speed is the distance traveled per unit of time. For a wheel, the distance traveled in one full rotation is equal to its outer circumference.
The basic formula is: Speed = Circumference X RPM
Circumference is the distance around the tire.
RPM is how many times it goes around per minute.
Image: ExplainMyBike.com
A bicycle or scooter odometer works by using a small magnet attached to a wheel spoke and a “Hall effect” sensor mounted on the frame. Every time the wheel completes a full rotation, the magnet passes the sensor and sends a brief electronic pulse to the computer on your handlebars. This system acts as a digital counter that tracks exactly how many times the wheel has spun throughout your ride. To convert those counted spins into a distance you can understand, the computer uses the wheel's circumference, which is the total distance around the tire's outer edge. This measurement is found using the formula Circumference = pi times diameter. By multiplying the total number of "counts over time" from the sensor by the wheel's circumference, the computer calculates and displays your total distance in meters or miles.
You’ll work with this technology in this activity!
Materials
Micro:bit w/battery pack (2 x AAA)
Hall effect sensor (Reed switch) + magnet
Alligator clip wires or alligator w/ fork terminals wires
Fasteners for fork terminals
Bike computer w/ Hall effect sensor cable & Spoke Magnet
Instructions
Part 1: Exploring the Bike (eScooter) Trip Computer
Locate the off-the-shelf trip computer.
Experiment by moving the magnet in front of the sensor. Notice that speed and distances change. (Refer to the user manual for more information on settings.)
You can put this away for now. You can add it to the eScooter later if you want, but the tech is already built into the display controller.
Part 2: Understanding How the Technology Works
Connect the alligator or alligator w/ forks wires to the Micro:bit as shown. It doesn’t matter which wire connects to which pins, but one should connect to P1, and the other ring should connect to 3V. The sensor acts like a switch, turning P1 on and off as the magnet passes by.
Micro:bit Programming
In example A, a variable called “count” has been created, and every time that the magnet passes near (does not need to touch) the sensor (connected to p1), you can see the count value increase in the serial monitor (make sure your computer is connected to the microbit while you test this.) In example B, pressing the A button resets the count back to zero. Use this program to test your hardware before moving on.
Next, we will determine how fast the sensor is changing and, for now, call it “count per minute” (CPM). (Note: Our goal later in this activity is to apply this to the wheel of the eScooter, and we will be thinking in terms of revolutions per minute or RPM). Add the following code:
In example A, a variable called ‘startTime’ is set to running time (ms). You can find this block in the input (more) library. This creates a starting reference point for time, and running time is how long the microbit has been powered on. In example B, a variable called ‘timeDifference’ is set to running time minus startTime. Now, as the magnet passes by, you can see the total count, and when it occurred relative to a reference point (startTime).
When you test this (connected to the device data by passing the magnet over the sensor, or clicking on P1 in simulator data) you should see something like this:
To keep track of a certain number of sensor changes over time, add the following to your program. Test it out to see it working.
Hint: While testing things out, a minute can feel like a lot longer! Consider adding some “debugging” code like this, to simulate a minute has passed at any give time:
Now that you have a count over time (CPM), you can create a formula to estimate the “speed” based on a shorter time. This is called extrapolation. For example, 10 counts in 6 seconds can be extrapolated to a reasonable estimate of 60 per minute (a minute it 10 x 6 seconds).
Apply the following changes to your program and test it out. (Hint: a new variable ‘speed(CPM)’ has been created, and some math has been adjusted to account for 6 seconds vs. 60 seconds – in millisecond units…)
Create a function called ‘CircumferenceCalculator’ that, when called, will take a set diameter and return the circumference in the same unit. Note: This example shows ‘20’, which could represent a 20–inch wheel… If the diameter is in inches, the resulting circumference will also be in inches.
Add the following to display your distance, based on circumference. Note: Since no wheel is connected at this point, this is just an example to show how it all fits together. As you test things out from this point, try not to go too fast… Try to move past the sensor no more than once per second (in real time) so that you can see how the number changes.
If your distance is in inches, the resulting values are inches per minute (IPM).
For example, you might see something like this, which shows 3 passes of the sensor (in the 6-second time period, multiplied by a factor of 10 to extrapolate to 60 seconds – or 1 minute!) and a total distance of 188.4 inches, which would be 3 times the circumference (20 x 3.14 = 62.8).
What is your speed in miles per hour (MPH)?
To determine your speed in MPH, you’ll need to convert inches to miles and minutes to hours… Hint: create an ‘IPMtoMPHCalculator’ function and call it when you report the results in the serial monitor.
Suggestions for Going Further
Create a method for switching between metric and imperial units (e.g., meters vs miles/ feet).
Create a method to track the total distance covered (like a car's odometer).
Add a way to reset this and/or create a “trip” function that only tracks selected trips
Develop a method of connecting time and date (such as using the extension PXT Time and Date) in your solutions
Develop a method for using additional sensors on the micro:bit in your solution to record and collect “trip data” (e.g., accelerometer, temperature, sound).
Use the alligator cables with fork terminals (like you used for this activity) to connect to the micro:bit and the sensor cable from the off-the-shelf unit instead of using the small controller it comes with – you can use your micro:bit!
Wrap-up
You’ve just learned how the “trip computer” works on most bikes and scooters. What surprised you about this technology? We’ll revisit this system in a later activity…
Next Activity
We will explore how the gamepad controller can be used as a handlebars interface to display data and broadcast signals that interact with other systems in your Smart Scooter Rider System.