Introduction: Car Raspberry Pi3 Dash Cam


I have previously worked with Arduino boards to develop a motion based mobile alerts. But always wanted to work with Raspberry Pi because of the diversified projects that could be done relatively easily because it is a full blown mini computer running on Debian based Linux. Then I remembered looking for a Car Dash cam a couple of years ago, but never bought one as they didn't feature all the requirements that I had in mind. The timing was perfect as I was already trying to explore Raspberry Pi and this use case made perfect sense to me to play around. Luckily for me they released RaspBerry Pi 3 model very recently, so went for it.

My expectation was below:-

1) Automatically start the raspberry Pi, start webcam and record in segments of 30 min as you soon turn on the car 12V+ Ignition Key.

2) Store videos for a month considering I spent 60 Hrs of driving on an average. Then delete any video files more than 30 days old.

3) Log all actions into a log file and again delete anything more than 30 days old.

4) When car ignition key is turned off, video recording should stop after 30secs and a graceful shutdown of OS has to be initiated. After 2 minutes, the power has to be completely cut off from the car battery. I don't want to risk with a dead car battery at any cost.

5) Finally the most important thing is to access the video and log files from my Android mobile device without connecting any cables or having to connect any keyboard/mouse/display to raspberry pi. [i.e. need to conveniently access files from inside my car cabin thru either bluetooth or wifi]

Step 1: Ended Up Buying the Following Hardware

1) 12V 2amp Wall Wart - This is mainly to simulate the car battery during my development/testing effort.

2) 12V Dc on/off toggle switch. Can be handy when required, but optional.

3) Snap plugs for easy installation and snug fit.

4) DC 12V Multifunction Self-lock Relay PLC Cycle Timer Module from Ebay - This will give you the 2 min delayed physical power off to the Raspberry Pi.

5) 2 LM2596 Step Down Module DC-DC Buck Converter - one to convert 12V Car Voltage to 5V to power up Raspberry Pi and the other - 12 to 3.3V to be connected to one of GPIO input pins[This will be used to signal turn on/off from Car Ignition 12V]

6) micro USB cable, cut off and then will be soldered to one of the LM2596 voltage regulator.

7 RaspBerry Pi3

8) RTC module - ds3231. To maintain time for raspberry pi...Note as it is installed in car there is no way for me to maintain time unless we have this module. We can also go without this module, but this makes life much easier to have the files organized and have the right timestamps.

9) Universal PCB Board to hold all components together in a neat layout.

10) 22 Gauge wires for soldering components together.

11) USB Web Cam - Anything from the compatibility chart here. Didn't use Raspberry Pi camera module as I was concerned about the length of flex cable to be used with the CSI port. Also bought a USB extension cable as in my case I required more than 2 meters of wire.

12) 32 GB micro SD Card - almost 4-5 GB will be used for OS and have at least 20 GB remaining to store 50 hrs of video [DVD quality]

Step 2: Tools Required

1) Solder kit

2) Hot Glue Gun

3) Cutting tools - nose plier, wire cutter, wire stripper

4) Heat Shrink Tubes, electrical tapes

5) Your own custom case - I used a small neat storage box from michael's store.

6) Multimeter for testing and tuning voltages for LM2596 Step Down Module DC-DC Buck Converter

Step 3: Set Up Everything

1) Install Noobs to RaspberryPi 3 using the 32GB SD Card.

2) Tune the 2 LM2596 Step Down Module DC-DC Buck Converter. One to 5V and the other to 3.3V be connected to one of GPIO input pins[This will be used to signal turn on/off from Car Ignition 12V]

3) Configure the timer circuit to function-10 [120 sec Delayed relay switch off once trigger goes off - This is how you achieve physical shutdown of Raspberry Pi after 2 mins, once car Ignition switch is turned off.]

4) Connect the 12V Wall Wart and all other components as shown in diagram. For now skip the timer circuit to make development faster.

