Two sensors for a robot

2capteur_250px imagine, build a robot is good. For example, you imagine a vehicle that moves ( independently or by remote control ). So he can react to its environment, it must like us with our 5 integrate information on the world that surrounds it.
The example that I know well, it is a ( old ) vacuum cleaner equipped with a detector of obstacles. When he meets a chair leg, a wall… He stops, back up a bit and go in another direction.

a suicidal vacuum cleaner

aspirateur Super! Mmmouais but when the vacuum cleaner is enquille under a radiator located sensors rather at the bottom of the chassis are silent and the other tries in vain to move forward because there is no obstacle.  Programmers were probably in a room heated by the ground without radiator 😀

and if there is that it’s… a staircase without door has witnessed several suicide attempts. The vacuum cleaner is not equipped either vacuum detector, doesn’t realize that happens at first markets and… tumbles down the stairs.

it makes you smile, but if you design a rover, a spider or a drone of things that you should think…

and how a robot may be informed of the surrounding world? With the help of various sensors that her return measured values or information on its position etc.

laser sensor: distance LIDAR measurement

robot-capteur-de-distance-laser-2 on paper ( Finally, on the screen ) is very simple. Just send a LASER pulse toward the front. IF it encounters an obstacle, this impulse comes back to the robot. Just to detect the exact time of the back, measure the time return ( flight time). We know the speed of light . Simply divide the time of flight by 2 ( bin so there is a roundtrip 🙂) and multiply by c ( speed of light ) for distance: D = c x T/2 .

this is the principle of the LIDAR ( L ight D iscoverability A nd R anging). This technique is used for example to measure the earth-moon distance through reflectors deposited by the Apollo missions or shipped on Soviet Lunar vehicles.

the problems for the realization of these sensors is the pulse length ( which must be the shortest possible ) and the size of the sensor. Advances in production techniques of the LASER beams, sensors and miniaturization of all it has resulted in the creation of a miniature sensor.

the Adafruit LIDAR sensor

tps_volee_01 vl53l0x Adafruit sensor is based on the circuit VL53L0X , which is only 4 x 2 x 1 mm

VL53L0X sensor allows to add a distance/proximity sensor to your project. He warns that a hand, a cat or a wall nearby. Depending on the ambient light and the reflectivity of the object, you will get a range of about 30 mm to 1.2 m with accuracy of ~ 5%.

the sensor contains a tiny laser source ( invisible ) and the receiver. The VL53L0X can detect the “flight time”, IE the time that light took to bounce off the obstacle. As it uses a very narrow light source, it is perfect to determine the distance only on the surface located directly in front of him. Unlike sonar using ultrasonic waves, the “cone” of detection is very narrow, unlike infrared distance sensors that try to measure the amount of light rebounded, the VL53L0x is much more accurate and has no linearity or ‘double image’ problems that you cannot know if an object is far away or very close.


the sensor is small and easy to use in any project robotics or embedded. It works in 2.8V and Adafruit brought together on this small map control and a level shifter. You can use it with any microcontroller running between 3 and 5 volts. Each card comes with a small connector solder.


the communication is done by I2C with an API written by ST, so it’s not too difficult to connect it to your favorite microcontroller. Adafruit provides a tutorial for this product.

adafruit_products_defaultrange the graph above gives the measure returned depending on the distance and the color of the obstacle.


for $ 15 this is a sensor that can provide your robots, drones… sensitivity to nearby objects. If you have the opportunity to test feel free to leave your imprssions in the comments below.

this sensor has been reported to me by Stroon2 I thank for this info.

line_tracker_03 it seeks to carry out surveys of water with its Raspberry Pi meter and he came across this interesting infrared sensor module.


the sensor is an infrared transceiver TCRT5000 .

tcrt5000 announced as follower of line ( Line Tracking Sensor Module ) this module can of course be used as a conventional detector and signal the presence of an obstacle or… other.

