Notebook 02


Lab Notebook


Date: 09/02 2012
Group members participating: Falk, Jeppe and Jakob
Duration of activity: 4 hours


The goal of this lab session is to get familiar an experiment with an I2C sensor, namely the ultrasonic sensor.


  • Explore the reading from the ultrasonic sensor using to determine under which circumstances the readings are most accurate and when it is not.
  • Run and analyse the to see how the ultrasonic sensor can be used to control a robot.
  • Using the setup from Philippe Hurbain, implement a leJOS wall follower.


Test of the Ultrasonic Sensor

With the sensor mounted, and running the the measurements are done indoor and on a flat surface with no obstructions.


The distance measurements was done with a 15x30 cm plastic plate.
Distance is measured in centimeters from the front of the sensor.

Distance Value
0 255
0.3 5
5 5
10 14
15 18
20 23
30 32
40 43
50 50
175 176
225 (max) 226

Looking at the table, we note the following things which are important for using the ultrasonic sensor

  • If the sensor is completely blocked, it can not read the ultra sonic waves and so it returns 255 (no echo).
  • The lowest measurement is 5 cm, and from a few millimeters to 5 cm, the return value is 5 for a steady (non-moving) target.
  • For a distance below 50 cm we get slightly bigger numbers than the actual distance
  • The sensor does not react to objects before they are only 225 cm from the sensor, which is a bit shorter than the theoretical distance of 254 cm.


Based on the readings from the Lego mindstorms ground plane, the cone is 22.5 degrees from the middle to the left and the right (45 degrees in total).
Making the robot lie on its side to measure the vertical angles of the cone, the readings result in the same values.
Holding a pen a few millimeters from each of the 'eyes' the left eye gives the value 255 and the right eye give the value 5. Concluding from this, the left eye must be the sensor and the right eye the sender.


Trying to read the distance to a round transparent plastic bottle, the readings are a bit weird.
Trying to read different kinds of water bottles, the values seems to be a bit off. At distance 17 the values fluctuates between 17 and 24,
Moving the object a bit more to the left (from the sensor's view) the measurements becomes a lot more accurate. This is the case not only with round objects, but with all smaller objects, that the most accurate results are obtained when the object is in the center of the view of the sensor, or slightly to the left of the center.

Time limit

If there is no object within the theoretical max range (254cm), the reading should time out.
The time limit for the measurements is the time it takes for the sound wave to travel the maximum distance back and forth.

\begin{align} \text{Time limit} = 2\cdot \frac{\text{distance}}{\text{speed of sound}} = 2\cdot \frac{2.54\text{m}}{340.29 \tfrac{\text{m}}{\text{sec}}} \approx 0.015\text{s} = 15\text{ms} \end{align}

Since no object (probable) will travel faster than the speed of sound, the frequency of readings ensures that the sensor will know the object is closing.

Tracker Beam

Using the (that uses the the car drives forward until it measures an object within the desired distance (default 35cm), and then it oscillates around that value driving forward and backwards never stopping, not even if actually measured 35cm.

Change of Constants

  • If the minimum speed (minPower) is increased the robot oscillates more.
  • The gain is the importance of the distance (power = gain*error). If the gain is increased the robot brakes faster when the distance get smaller.
  • The desired distance is obvious and there is no need to test this.

The control of the is a closed loop control seeing that it get feedback all the time. It uses proportional control for the setting of the speed.

Differential Control

Adding differential control to adjust the speed the robot reduced the size of the oscillations.
There were some problems with getting the speed from the motor, seeing that the API seems to be out of date.

Wall Follower

Building a wall follower inspired by Philippe Hurbain. The robot has limited flat surfaces and therefore the mounting of a 45 degrees sensor can be a bit difficult.

wallfollower_1.jpg wallfollower_2.jpg

The is not too complicated however Philippe Hurbain has very different values for the distances.


The running of the and the related results reveals the limits of the ultrasonic sensor regarding distance and the cone/vision. It also showed that the sensor had misreadings when an object was not centered in front of the sensor.
The works very well, and the implementation of the is not too difficult once the problems of attaching the sensor in a 45 degree angle is overcome.
All in all both the limitations and how to control the robot from the input of the ultrasonic sensor is shown in the above.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License