5) Connect RTC module - ds3231. I followed anotherinstructionfrom Instructables. This will make sure time is always maintained.

6) Configure your wifi for 2 routers - 1) home - for development/testing 2) to your mobile[Wifi Tethering].

7) I didn't use raspberry bluetooth as didn't find any easy way to connect automatically without display and share files later to my mobile.

8) Install avconv for USB video recording.I didn't use motion to record as that was more for motion based recording and didn't quite get the controls i needed.

9) Install Apache web server. so that you can access files directly through http.

10) Connect everything as shown in the circuit diagram. I am no expert in doing circuit schematic diagrams :) and hopefully my rough diagram explains everything even to the novice reader over there.

Step 4: Write Some Shell Scripts/python Code

I have published all scripts and folder structure to GitHub. Below would give some overview on what is done.

Put the following Crontab entries on bootup so that everything starts once pi finishes bootup.

To record from USB Cam

@reboot /home/pi/CamProj/scripts/shell/ &

To monitor Ignition position through GPIO pins/python code and shutdown system gracefully

@reboot sudo python /home/pi/CamProj/scripts/python/ &

Delete any video/log files older than 30 days. For a 32 GB SD card this archival policy was good.

@reboot sudo /home/pi/CamProj/scripts/shell/ &

Step 5: Solder All Components Together and Final Testing

I soldered all components together and hot glued into the plastic box. Wasn't a perfect work, but hey I was impressed myself with the final look as I was totally new to this. I did some extensive testing for hrs to make sure the setup was pretty stable and fined tuned the code at this stage.

Some testing I did to make sure all worked:-

- Was the file deleted after a pre set time? I don't want the sdcard to become full and crash the entire system.

- How good was the recording when camera was shaked and under low light settings? It was good for a USB camera and would have been much better if it was a Pi Camera. Anyway I didn't go for that because of the flex cable length restriction.

- Simulated the car key Ignition on/off toggle very frequently/randomly to make sure the OS booted up/shutdown and all logs were captured as expected.

- Did some field testing with car with Key Ignition on/off before I put the system inside the car.

- Accessed the video files from inside car cabin using Android Wifi Tethering in mobile and with Apache web server running on Pi. [i.e Pi connects to mobile as router]

Step 6: Time to Connect to the Car

- The wiretap differs between various car models, but you would need 3 basic connectors coming out of the car

a) 12V always on from battery

b) 12V Ignition key On

c) Ground wire

- Use suction cup with mount to fit the USB Cam nicely behind the rear view mirror.

- Pass the Usb cable behind the headliner to A-Pillar to go inside the glove box and to the engine bay as shown in pic. I didn't remove the headliner and A-pillar for these and was able to push the cable from side. But was forced to remove the glove box to get proper access to route the wire further.

- Keep the Pi box in a place where it does not move, connect the USB cable, power cables and zip tie all in place.

Step 7: Conclusion

Below are my observation after having this installed in car for a couple of days

- First I was very much impressed with the stability and complete autonomous nature of the system.

- Every time Pi booted, recorded and shutdown gracefully.

- No drain of battery.

- The quality was acceptable considering Pi does real time MPEG 4 encoding. Will try Pi Camera module for 720P recording later if I could figure out a way to overcome the cable length restriction without any signal loss.[I need 3 meters of cable length going inside tight corners with twists] . Appreciate any suggestions here.

- Check out the video quality yourself which I took after all was connected.

- Last but not the least, the joy you get during the whole build process and viewing the end product work has no words to describe. Pls input your feedback for improvements/suggestions and I will try to incorporate.


This Instructable info is to share my experience and intended purely for informational purpose only. Changes may occur in circumstances at any time that may affect the accuracy or completeness of the information presented within any section. I do not accept responsibility for any loss,expense or liability that you may incur from using or relying on the presented information.

First Time Author Contest 2016

Participated in the
First Time Author Contest 2016