IR sensor for traffic density?

Hello guys, new and noob here,

I was thinking a new proyect to measure the traffic flow. I want to put the device up the traffic light and with sensors looking down to the asphalt.

I'm not sure about what sensors use. IR sensors look good choice for me atm, but I dont know if there are some of them to detect 3~5m distance.

Any ideas?

Edit- Sorry, I just notice I posted in wrong subforum :/. Move it, plz

I'm not sure first off where it would be legal for a civilian to put anything on a traffic signal, assuming we are talking about one that is owned by the transportation department and not something privately owned. But if somehow you have gained permission to do so, I can think of a few different ways one might set up a counter that could do the job of determining a rough idea of traffic density over time. I'm not sure an infrared sensor would be the best choice for this given the distance to the ground, generally these are used for determining very short distances and changes in reflectivity such as seen on line follower robots and sumo-bots. Ultrasonic rangefinders depending on the type can be relatively accurate up to about 9 meters, and if you take several measurements from the sensor, or take measurements from multiple sensors, you can determine an average across all of the readings, assuming they will sometimes return an odd number.

To calibrate, you first need to determine the distance to the ground, that will be your baseline, your zero. When the sensor returns that number it can be considered "No object in range". Then when a vehicle passes under or stops under the sensor, you will get a lower number. Regardless of how long that number stays low, you don't want to count it until the number goes high again, indicating the vehicle has left. So each time a vehicle passes under the sensor it is counted. The inclusion of a realtime clock and a means of storage, either with an SD card breakout, or a wireless connection to something storing your data, you can come up with a way to graph your vehicle count over time. This will not only give you traffic density, but you will be able to determine high traffic times (Rush hour).

I would consider testing this out in a controlled environment first, something like a doorway in your house, entrance to a college dorm etc. As long as it is some place your project can remain for a while, undisturbed and not breaking any laws.

For references, let's first start with setting up a rangefinder if you're not yet familiar. I refer back to this one often as it's a really basic use of my favorite low-cost rangefinder, the HC-SR04. Simple Arduino and HC-SR04 Example You can regularly pick these up online for a couple of dollars. I've even seen them sold in lots of 5-10 pieces for under $10 USD.

If your preliminary testing with these determines that they do not have the accuracy your project needs, you may need to step up to some variation of a laser rangefinder. Naturally these are a little more expensive and can be a little more tricky to get dialed in than an HC-SR04 but you're dealing with the same number of wires and the basic code isn't all that different when it comes down to it. Here's a walkthrough I pulled up in a couple minutes of searching.

Laser Rangefinder with Arduino

I'm new here too but I will do my best to answer any questions you might have. Just remember, I haven't worked with laser rangefinders at all yet myself.

Thank you so much, bro.

I was searching info these past hours and yes, ultrasonic rangefinders look better choice. That sensor has 3mm accuracy so I hope there is no problem to differentiate between 2 vehicles, even very close each other.

You can set the limits for your sensor differently if you find it isn't counting accurately enough, perhaps if it were to count a vehicle when it senses the differentiation between say a meter or so from the ground and the top of the roof instead of measuring from a base value of distance to the ground and anything higher. That way even if vehicles are bumper to bumper, the roof of a given vehicle will still be higher than the hood. The only time this might be less accurate is with large square vehicles like buses and very small ones like motorcycles.

Either way you are going to find greater accuracy with a laser rangefinder or multiple sensors per lane. perhaps a more sophisticated setup designed specifically for measuring traffic would be something on the surface of the road in the center of each lane that triggers when it picks up engine harmonics. But that brings about an entirely new grocery list of problems to sort out.

Ok, I will try it and I'm sure I'll be back later.

Next step would be sending data to a remote server. GPRS shield should be enough, right?

I’ve never used one of those so I’m honestly not sure. Whatever means you have to send data from the arduino that something else can receive should work though. Just make sure you’re not using a non civilian frequency. Depending on the distance you need to cover you might be able to use bluetooth, or an ethernet shield.

Hi Ardul

I wanted to follow up with you as I am doing some research of my own on wireless data transfer with the Arduino. My hope is to eventually build a balloon satellite module that will log data along it's flight path but also broadcast it back to a ground station. I realize this is a big task and I am still relatively new to the Arduino platform. Also, admittedly my C-skills are a bit rusty.

I found the following page that goes over transferring data using two Arduinos and two XBee modules. It might be of some help to get you started. Wireless data transfer with XBee

Closer to what I'm trying to do, but also something you could make use of for your project is another link I have here for a Arduino based balloon-sat module which relays it's GPS coordinates back down to the ground using a Radiometrix transceiver. This will transmit the data over the HAM radio frequency band. You have to have an operators license to broadcast on that band but I'm told it's a relatively simple process. Balloon-Sat Arduino

Using your own adaptation of this second design, you should be able to transfer your data over a much wider range. These Radiometrix transceivers have been used on small satellites to send data to the ground from orbit. Broadcasting across town should be no problem.

Oh man, that's f**g awesome.

Cool, I will check both ways. Yesterday I was looking for some info about the GPRS shield and I think is also enough for a town-city.


Anyway, atm I'm a bit disappointed with ultrasonic sensor. I got the HC-SR04 and at >50cm starts to fail. I was searching more US sensors with better quality, but price is about 80$. For that cost, 25$ (Arduino) + 80$x2 (Sensors) is better choice Raspberry Pi with OpenCV for counting traffic.


There’s a few different options as far as ultrasonic rangefinders go and there may be some tricks out there to gain more accuracy. I remember reading on a thread here, somebody mentioned that people used to use the sonar modules out of old Polaroid cameras as the sensors for their robots. To that end, I found this page, though I didn’t find anywhere a mention of accurate distance. Still might be worth a look.

Modifying a Polaroid sonar

It’s worth it to do some more research before making that initial purchase for something like this as ultrasonics and sonars tend to get a little pricey depending on the model and design you choose. I’ve only used them for robots and tend to hard program an upper and lower limit on the values they return to prevent my robots from going insane in large areas or rooms that tend to bounce sound waves a lot (Like concrete courtyards and long hallways). As I mentioned before, you may have to consider using a laser rangefinder for your application unless there’s one out there with a better range. Though, when I initially researched the HC-SR04 I thought I learned that it’s accurate up to 9 meters.

Hi there,

I too am new to this forum, my reason for being here is that I would like to create a traffic monitoring network for my community.

Our Council recently spent £20K on a traffic survey that (deliberately???) spanned over our school holidays, this traffic survey is the basis for numerous housing developments... adding 50% to our town over a decade!

I need to create a low cost, easily maintained OPEN network to create the data the community needs to inform itself. I would also like to be able to measure average and peak speeds for our roads too.

Others in our group are also working on an Air Quality monitoring project.

I will watch with interests.