Project Smart Car
I'm crazy about older cars, but i love having the luxury and convenience of newer cars with sensors etc.
So I thought why not combine those two things?
I started thinking and soon I came to the conslusion of making a model of a real car with parking sensors, light sensor, a mini-display, LED's, speedwarnings etc. that easily can be transfered on a real car.
So if you also would like to learn how to upgrade your beautiful old car, then don't hesitate to read and follow my instructable!
Supplies
Above you can find bij BOM (Bill of materials). You can alsof find a small pdf of the link where you can get the components that i already had.
BOM = A BOM is a list of used products/goods that are incorporated into a manufactured product/end product.
Electronics
- Raspberry PI 3 model B (you can chose which model, I used this one. Make sure it's compatible.) 1x
- Arduino Uno Rev 3 (you can chose which model, I used this one. Make sure it's compatible.) 1x
- Jumper wires male - male (This comes in large amounts, I chose a pack of 40 pieces) 1x
- Jumper wires female - male (This comes in large amounts, I chose a pack of 40 pieces) 1x
- Light dependent resistor (LDR) 1x
- JSN-SR04T sensor (distance sensor) 4x
- Speed sensor 1x
- Piezo (passive) buzzer 1x
- White/transparent LED's 2x
- LCD - display 1x
- Trimmer (for the brightness of the LCD)
- Grove - LED String light (5m so it's easily to transfer to a real car instead of a model) 1x
- Button 2x
- DS18B20 temperature sensor
- Level shifter (5V-3.3V)
- Powersupply (5V)
Materials
- Woodglue
- screws
- wood (look at the first step for size)
- axes
- wheels
- hinges
- lego blocks
- plexiglass
- rubber caps
Tools
- Saw 1x
- Drilling machine 1x
- screwdriver
- rocker saw
- sandpaper
Making the Model Car
I started making the car first, so that I exactly knew how much space I had for my electronic scheme. If you want to start coding first you can go to step 10.
The first thing you need to do is very important and that is choosing the right wood. Go to your nearest woodshop and ask them for small editable wood. This is because you should be able to easliy saw out the right shapes and curves of the wood.
Cut the Wood
Cut the wood into the sizes you want. If you want to use my sizes go check the PDF below. In this PDF you will find drawings of every side of the car with the right sizes.
Downloads
Making the Base of the Car
In this step you need to make the base of the car. The first thing you need to do is cutting the holes for the wheels. You do this in the base wooden plank of the car. Then you need to add 4 small planks with woodglue on this base plank (as you can see on the picture above). After this, make 4 holes in 2 of the small planks for the metal axis for the wheels. Then you can add bolts to hold the pipes in the right place. After this add the wheels to the pipes and again add bolts for strength.
Finish the Base of the Car
This step is pretty easy. Take a wooden board and cut it exactly like the base board. Then screw this on the base and the base is done! Note: you can remove the screws later for installing the distance sensors or you can just wait with these screws until your done.
Adding Some Details (optional)
This step is completely optional. I added some lego blocks as lights for detail. You can do the same as I did or you can just leave it like it is.
Adding the Body
In this step we will see how I made the body of the car. First I saw two holes in my base (you can find this on the picture) for my cables of my distance sensors. Then I added 4 small planks and sawed out the 4 wheels on the 2 sides. The next thing I did was adding 3 more little planks on the inside of the car with hinges for the hood and trunk. I also add some rubber so that my hood has a soft spot to rest on.
Hood and Trunk
In this step you need to add the hood and trunk of the car. Saw the wood and add them to the hinges.
Finishing the Car
The third last step you need to do is drill 2 holes for the LED's that serve as the headlights. Do this on the front of the body. The holes should only be 5 millimeters (see picture). The second last step you need to do is to attach the base and the body together. Do this with 4 screws. Now the last thing you need to do is to add a windshield for the car. You can use whatever you want, for example cardboard or plastic... And so the car is ready.
Building the Circuit
Underneath this you can find a PDF of the both electric diagram and breadboard scheme of the circuit.
Components explained:
1. Arduino
I used the Arduino to capture my distance sensor data and send it to the Raspberry PI with Serial communication.
2. 4x JSN SR-04T (5V):
This is a distance sensor that measures the distance between the sensor and any object. Note: This is a waterproof sensor but cannot measure distances shorter than 20 cm (I will explain how I fixed this later in my Arduino code in step 10.
3. LDR (5V)
This is a light dependent resistor and simply measures the light intensity. This is used for the recommendation of the status of the headlights.
4. Level shifter (5V - 3V)
This is used to connect the Arduino (high voltage 5V) to the Raspberry PI (low voltage 3.3V).
5. Raspberry PI
This is the brain of the program. The RPI, short for Raspberry PI will continually ask the Arduino for the data and will do all the things such as displaying the temprature, take care of the database...
6. DS18B20
This is used to measure the temprature.
7. Grove LED (3.3V)
I used this for the atmosphere inside the car. This changes if the speed changes. If the speed goes up, the lights go up and vice versa.
8. LCD display (5V)
The LCD display has 3 states and can be changed with a button: If the LCD is in the first state, he will display the IP-address of the RPI. If the LCD is in the second state he will display the speed (in km/h) and the temprature (every 10 seconds) and the brightness (also every 10 seconds).
9. Trimmer (5V)
This is used to change the brightness of the LCD display.
10. 2x button
One button is used to change the state of the LCD. And the other one is used to turn ON/OFF the headlights of the car.
11. 2x LED (white)
These two LED's are used as headlights of the car. They can be turned on with the button.
12. Active buzzer (3.3 V)
This is used to give the distance from an object. When the car is close to a wall for example, the buzzer will beeb very fast. When the car is far away the buzzer will stop (longer than 70 cm) or if it's less than 70 cm the buzzer will beeb very slow.
13. Powersupply (5V)
This is used to power the LCD and trimmer.
14. Speedsensor (3.3V)
This is used to measure the speed of the car.
Code for Arduino
You can find the code I worked with for the Arduino below this block of explanation.
Short explanation:
The Arduino code is used for the 4 JSN SR-04T sensors. The Arduino continuously asks the value of the sensors and makes a small calculation and sends this back to the RPI.
Declaration:
The declaration section is used to declare all of the things I needed.
Setup:
The name explains itself. We do the setup of everything we need.
Loop:
The loop section continuously repeats the code inside. First we set the trigger pin to low for 2 microsenconds. Then we send a 10 microseconds high to te trigger ranging. And then I place it back to low. After this I read the time that has passed for the pulse.
To calculate the distance I divide the time with 58.
Then it checks if serial is available and it checks if the message from the RPI is correct. It does some calculations to know how far the distance is. Important here is the >24 and <70, this is how it knows that the object is very close or very far away. It does this because I measured a previous distance.
It adds everything to a list and then sends it back to the RPI.
Float convertLDRToProcent
This function calculates the brightness in procent of the LDR.
Downloads
Getting the RPI Ready
To be able to work with de RPI we need to get a few things in order beforehand.
Frist we need to put an image on the SD-card of the RPI.
- Download the image below (naam).
- Put the image on the SD-card (minimum 8 GB space required on SD-card). A handy tool to do this is Win32 Disk Imager.
- Safely remove the SD-card from your computer (safely remove: At the bottom right click on the arrow, then right click on the SD card and choose remove safely).
Connect the RPI
- Boot the RPI.
- Connect the RPI to your pc with an ethernet cable.
- Make an ssh connection using putty to the adress: 192.168.168.168 for the user *student* and password *W8w00rd*, remove the '*'.
Note: This image is written for azerty keyboards. The password in qwerty is: *Z!zààrd*, remove the '*'.
Setting up the RPI
- Type `sudo raspi-config`.
- Choose Advanced > Expand Filesystem.
- Reboot the PI (use command: sudo reboot and fill in the password: *W8w00rd*, remove the "*").
WIFI connection
- Type `sudo -i`
- Type `wpa_passphrase >> /etc/wpa_supplicant/wpa_supplicant.conf`. Replace and to your own SSID and password, remove the "<>".
- Type `wpa_cli -i wlan0 reconfigure`
- (Optional) type `wget www.google.com` to see if it's working.
Upgrade
If you want to upgrade the image to a newer version.
- Type `apt update` to see which updates are available
- Type `apt upgrade` to install the available updates.
- Type `Y` if you are asked if you are sure.
Configuration MySQLWorkbench
- start MySQLWorkBench on your PC.
- Make a new connection in MySQLWorkbench.
- Under Connection Method, choose Standard TCP/IP over SSH.
- SSH Hostname: `192.168.168`.
- SSH Username: `student`
- SSH Password: `W8w00rd`. Save this if possible.
- MySQL Hostname: `127.0.0.1`.
- MySQL Server Port: `3306`.
- Username: `student`
- Password: `W8w00rd` Save this if possible.
Configuration Visual Studio
- Open Visual Studio
- Install the extension : Remote-SSH.
- Press F1 and tap SSH.
- Select the option: Remote-SSH: Add New SSH Host.
- Tap `ssh student@192.168.168.168 -A`
- Choose an option to save the file.
- Press F1 and tap SSH.
- Choose the option: Remote-SSH: Connect To Host.
- Choose the option: 192.168.168.
- A new window will open and the password for the RasPi will be requested.
- Type `W8w00rd`.
- After this, Visual Studio Codede connection will open and install some things on the RasPi.
> Be patient. It takes a little longer the first time.
Cloning GitHub repository:
- Create a repository. If you don't know how watch a video about it.
- Click on the icon: Source Control in Visual Studio Code.
- Past your link to your repository.
- Press yess if Visual Studio Code asks to open the repository.
- You can also colne my repository from step (nog aan te vullen)
Frontend in apache
- Surf to: http://192.168.168.168.
- Normally you should see the Apache2 Debian Default Page.
- Type `sudo -i`
- Type `nano /etc/apache2/sites-available/000-default.conf`.
- Use the arrow keys to navigtate to "DocumentRoot /var/www/html or `DocumentRoot /home/student//Code/Frontend".
- Change this to `DocumentRoot /home/student//Code/Frontend`.
- Press: Ctrl + x, type `Y` and press: Enter.
- Type `service apache2 restart`.
- Now we have to set the permissions on the root folder correctly.
- open `nano /etc/apache2/apache2.conf` and use the down arrow to look for the following lines:
`\\
Options FollowSymLinks\
AllowOverride All\
Require all denied\
\`
Change this to:
\\
Options Indexes FollowSymLinks Includes ExecCGI\
AllowOverride All\
Require all granted\
\_\`
- Press: Ctrl + x, then type: `Y` and press: Enter.
- Type: `service apache2 restart`
automatic start-up (optional)
- Create a file named _myproject.service_.
- Place the following code in the file:
`[Unit]`
`Description=ProjectOne Project`
`After=network.target`
`[Service]`
`ExecStart=/usr/bin/python3 -u /home/student//Code/Backend/app.py`
`WorkingDirectory=/home/student//Code/Backend`
`StandardOutput=inherit`
`StandardError=inherit`
`Restart=always`
`User=student`
`[Install]`
`WantedBy=multi-user.target`
- As root user, copy this file to _/etc/systemd/system_ with the command `sudo cp myproject.service /etc/systemd/system/myproject.service`.
- To test the file, type `sudo systemctl start myproject.service`
- To stop the file, type `sudo systemctl stop myproject.service`
- If all works well, you can have the script start automatically after booting:
`sudo systemctl enable myproject.service`
Database
This is a short explanation for the database. In MySQLWorkbench, you can recreate the model as shown in the picture and then you can work with forward engineering to make the database.
- Go to: Database
- Click: Forward Engineer...
RPI Code: Short Explanation
Underneath you can find the my repository where you can find the code of my entire project.
You can also find code for a website. The app.py does the most of the things. I call it the brain of the smart car.Take a look in the code. You will find comments in the code that will give some additional explanation/information. You can find my repository by clicking on this link.
Putting Everything in the Car
As you can see from the picture it is difficult to put everything on 3 breadboards and still keep it clean. I placed everything in the hood of the car.
Enjoy the Smart Car!
This is the end of the instructable, I hope you learned something and I hope you had fun making The Smart Car!
If you have any questions, don't hesistate to ask them in the contact section!