DRT Pi - a Lesson on Distance, Rate, and Time




Introduction: DRT Pi - a Lesson on Distance, Rate, and Time

The Raspberry Pi (Pi) is a powerful tool that may be utilized for many things in the classroom, but once it is paired with the Raspberry Pi Sense HAT, it truly opens the door for classroom integration. The Raspberry Pi Sense HAT is armed with many features which one may utilize to help bolster a more traditional lesson through hands-on interactivity.

This lesson plan visits the concepts of Distance, Rate, and Time and how they interrelate. I’ve developed a script which utilizes the Sense HAT’s on-board magnetometer to detect magnetic changes/ similarities. On completion, the script’s job is to hand the user a variable for Time. To get the variable for Distance all one really needs is a ruler.

Simply put, it’s possible to utilize these things to push a car (with a magnet attached) down a track (composed of or measured by the ruler) and have the Raspberry Pi/Sense HAT (stationed at the end) give the user how long it took for the car to reach the end of the track. In measuring these two variables we are then able to come to the final variable, Rate.


Step 1: The Lesson

This lesson is aimed towards students in fourth to eighth grade but is certainly able to be utilized elsewhere.

The teacher should begin by conveying the necessary information related to the topic at hand (Distance, Rate, and Time). This is supported by providing the students definitions for each of the concepts, the formulae, and providing/ explaining the concept behind the DRT Triangle. Feel free to change it up and have students look up the definitions online, or to pull definitions from your own curriculum. An example set of information has been provided in the DRT Pi Lesson Notes document that is attached.

Armed with this information, students should be given a worksheet to help master these concepts. A worksheet has been provided (Attached as DRT Pi Worksheet), however, feel free to create your own. The beginning of the worksheet will/ should allow the students to demonstrate their understanding of the core concepts. The second part of the worksheet is the lab portion and will allow them to be a bit more interactive and creative with the concepts.

Step 2: Lab Procedure

  1. Split the class into groups of two to four.
  2. Hand out the worksheet that goes with this lab.(The worksheet and the answer key have been attached to this Instructable)
  3. During the lab portion the missing variables will be obtained by completing the experiment.
  4. Rotate the groups through the lab. While waiting to get the group’s variables, the groups who are not experimenting should discuss/ work out the questions on their worksheets.

Additions are suggested in the DRT Pi Lab Instructions document attached to this Instructable

Step 3: Readying Your Raspberry Pi

This Instructable does not go into how one assembles their Raspberry Pi. It only details using a script that was made for this lesson, which utilizes the Raspberry Pi and Sense HAT.

Guides that can help you with setting up your Raspberry Pi may be found at the following:



A guide that can help you with the Sense HAT may be found here:


You may buy a complete kit for the Raspberry Pi that has Raspbian pre-installed, then it’s simply a matter of placing the SD card in the Pi and attaching the Sense HAT.

Purchasable examples:

CanaKit Raspberry Pi 3 Complete Starter Kit - 16 GB Edition:


Sense HAT is also on Amazon:


The complete kit is not the most optimal way financially, but it should make things easier.

Step 4: Readying the Car

For this lab you’ll need a toy car (such as a Hot Wheels or Matchbox car) and a magnet (use something like a disk magnet used for crafting).

Attach this magnet to the roof of your car.

The car pictured here is just a car that was purchased in a pack at a dollar store. It’s recommended that you get a better-quality toy car than this.

Step 5: Downloading/Getting Magcar.py on to Your Raspberry Pi and Using It

You may get magcar.py by downloading it here (above) or you may get it from here: https://github.com/MacJM/magcar.py

If you download it from the github link, see the image above for how to download this file. Once it's downloaded unzip the folder to retrieve the file.

you can download it straight to your Pi or move it over with a USB. Either way, make note of where it’s located.

Using magcar.py

Once you have the Pi with the Sense HAT module up and running, you’ll be using the magcar.py script. This is something made just for this lab.

Place this file where you’d like on your Raspberry Pi, examples may be in Documents, Downloads, or Desktop.

Open the Terminal, Ctrl+Alt+T.

Following the previous examples, type either ‘cd ~/Documents’, ‘cd ~/Downloads’, or ‘cd ~/Desktop’ in the terminal to change directory to the magcar.py location.

While in this directory, type ‘python magcar.py’ to initialize the script.

If you followed the photo and input ‘python -i’, Ctrl + D to exit out

Step 6: Running the Experiment

Set up a track for the car to move down. Make sure to measure it or just build it with a ruler. This will give you the Distance variable.

Place the Raspberry Pi w/ Sense HAT at the end of your track and run magcar.py. Follow the Instructions given in the terminal for the procedure. Instructions are also listed here:

  1. Clear the area around the Pi and letting it sense/ print what it senses into the terminal.
  2. Put the car next to the Pi (where it instructs) and let it set variables based on what it senses.
  3. Clear the area around the Pi again and continue
  4. When it prompts you to, place the car at the beginning of the track
  5. When you’re ready to go press enter (as is prompted), get ready on red, and push the car on green

Once this is been correctly followed you should be given how long it took for the car to make it down the track. Which you’ll be using for your Time variable.

Then you’ll be able to solve for Rate

If you are having issues, please read the attached document (DRT Pi Lab Instructions) for more detail on this process. There are also some suggestions for how to solve issues you may come by.

Step 7: Recap and Conclusion

In closing, I’d like to revisit the Raspberry Pi Sense HAT. Once this system is assembled there are many other experiments you can do with it, not just the one included in this lesson plan. The Sense HAT is equipped with the following sensors: Gyroscope, Accelerometer, Magnetometer, Temperature, Barometric pressure, and Humidity. It’s also been made relatively easy to pick up and learn the programming portion involved. If you have any ideas for ways to utilize these sensors, give this system a try.



Classroom Science Contest

Participated in the
Classroom Science Contest

Be the First to Share


    • Block Code Contest

      Block Code Contest
    • Battery Powered Contest

      Battery Powered Contest
    • Plywood Challenge

      Plywood Challenge



    1 year ago

    Looks like a fun STEM lesson! Thanks for sharing!