I do the < 10cm check for Lego maintenance purposes, (i.e. Otherwise, turn the motor on by setting one of the GPIO pins as high. So if the measurement from the sensor is greater than 100cm or less than 10cm, keep the motor turned off. Never connect the output of the Raspberry Pi to a motor as you'll damage the Pi!ģ)Controlling the pins based upon distance measurements: Read more about it there but it basically uses a motor controller board to take logic output from Raspberry Pi GPIO pins and switch on the Lego motor. A main loop that continuously gets a measurement and acts upon the result.įor this I re-used techniques I first learnt about for my Lego car project.Function GetAMeasurement - Which takes a measurement.The result is the bulk of the code I've pasted in at the bottom of this posting. It's just fascinating how tangible it is to do this through Python on the Raspberry Pi. The physics and maths behind interpreting the length of the echo pulse and turning it into a distance measurement.Python code to capture the echo response duration.Python code to trigger a measurement (creating a short pulse).Python code for setting up and controlling the GPIO.Principles of potential dividers (required to drop the sensor's 5V output down to 3.3V for the Raspberry Pi).I won't replicate it here but the highlights are: I followed this tutorial, it's utterly brilliant. ![]() ![]() Previously I've used Scratch but for this project I decided to use Python to understand a little more about how to control the sensor and interpret the results. I've used an HC-SR04 ultra-sonic sensor for a couple of previous Raspberry Pi Scratch projects like a press up counting machine and a simple game.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |