Smart RC-car

by KobeDesp in Circuits > Raspberry Pi

217 Views, 1 Favorites, 0 Comments

Smart RC-car

287867109_701280067838823_1182838397989053835_n.jpg

This isn't your average RC-car. A mechanism to avoid crashing into the wall to prolong the lifespan of the car; a way to see if the batteries are nearly dead and a website with speedometer to see the current speed of the car.


Supplies

  • raspberry pi
  • relay on a PCB
  • 16x2 LCD display
  • ultrasonic distance sensor
  • voltage sensor
  • ninco Racers hyundai i20 WRC (or other rc-car with DC-motors)
  • MCP3008 chip
  • 74hc595 shiftregister
  • hall-effect sensor
  • active buzzer
  • 10k ohm potentiometer

Wiring

breadboard-LAPTOP-SU1FDN4E_bb.png
  • The LCD is connected to the Pi using a shiftregister.
  • For the ultrasonic sensor you need a 1k Ohm resitor for the echo pin after that you need a 2k ohm resitor to the ground and a wire to one of the pins on the raspberry pi.
  • The voltage sensor is connected to the Pi using a MCP wich is connected to the pi using the SPI pins on the Pi (do not forget the enable these with raspi-config). The voltage sensor is directly connected to the + and - of the car battery.
  • A relay is placed between one of the wires of the car dc motor and is connected with normal closed
  • For the buzzer the + is connected to one of the pins of the Pi
  • Between the hall sensors + and output you need to put a resistor with 10k Ohm, optionaly you can add a capasitor of 1 micro F between the + and - of the sensor

Making the Database

Screenshot 2022-06-20 165525.png
Screenshot 2022-06-20 165543.png
Screenshot 2022-06-20 165602.png
Screenshot 2022-06-20 165619.png

Make a table devices where all info about your different sensors and actuators are stored. Then make a table Actions where all different type of actions are stored. like reading data or activating an actuator. At last make a table called History where you keep track which device a certain action did so you're gonna need 2 FK's from both your other tables.

Writing the Backend Code

My code is in this github: https://github.com/howest-mct/2021-2022-projectone-despeghelkobe

Your code will be split up in 2 main files: frontend & backend. The frontend is for your website and the backend is where you will read your sensors, contol your actuator and send/get data from your database.


I made a main file named "app.py" where all my threads were running and made a folder named helpers where I put the code that could easily be placed in function to make my code look much cleaner and easier to understand.

There are 2 main Threads: one is for the reading of sensors and the other is for automaticaly opening my webpage on my raspberry pi screen if you connect via VNC viewer or if you attach a screen to it. You will also need to make a socket to communicate between you front- and backend and an API to easily get the data from you Database to your frontend.

The folder "repositories" is used for the communication between the backend and the database. And the "config.py" is where your database settings are stored.

Making the Website

Screenshot 2022-06-20 171754.png

This is a 2 page website where in the index you can see the speed, adjust the automatic stopping distance of the car, turn of the Pi, see the dashboard lights and manualy turn on/off the car.

On the data page you can see a graph of the voltage & speed over time and some of the last logs.

I worked mobile first and worked my way up the viewport size until I had desktop size. For the main structure of the site I used css grid a very usefull tool to make the layout of the page look attractive. To align the smaller elements I generally used flex-box.

my code: https://github.com/howest-mct/2021-2022-projectone-despeghelkobe/tree/master/front-end

Installing the Part on the Car

I used a prototyping PCB to solder all my components on it. Then placed a magnet inside the wheel and the hall-effect sensor near it. Then I put a relay (connected to the common and the normal closed) between the motor of the back wheels. I Attached the voltsensor to the wires comming from the batteries. On the PCB itself i soldered a t-piece for my raspberry pi, a shiftregister and a MCP3008. The LCD I installed in the roof of the car so that you can read it from behind the car and I installed the ultrasonic sensor at the front of the car so it could see how far it was from the wall (make sure you have long enough wires for this so you can easily assemble the car back together when everything is inside.

The Endresult

285284897_557109305806605_4640092828369180153_n.jpg
286258172_3234495543500442_2583533438569361168_n.jpg
286731545_1009502176424121_8144825078422142055_n.jpg

Now you will have a drivable car on which you can see the IP address to link to the site where you can view the data and see the live speed. You will also be able to change the automatic stopping distance of the car so that you don't drive against the wall.