Skip to content

Activité

Compteur de pas sensible

Intermédiaire | MakeCode, Python | Accéléromètre, Écran LED | Capteurs, Conception du produit, Corps humain, Forces, Outils de performance

Étape 1 : Maîtrisez

Qu'est-ce que c'est ?

Un compteur de pas que vous pouvez rendre plus précis en l'adaptant à votre propre style de marche.

micro:bit attaché à la chaussure

Ce que vous apprendrez

  • How the micro:bit can collect numerical acceleration data
  • How to apply thresholds to sensor data to trigger events like increasing a step counter

Comment ça marche

  • The Step counter and Low energy step counter projects use the ‘shake’ gesture to count steps. The 'shake' gesture uses several accelerometer sensor readings to decide if the micro:bit has been shaken.
  • You may find that the ‘shake’ gesture isn’t triggered every time you take a step, or that it’s triggered too easily, leading to inaccurate counting of steps.
  • To make a more accurate step counter, instead of using the ‘shake’ gesture, this program uses numerical data from the accelerometer to decide whether you’ve taken a step and, if you have, increase the steps variable by 1.
  • If the acceleration is greater than (>) 1500, the steps variable is increased by one and show the step count on the LED display output. 1500 is the threshold – the point at which a movement will trigger a step to be counted.
  • You may need to change the 1500 number to make the step counter more accurate – but you can decide what threshold to use, whereas with the ‘shake’ gesture the threshold has been decided for you by the people who designed the micro:bit.
  • Modifying the threshold to work for you is called calibration.
  • Note that when micro:bit is not moving, the accelerometer gives a strength reading of about 1000. This is caused by the Earth’s gravity pulling down on the micro:bit.

Ce dont vous aurez besoin

  • micro:bit (ou simulateur MakeCode)
  • MakeCode ou éditeur Python
  • un boîtier de piles (optionnel)
  • something to attach the micro:bit to your shoe or leg – string or Velcro.

Étape 2 : Codez

Étape 3 : Améliorez

  • Make your batteries last longer by changing the program so it only shows the number of steps when you press button A.
  • Modifiez le programme de sorte que le bouton B réinitialise le compteur à 0.
  • Mesurez la longueur moyenne de votre pas et demandez à votre micro:bit de multiplier cela par le nombre de pas pour calculer la distance que vous avez parcourue.
  • The accelerometer can measure forces in 3 dimensions, called the X, Y and Z axes. You can modify the code to choose which axis to measure, depending on which way up you fix your micro:bit to your leg or shoe.
image showing X axis across front of micro:bit, y axis up and down, z axis running back to front