Distance Measurement Vehicle via Websocket using Arduino

Distance Measurement Vehicle via Websocket


When you measure distance between two point general way is to use a ruler. But you can use a lot of other ways: by laser, map, foot or walking meter.

The walking meter is very useful when you are measuring curved (not straight) distance. But it might be very tired because you should walk the entire distance.

Distance Measurement Vehicle via Websocket

Here is a movie which is measuring distance. You can see that the vehicle is being controlled by the web browser and distance is displayed in the web page in real-time.

This project is about a distance measuring vehicle. It is remotely controlled through the WiFi network via Websocket and user can get the distance data from the vehicle in real-time via the Websocket.

Now, I am going to explain how I have implemented the system.

1. Assembling a vehicle

At first, I have assembled a vehicle from the DFRobot.


The vehicle kit was great because I could get everything from this kit. But when I assembled two encoders some parts were not fit so it was tough to fix.

2. Modifying a web page

I have implemented a web page by using a source code from hackster.io. It is a cool implementation of a joystick via Websocket.


I have added a function to display distance data from the vehicle.

And I have modified that it transmits control data to the vehicle only when joystick position is changed over predefined offset because there were a lot of data transmission with original web page.

3. Programming Arduino Uno

I have programmed one source code for the Arduino Uno and PHPoC Wifi Shield.

The PHPoC Wifi Shield supports Websocket so user can implement a real-time web-based system with Arduino Uno.

Data from the web browser through PHPoC Shield’s Websocket are text number from 0 to 100. But the PWM data for the DC motor driver are from 0 to 255. So there is a conversion routine after reading the data from the Websocket.

And distance is transmitted every 10cm through the Websocket. Distance is determined by counting the encoder on the wheel and calculating it based on the wheel’s diameter.Schematic Distance Measurement Vehicle via Websocket

So I needed to count the encoder. But calculated distance is so large than I expected. I found that there are a lot of noise when I reading the encoder state from pin 2. So I programmed software filter. The algorithm is followed:

Read more: Distance Measurement Vehicle via Websocket

Leave a Comment

Your email address will not be published. Required fields are marked *