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/record.sh &

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

@reboot sudo python /home/pi/CamProj/scripts/python/Monitor12V.py &

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/deletearch.sh &

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.

<p>Your circuit is a bit confusing around the timer. On the right side, there are two connections labeled NO and COM. Can you clarify that area's connection to power? It looks like the NO and COM are connected to each other, to the battery and to the positive connector on the LM2596 (5v). Is this the case, or does the connection from the COM port jump over both the connection to the NO port, and the ground to the LM2596 (5v).</p><p><br>Thanks<br><br>Mike</p>
<p>Yeah..It did look confusing when i see it now. COM receives always ON circuit[+12V] from car battery. NO - Normally Open goes as an input [ +5V via LM2596 ] to Raspberry PI. You can see more configuration options for this timer in http://www.plexishop.it/pdf/I120%20-%20datasheet.pdf</p>
So for clarity's sake, they are two separate connections.
<p>I'm assuming you take out the SD card to view any footage?</p><p>I was thinking of something like this that could work in tandem with an Android Phone (and something like Tasker) to transfer data via wifi/bluetooth to the phone. Perhaps from there we could upload to a service such as google drive or dropbox for access at any time?</p><p>If it's too much to ask for every piece of footage to be transferred (lots of uploading, file transfer to phone, etc), perhaps a physical button could initiate the transfer of the past ~3 minutes of footage?</p><p>I really like the idea of a completely autonomous dashcam that automagically gets the footage on my computer at home in some way or another.</p>
<p>I am already accessing the files using mobile tethering[Step 4 screenshot] to retrieve only that is of interest to me. But you can very well extend this to upload all your files to your home server using wifi and a simple python program considering the proximity of car garage.</p>
<p>Hi Vijay.</p><p>To use the Pi Camera you just need this <br></p><p><a href="https://www.tindie.com/products/freto/pi-camera-hdmi-cable-extension/" rel="nofollow">https://www.tindie.com/products/freto/pi-camera-hd...</a> and a 3m HDMI cable. </p><p>I've used it for a different purpose but works well.</p><p>Thanks,</p><p>Marco</p>
<p>Hi Marco,</p><p>I have thought about this and was sceptical initially about the compatibility/interference and tight corners that the cable needs to go through. Anyway I am trying to directly solder the 15 pin flex cable to the 19 pin HDMI cable instead going through the module [Why not do it the hard way :)]. I am working with an upgraded version of this project now and will let know once it works without any issues.</p><p>Appreciate your inputs as well !!!</p><p>Thanks</p><p>Vijay</p>
<p>Would this work with a RPi 1 Model B+ or zero?</p>
<p>Hi Vijay, Nice idea. I tried to search for building a dual channel dash cam and landed on your project (see: http://android.stackexchange.com/questions/156256/using-old-android-phones-as-multi-channel-dash-cam). It is a good start for me. If you happen to know any input on how this project can be modified to accommodate a secondary cam please let us know. Thanks again.</p>
<p>Hi,</p><p> I really wouldn't recommend 2 USB cameras attached to Raspberry PI3, as it will enforce all video encoding in CPU resulting in resource hogging &amp; poor video quality.</p><p> You can have 1 USB and 1 Raspberry Pi camera. That will definitely work, as Pi camera uses the CSI port and thus not heavily relying with Raspberry Pi CPU.</p><p> The final picture would look like :-</p><p> 1) 1 USB camera - Uses CPU and records @ 480 resolution/15 frames per sec</p><p> 2) 1 Pi Camera - Uses GPU and records @ HD.</p><p> I haven't tried this setup, but it should work for most part without any issues. </p><p> Refer to my GitHub for coding instructions. You can use the crontab to add an entry for another Pi camera using python program.</p><p> Best of luck and let us all know on how it comes.</p><p> Thanks,</p><p>Vijay</p>
Thanks for the inputs Vijay, this idea is just at its inception stage and this would be first Pi project as well - so I guess this will take some time to mature. Sure, when ever it happens it will be on this site. Thanks again.
<p>Nice project! What resolution is it recording at? (Is that sample video clip at original resolution? - I noticed you can't read number plates etc)</p><p>I would be tempted to try the new Pi camera with a long connector - this one is 2m long <a href="https://www.adafruit.com/products/2144" rel="nofollow">https://www.adafruit.com/products/2144 </a> or one of the HDMI extenders Kev mentioned.</p><p>Also, how long have you had it running? I would be worried about the SD card corrupting fairly quickly with all the writes - have you considered making the SD card read only at boot, and using a sacrificial USB storage for the logs/video etc.? (If you're really keen, you could use an SSD drive via usb?)</p><p>I think this might be a nice project to tinker with :-)</p>
<p>Thanks Stuart for your feedback.</p><p> It records @ 480 resolution/15 frames per second. Believe it or not this was the toughest part in the entire project to tweak, as anything lesser resulted in poor video quality and anything higher it started to hog the CPU for resources.</p><p> Overall the whole project is running fine for the last 4 months without any major issues and I am surprised as well with its robustness.</p><p> The only issue i have faced so far is with maintaining time a couple of times though i have the RTC module - ds3231 installed with a good battery.</p><p> Yeah, and as you pointed out writing onto SDCard all the time is prone to card failure issues...will try to incorporate USB storage when i have some time.</p>
<p>There is a method of using the Pi Camera module with a HDMI extension.</p><p>I've used this product: <a href="http://petitstudio.blogspot.co.uk/2015/04/the-raspberry-pi-camera-extension-cable.html" rel="nofollow">http://petitstudio.blogspot.co.uk/2015/04/the-rasp...</a> with success, although the first HDMI cable I used didn't work.</p>
<p>Hi,</p><p> Thanks for your inputs, have couple of queries with that setup and appreciate your response.</p><p> 1) Looks like GPU hardware encoding is supported only through CSI port. So even if it is adapted to HDMI Cable will it still support GPU encoding and will I be able to achieve the 720P, 30fps video recording?</p><p> 2) Does that setup still support/work with the pi Camera python libraries?</p>
of course the timer would fix it, didn't even think about that. it will buffer the voltage drop, as long as you don't hold the starter on longer than the 3 seconds, which is not good for your starter anyway. great peice of work. ?
how do you over come the power drop on engine startup?(acc-ign) I imagine that this will eventually throw raspberries boot sequence, or damage the pi, as the power cuts off to accessories when high current is pulled from the battery for the ignition system.
<p>I did verify and test this part with the help of multimeter when doing my initial testing/setup with the car. The Voltage sent to Pi didn't drop any less than 5V. I could only think of 2 reasons here:-</p><p>1) Either the electrical system is rock solid in my car as I usually don't see that much voltage drop in the instrument cluster</p><p> or</p><p>2) The combination of Timer circuit with Voltage regulator- LM2596 helped it. The timer circuit continues to power the whole setup for 3 seconds even after a complete switch of and may be that helped if there were a drop.</p><p>Anyway it's been 3 days, at least started my car for 20+ times and haven't found a single improper bootup or shutdown.</p><p>Will post if I encounter any issues and thanks for your queries.</p>
<p>Cool dash cam.</p>

About This Instructable




More by vijayp44:Car Raspberry Pi3 Dash Cam 
Add instructable to: