Car Raspberry Pi3 Dash Cam

53,956

197

36

Intro

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.

Disclaimer:-

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.

Share

    Recommendations

    • PCB Contest

      PCB Contest
    • Toys Contest

      Toys Contest
    • Make it Glow Contest 2018

      Make it Glow Contest 2018

    36 Discussions

    1
    None
    KeithM9

    6 months ago

    Nice one. Is there a way to make it with some kind of manual record and stop buttons?

    3 replies
    0
    None
    vijayp44KeithM9

    Reply 3 months ago

    Sure you can. It is a matter of adding Tactile switch, then interfacing with GPIO pins and using it appropriately in the python code.

    0
    None
    Mitomon1vijayp44

    Reply 17 days ago

    Hi there, how do you prevent data loss if it is shut off early? I've been working on making a manual dashcam, so I removed -t. What python modules should I be using? I've got GPIO, and sys to run the shell script instead of crontab. I can make the mp4 file, but don't know how to stop recording properly so that it saves and isn't corrupted. Any tips would be appreciated :P

    0
    None
    vijayp44Mitomon1

    Reply 7 days ago

    Sorry..but couldn't answer this very specific question, but the setup I had worked for a year without any issues as the shutdown itself stops the recording..Yeah, it can be improved in many ways, but this setup gave me on what I want. The entire code base for this setup is under GitHub and you can use it for your reference.

    0
    None
    alextoveyBenjaminH10

    Answer 7 weeks ago

    Yes i've got it working on the 3b+ :) a bit of fiddling required but it works.

    0
    None
    alextovey

    Tip 7 weeks ago on Step 3

    To install apache in RPI to go the console and type sudo apt-get install apache2

    To install the cron tab items go to terminal and type crontab -e
    Scroll tothe bottom and type in the command lines without any timings. save and exit.

    0
    None
    AlbertL55

    Question 4 months ago on Introduction

    I am sorry for my ignorance but can I add some features in the camera - let's say object or light detection? Is this possible?

    1 more answer
    0
    None
    vijayp44AlbertL55

    Answer 3 months ago

    I know at least there is motion detection using python libraries for Pi Camera. For this setup to work, the raspberry Pi has to be in always ON using the car Battery. There are workarounds for this, but let this forum know of any ideas. After all this a place to experiment and learn :)

    0
    None
    vijayp44lhj734017

    Reply 3 months ago

    If you plan to use the CSI port for camera it will work. USB camera uses CPU for processing and will hog for resources.

    0
    None
    vosm10

    1 year ago

    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).


    Thanks

    Mike

    4 replies
    0
    None
    vijayp44vosm10

    Reply 3 months ago

    COM to +ve side of Raspberry pi Power supply via LM2596 = Finally gives 5V+.

    NO to +ve side of Car Battery [Always ON line].

    Hope that clarifies

    0
    None
    vijayp44vosm10

    Reply 1 year ago

    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

    0
    None
    vosm10vijayp44

    Reply 1 year ago

    So for clarity's sake, they are two separate connections.

    0
    None
    ShinigamiRic

    1 year ago

    Hi. Thank you for you instruction. Please tell me about relay. CH1 uses 12V+ Ignition to start on relay (red square in attached scheme)?

    000016.jpg
    1 reply
    0
    None
    vijayp44ShinigamiRic

    Reply 3 months ago

    That's right. CH1 is the trigger connected to Car's 12V+ Ignition that controls COM/NO[Normally Open] ports, in turn that makes the raspberry Pi to start.

    0
    None
    msubzwari

    1 year ago

    To use Pi Cam, how about separating the build in two boxes. One containing RPI 3, RTC and the two LM 2597 boards with Pi cam mounted on it. The other box containing the timer circuit. Only 4 wires to run between the two for the 12VDC inputs to the LM 2597 boards.

    0
    None
    ahernandez5

    1 year ago

    So, I'm looking into this, and the more I see the LM2596 triggering the 3.3v on the GPIO pins, why not an optocoupler, or even a mechanical relay switch to just cross the 3.3 to ground on the rpi, this way you don't have a whole component.

    I'm about to do this, as I've forked your github and about to add a raspicam version of your usb video recorder. I'll extend it a bit so I can do a push request, but the LM2596 on that gpio pins makes me nervous.

    I'm going to follow yours, then follow this one ( https://forum.allaboutcircuits.com/threads/12v-home-alarm-system-to-3v-raspberry-pi-connection.106444/ ) to compare, since I have several LM2596 kits I got from amazon.