Make a Laser Arduino Robot Using Parallax Laser Sensor – Part 2

arduino robot

Click here to read Part 1 of this article >

arduino robot


In Part 1, we built a custom acrylic base board to mount NEMA 17 stepper motors to the chassis. We then attached the Arduino Uno 3 and the motor shield to the acrylic base and installed the motor shield library. In Part 2, we will be adding the rest of the parts required for the robot to function, such servo and Laser Range Finder (LRF), and writing a program that allows the robot to move around autonomously.

Please refer back to How To Make Your Own Robot and How To Make Your Own Robot (Part 2) where we showed a simple and easy way to build your own wheeled robot from scratch using Arduino UNO R3. In this article, we will further improve the functionality of the robot by making it mobile and adding laser range finder (LRF) to allow the robot to detect objects and measure distances.

The robot is designed to:

  • Move forward, backward, turn 90 degree left & right and turn 45 degree left & right.
  • Avoid obstacles by moving in different directions based on best available paths.
  • Measure distance from various directions (forward, 90 degree left & right, 45 degree left & right.
  • Make decision on which direction it will take (forward, backward, left or right) based on the longest distance available.


The hardware required for this Robot are available in many electronics shop, we provide examples of shops in the  Hardware list.




  • Round file
  • Dremel Rotary Tool
  • Soldering Iron
  • Mini Hacksaw

Install and test the servo

The next step is to install a servo for panning. First screw the two small plates to the servo base, and then screw it to the acrylic base as shown in Figure 1 and Figure 2. Install aluminum mounting to the top of the servo using 2 screws.

arduino robot

Figure 1. Attach servo to acrylic base using 2 small plates.


arduino robot

Figure 2. And attach aluminum mounting to servo.

Connect the connector from servo to motor shield as shown in Figure 3. There are 2 servo connectors in motor shield labeled “servo1” and “servo2”. Use servo1 for this connection (the one on the outer side). Please be careful not to reverse the connection.

arduino robot

Figure 3. Connection between servo and motor shield.

Now we are ready to run the code, upload the code below to Arduino. There is no need to install a new library. The required library (Servo.h) is already included with the Arduino IDE program. The servo will use Digital pin 10 (servo 1) or you may use pin 11 if the servo is connected to servo 2 in motor shield.

The code is very simple; it scans from left to right and back to original position.

The following video shows how the servo works:

Install Laser Range Finder (LRF)

Laser Range Finder Product Document – Parallax

Parallax Laser Range Finder (LRF) Module is a distance-measuring instrument that uses laser technology to calculate the distance to a targeted object. Distance is calculated by optical triangulation using simple trigonometry between the centroid of laser light, camera, and object. Optimal measurement ranges 6–48 inches (15–122 cm) with an accuracy error <5% (average 3%).

Hardware installation is simple. Simply drill 2 holes to match with LRF position then screw the LRF into the aluminum mounting using plastic spacer (see Figure 5).

arduino robot

Figure 4. Connect LRF cable to motor shield.


arduino robot

Figure 5. LRF attached to aluminum mounting

Due to the max optimal measurement 122 cm of the LRF, we need to bend forward the aluminum mounting a little bit so that the range will always be less than 120 cm (Figure 6).

arduino robot

Figure 6. Bend the aluminum mounting forward, so that the distance from laser to floor less than 120 cm

Connect the cable connector to the LRF exactly as shown in Figure 7.  GND goes to Ground, VCC goes to 5V, SOUT goes to pin 8, and SIN goes to pin 9.


arduino robot

Figure 7. LRF connection to motor shield

Now that we have installed and connected the LRF, let’s upload the code! Again, there is no need to install library. We will use SoftwareSerial.h which is already included in Arduino IDE.

The following code is originally from the sample code with some modification, converting distance data from string into integer. What it does is to measure distance to the object in front of the sensor and print the result. We will use serial monitor to display the result.

Here is the result shown in serial monitor. All measurement are in mm.

arduino robot

Install OLED display

First, let’s install the OLED plastic case into the acrylics base (see Figure 9), then connect the cable (which comes with the OLED Display) to the display. For connection to motor shield, cut the cable from other jst connector then solder red cable to 5V, black cable to Ground, yellow cable to pin SDA, and green cable to pin SCL. Just to make sure see also the back of OLED display.


arduino robot

Figure 8. Connection between OLED and motor shield.

Once we have attached OLED at the base and connected the cables, now we are ready for some coding.

First, make sure that the library, SeeedOLED.h, has already been installed. Then, upload the following code to Arduino. This code uses function oled1 which will be used in the final coding later on. Basically, it displays number from 100 to 109.

When the program runs properly it will display as shown in the following video:

Install the final Code

So now we have installed all the hardware and tested the individual devices. Let’s put it all together and build a smart laser robot that can move around autonomously. The final code will do the following:

  • Measure distance in front:
    • if the distance is more than 70 cm, it’ll move forward for 500 steps (around 50cm);
    • If the distance is less than 70 cm but more than 40 cm, it’ll move forward for 200 steps (20 cm);
    • If the distance is less than 40 cm, then scan 90 degrees left, 45 degrees left, 45 degrees right and 90 degrees right;
  • Measure the distance for each direction and then find out which direction has the longest measured distance;
  • Turn to the direction which has the longest distance;
  • Back to the first step.

Copy the following code and upload to Arduino:


arduino robot

Figure 9. Final look with OLED attached to acrylic base.


In the previous articles, How To Make Your Own Robot and How To Make Your Own Robot (Part 2), we have created a simple wheeled robot using stepper motors. This time we improved the functionality of the robot we created before by adding laser range finder (LRF) and making it mobile. I have wanted to create something that does measuring for us. The laser sensor, in this case, allows the robot to detect and avoid object(s) and obtain more accurate distance data. There are many other applications of laser robot. You can come up with your own fun projects using the laser sensor.

We will make something even cooler next time. So stay tuned!

Purnomo Nuhalim
Purnomo Nuhalim
Hailing from Melbourne, Purnomo is a retiree and electronics enthusiast. Currently he is keeping himself busy with various open hardware projects using Arduino and Raspberry Pi. Besides electronics, he is also passionate about aero modelling and astronomy.

Check us out on Social Media