In this small project I would like to show you how can you create a simple Radar at Home with Arduino. There are many similar projects on the internet, but they are all using an ultrasonic sensor to measure the distance. In this project I use an infrared sensor for distance measurement.
My goal is to create a very simple and cheap LIDAR system with it and implement a mapping device.
You will need the following materials:
- Arduino (I used a Maple Mini)
- Sharp distance sensor (I used Sharp GP2Y0A02YK0F)
- Micro Servo (9g)
- Breadboard, wires
- Optional: 4.7k Resistor, 100nF Capacitor
The main difference between ultrasonic and infrared distance sensors is that the ultrasonic sensor measures distance in wider range. Therefore it is not able to precisely locate the position of an obstacle. It means that it measures the distance of the closest object which is located inside a ~ +-30° angle range.
Of course, it doesn’t mean that the Sharp sensor is better. Sometimes this property can be very useful (e.g. used by drones to measure height from ground). The right choice is totally depending on the requirements of your project.
SchematicIt is very simple to make the connection between parts. Select a PWM Output and an Analog Input on your Arduino board and connect the Servo and Sharp distance sensors to those pins. I used the following pins for this purpose:
- PA0: Analog input for Sharp distance sensor
- PA9: PWM Output for Servo
Sometimes the Sharp IR Sensor can have noisy output, therefore you have to put a simple Low Pass Filter on it. I used a 4.7k resistor and a 100nF capacitor to reduce the noise on the analog pin. Besides that I also filtered the measured value in the code by reading it multiple times and calculating the average.
Unfortunately the used infrared distance sensor has non-linear characteristic. It means that to get the distance, it is not enough to multiply the measured ADC value with a constant value and adding another constant value to it.
Although the datasheet of the sensor provides the characteristic, I prefer to measure it by myself in the specific project (it could depend on the used voltage). For this, I made pairs from the measured ADC Value and distance for every 10 cm. (My sensor was able to measure correct distance from 12 cm).
I used these pairs in the code to get the correct distance with Linear Interpolation.
// Structure to store ADC Value - Distance pairs
typedef struct {
float distance;
float adcVal;
} S_DIST_ADC_MAP;
// ADC Value - Distance pairs
// Fill it measured SHARP Sensor characteristic values.
S_DIST_ADC_MAP distAdcMap[] = {
{12, 3599},
{20, 3122},
{30, 2295},
{40, 1733},
...
};
// Function to get distance [cm] from measured ADC Value
float getDistance(float adcVal)
{
float distance = DISTANCE_MAX;
// Linear interpolation from measured ADC value and MAP.
for (int i = 1; i < (sizeof(distAdcMap)/sizeof(S_DIST_ADC_MAP)); i++)
{
if (adcVal > distAdcMap[i].adcVal)
{
float factor = (adcVal - distAdcMap[i].adcVal)/(distAdcMap[i-1].adcVal - distAdcMap[i].adcVal);
distance = factor * (distAdcMap[i-1].distance - distAdcMap[i].distance) + distAdcMap[i].distance;
break;
}
}
return distance;
}
You will find a simple Arduino code at the end to measure ADC Value during characteristic measurement.
Serial CommunicationI used serial communication to send the measured angle-distance values to the PC. Since I have to send multiple bytes and different type of messages, I designed a simple communication protocol.
This procotol makes able to define different message types in a generic way. In this project I used 2 message types:
- Parameters: Used to send parameters to PC Application, defined on Arduino like maximum distance and number of obstacles in a round.
- Obstacle: Used to send a detected obstacle. It is identified by angle of the servo and measured distance. The x-y position will be calculated by PC application.
To communicate with Arduino and draw the measured points like a radar I made a PC Application in Qt (C++). It receives some parameters (defined on Arduino) and the measured distance points.
Comments