this module is inexpensive ( less than 2 euros to the unit and less than 5 euros per 5 ) and it is adapted to the 3.3V Raspberry PI! On the site of the seller this module is announced as powered 5V. Looking at the sensor closer ( once receipt ), Stroon2 realized that the single integrated circuit it can run on 2V to 6V range.
Tests have confirmed that it works perfectly in 3.3V 🙂


the module can be used directly without the addition of component added. The only difficulty is finally in the mechanical adaptation to the water meter…

after trials, Stroon2 gave me the following information:

here’s a little extra because counting impulses played me a few laps… This is unrelated to the sensor but the parasites.

a network cable is used to carry the signal of the IR sensor.
Temperatures (DS18B20 x 5) 1-wire sensors using other strands of this same network cable.
This cable is very long (< 3 m) but this length seems sufficient to interfere with the signal from the IR sensor and trigger changes of spurious States on GPIO port.

the counting is done with a bit of code Python that runs in the background.
I use the RPi.GPIO module and the GPIO.add_event_detect function, which allows the detection of the GPIO port state change.

I started by simply adding state changes to increment my total but it doesn’t work because function is also triggered on parasites.
The setting of the Bouncetime does not appear to have any effect.
A capacitor in / / has improved some things but not 100%

surprisingly, there may be successively several trigger on the same type of front (rising or falling) then that between two rising edges should necessarily be a falling edge! (and vice versa).
This is may be just the result of the bouncetime that hide an interruption if it is too close to the previous…

in short, to eliminate false positives I uses a previousEdge variable that retains the previous state of the GPIO port.
When a change is detected, I compare the current state of the GPIO port with the previous state. If it has not changed, it is not a change of State, I don’t know this detection.

here is the code below for info. This isn’t the great development, but the account is just 🙂

in summary:
at startup I initialize my water meter reading by reading the last value in a file.
I increment my statement of 0.5 litres to every ‘real’ trigger. (1 round/litre so 2 fronts when the mirror passes in front of the sensor)
I’m writing my statement in the file every 300 seconds.
FYI, I trace the false positives in a files.

 #! / usr/bin/python3 import RPi.GPIO as GPIO from time import sleep from os import getcwd import time import datetime #___PARAM___ loopTime = 300 #attente between records periodicals pine = 27 #GPIO to monitor Bouncetime = 100 outputLog = "trace.log" dataFile = "datafile.dat" #_ NBRising = 0 NBFalling = 0 NBFalsepositive = 0 previousEdge = 0 print ("Port =", pine) print ("Bouncetime =", Bouncetime) print ("NBRising =", NBRising) print ("LoopTime =", loopTime) obFichier = open (dataFile (, 'r') statement = float (obFichier.readline ()) obFichier.close () print ("=", statement) GPIO.setmode (GPIO. BCM) # set up BCM GPIO numbering GPIO.setup (pine, GPIO. IN, pull_up_down = GPIO. PUD_DOWN) # set GP you input def my_callback (channel): global NBRising global NBFalling global statement global previousEdge, NBFalsepositive pinStatus = GPIO.input (Pin) if (pinStatus == 1): NBRising = NBRising + 1 else: NBFalling = NBFalling + 1 if (pinStatus == previousEdge): print ("False positive") NBFalsepositive = NBFalsepositive + 1 else: previousEdge = pinStatus print ("True edge detected") statement = statement + 0.5 GPIO.add_event_detect (pine, GPIO. BOTH, callback is my_callback, bouncetime = Bouncetime) while (True): print ("Waiting events...")
sleep (loopTime) ts = time.time () now=datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') obFichier = open(outputLog,'a') line = now + "Rise =" + str (NBRising) + "Fall =" + str (NBFalling) + "False =" + str (NBFalsepositive) + "Statement =" + str (statement) "n" obFichier.write (line) print (line) obFichier.close (obFichier) plus obFichier.write (str (statement)) obFichier.close () GPIO.cleanup () open(dataFile,'w') # clean up after yourself


here’s an infrared sensor size and discounted prices that can probably fit into one of your projects. There still do not hesitate to leave a return on your use in the comments below.

No comments:

Powered by Blogger.