Build a Speed Camera and Traffic Logger with a Raspberry Pi
I’ve always been interested in connecting things up to computers that they were never designed for. I could reminisce about my first drawing capture arm that used captured the two joint angles with potentiometers and used them to control the pulse width oscillators that fed into the cassette input on a ZX Spectrum. (I’ve just done a google search for this idea and came up blank – I’m sure there used to be commercial products – it looks like this technology has been lost in the digital dark ages.) Over the last couple of decades it’s been hard going as most business focused and mass produced hardware has little hackability. With the advent of the Raspberry Pi and the looming Internet of Things it’s now really easy to have a lot of fun. Partly it’s about control but it’s also about curiosity and being able to see and understand things that are not normally visible either because we don’t have the physical senses or the timescales are too short or long.
In this post I want to describe my latest “experiment” with a doppler radar. I’ve played around with PIR sensors and light sensors in the past and both of these have their limitations as motion sensors. Radars are becoming quite popular for automotive applications from parking sensors all the way to autonomous vehicles so I decided to see what I could get working.
Hardware – Radar Module
The radar technology I found was a 24Ghz stereo doppler radar module. Cheaper 10Ghz modules are available on ebay and it appears that most automotive radars use 77Ghz. It appears to be the case that higher frequencies give better range. The module I have used has the limitation that it doesn’t measure distance to a target – all it can detect is movements towards or away from the sensor. This is achieved due to the doppler effect which causes the echo from a moving object to be of higher or lower frequency than the original frequency depending upon if it’s moving towards or away respectively. Because the 24Ghz signal is way too high to sample and process directly the sensor module works by subtracting the transmitted signal from the received echo. This causes beating and the result is a much lower frequency which is proportional to the speed of a target. The reason the sensor is called stereo is because it has two outputs. These two outputs don’t detect in different directions but instead are used to detect if a target is moving towards or away from the radar. This is done by detecting the phase of the received echo with one output receiving the real and the other the complex part. A target moving towards the sensor leads to a positive phase shift and away a negative phase shift. The output frequencies are in the range of human hearing with each 1mph roughly 72Hz (or 44Hz per 1kmh)
Multiple objects moving at different speeds are independently detectable because of their different frequencies. The following spectrogram (Audacity is great) shows a recording of the response pointing at a fairly busy motorway. You can also see how the relative speed and hence frequency varies as the vehicles move away from the sensor – this is known as the cosine effect. You can hear what this sounds like from this audio sample on soundcloud.
Hardware – Signal Amplifier
Unfortunately the output from the radar module is really feeble. After experimenting with a number of approaches I settled on using an operational amplifier circuit fed into a the line-in on a sound card. It seems that the choice of operational amplifier is not that critical. I tried three (LM833n, NE5532a and LM358) and few different circuit designs but the signal to noise ratio was pretty much constant. High frequency noise from the radar module and it’s sensitivity to picking up electromagnetic hum 50Hz/60Hz seem to be the main issues. Here is a plot of the noise spectrum when no movement is present:
I powered this from a separate regulated 5v supply because the noise on the USB 5v power is horrendous.
Update: Peter has been experimenting with a pre build audio amplifier module based on the LM386 (http://www.ebay.co.uk/itm/141507760671) and has had success eliminating the 50Hz hum)
This is what it looks like assembled with radar module connected:
For more detail: Build a Speed Camera and Traffic Logger with a Raspberry Pi