STEAM DISCOVERY LAB
  • About
  • Tools
  • Projects
  • Resources
  • About
  • Tools
  • Projects
  • Resources
Search

Micro:Bit Car Kinematics

Picture
Lesson Objectives:
  1. Students will learn about numerical integration
  2. Students will learn about relationship between position, velocity, and acceleration
  3. Students will learn to write data to files

Materials:
  • BBC micro:bits
  • Laptop with Mu Software 
  • Assorted LEGO pieces to construct a cart
​
Let's Get Started!
​
As you may know if you've taken physics, velocity is the derivative of position and acceleration is the derivative of velocity. Conversely, velocity is the integral of acceleration and position is the integral of velocity. So, if you know one of the three, you can calculate the other two. Micro:bits have an accelerometer built-in, so you can easily measure the acceleration a micro:bit is experiencing.  If you apply numerical integration to the accelerometer data, you can calculate the velocity and position of the micro:bit. 
​
​Goal:
Create a micro:bit program that measures the micro:bit's acceleration and integrates it to determine velocity and position. All of this data should be repeatedly recalculated and logged to a text file. 
​
Construction:
Build a small cart out of LEGO pieces (or anything else you can find). The micro:bit and its battery should securely mount to the car with one axis of the micro:bit's accelerometer aligned with the direction of motion.  If you want to use the cart with photogates, make sure at least one side of the it has an opaque wall. See the picture at the top of the page for an example. 

Also consider how you want to test the car. You may want to create a ramp or race track of some sort.

Numerical Integration:
You may have heard integrals referred to as the 'area under the curve'. Numerical Integration tries to approximate this area. The simplest way is to add together the areas of a lot of rectangles of height equal to the value of the function at that point and a width of the time step, dt. In other words, it is the measurement value * time since last measurement + previous integral value. 
More Information

So,
velocity = velocity + acceleration * dt
position = position + velocity * dt

You will want to create a function that that takes acceleration, dt, previous velocity, and previous position as inputs. It should calculate and return new velocity and position values. 

Code Structure:
The structure for this code is similar to the Micro:bit Pendulum. Take a look at the instructions and code from it. The basic structure is:
  • Collect measurement
  • Perform calculation on measured data (In this case, Numerical Integration)
  • Write data to file
  • Repeat
This should occur between from when one signal is received until another signal is received. The simplest signal to use is button presses on the micro:bit. 
Car Motion Integration Code

    
​Improving Integration:
If you look at your results for this project, you'll likely see that they are not very accurate. There are two major contributing factors:
  1. The micro:bit accelerometer - the micro:bit's accelerometer is fairly inaccurate and noisy. While you cannot entirely solve this problem, you can reduce its effect by filtering the data. One filter you can use is called a median filter.
  2. Numerical integration - Numerical integration is an inherently error-prone process. However, rectangular numerical integration is the least accurate method. A more accurate method of integration can be used, such as trapezoidal integration.  
You can try modifying your code to implement these techniques and see if it improves your results

Combining with Photogates:
You can combine this project with the Micro:bit Photogate project.  You can either just test your car on a track with photogates to compare your results or use the photogates to send a start and stop signal to the car to control the time period that the numerical integration code is run for. Code for this is included below. 
Car with Photogates code

    
Start Photogate code

    
Stop Photogate code

    
References
The following functions and documentation may be helpful.

The full documentation may be found here:
  • https://microbit-micropython.readthedocs.io/en/latest/microbit_micropython_api.html​
Useful Functions
microbit.running_time()
​
Return the number of milliseconds since the board was switched on or restarted.

microbit.accelerometer.get_y()
Get the acceleration measurement in the y axis, as a positive or negative integer, depending on the direction. The measurement is given in milli-g. By default the accelerometer is configured with a range of +/- 2g, and so this method will return within the range of +/- 2000mg.

Picture
200 Boston Ave, Medford, MA 02155
steamdiscoverylab@gmail.com
Center for Engineering Education and Outreach
​Tufts University
About
Tools
Projects
Resources
​
Contact
LEGO®, the LEGO® logo, the Brick, MINDSTORMS®, and the Minifigure are trademarks of ©The LEGO® Group. On some parts of this site  you will get access to so-called “developer software”, which offers documentation on different ways to operate the LEGO® Education SPIKE™ Prime Hub and technology. Whatever use you make of the developer software, bear in mind that the results are not experiences that the LEGO Group endorses, is with or will be liable for. No rights in or to trademarks of the LEGO Group are implied or given, and you may not apply to or register any protection anywhere in the world for intellectual property or industrial rights or similar in respect of any developer software, derivative or other result achieved through its use. The developer software is made available “as is” and, to the extent possible, no warranties or representations are implied or given in relation to it by the LEGO Group. It’s your responsibility to ensure all uses that you make and enable others to make comply with all applicable laws and best practices. By accessing the developer software, you acknowledge that the terms and conditions set out above and in LEGO Education’s terms of use for SPIKE Prime apply.
  • About
  • Tools
  • Projects
  • Resources