Pi-Powered Speedometer
Year
2024
Involved
Computer Science
Basic Physics
Credits
James Maclennan
Project Idea
When my Dad gave me his old Raspberry Pi 3b Microcomputer (from 2016), I wanted to make the most out it. Since me and my friends had the hassle of tracking the karts speed via GPS, I thought making a real physical tracker, with maybe an infrared or a magnetic sensor, would be a really nice feature for the kart. Especially since Raspberry Pi mini-screens offer a nice interface for the driver. So I got to work!
Basic Setup
The setup consists of an infrared-laser, reflective tape, powerbank, raspberry pi 3b and an mini-screen. As seen in the video, I decided to place the screen in the steering wheel and the made the cables go from the powerbank along the chassis all the way up into the steering wheel.
The Sensor
This was a hard choice to make: I was looking for accuracy, reliability and compatibility. At first, I bought a magnetic sensor, the MLX90393. The idea was to have a magnet (on the axis) pass through the sensor, that was attached slightly above the axis. But after hours trying to get it to work, I realized what issue had occurred. After I wrote a script to check at what rate it could actually sense a magnetic field, it turned out to be a measly 7hz. And for accurate measuring I would at least 50hz.
So, I turned to industrial sensors: more performance, but at the cost of less compatibility. I did some research and found out about a sensor called the E3F-DS30C4. It was not made for Microcontrollers, but theoretically it could work. The sensor releases a 12V output when it picks up it's own (reflected) infrared signal. And a Raspberry Pi has GPIO pins that detect electric currents. But since they detect 3.3V, I had to calculate which resistors where required to reach the desired current. Eventually, after failing with the other sensor, I had figured a way to do it differently. So, I put everything together and soldered the wires … and it worked!
Python-Code
The idea behind the python script is pretty simple:
Detect when the GPIO pin receives a signal
Calculate time between current and last signal
Calculate current speed (speed = distance / time)
Display the speed
Using PyGame for the graphics, GPIO for the sensor and the time package, I started writing the Python Code. But something didn't work: it kept showing lightning fast speeds. So, after about an hour of trying to figure out what was wrong with my setup I realized that my Raspberry Pi would detect false GPIO signals, when the voltage, powering it, wasn't sufficient. Thereafter I switched the faulty Micro-USB cable for a better quality one, and it worked!
