Shareable Smartbike
Whenever I use my bike I tend to forget to turn on my lights when it gets dark. Also on my bike I don't have a way of knowing how fast I'm going.
So I've decided to make a shareable smartbike that keeps track of:
- Speed
- Location
- How long you've been using the bike
It also automatically turns the lights on or off. I used an RFID scanner so somebody else can use the bike without changing my data.
Supplies
- Raspberry Pi 3 (€32,49)
- SD Card (for RPi) (€13,99)
- GPS NEO 6M (for speed and location) (€15,99)
- Anker PowerCore 10400mAh (€29,99)
- RFID RC522 (€5,49)
- 16x2 LCD (€9,99)
- Elegoo Uno R3 Board (€9,34)
- LDR (€1,50)
- MCP3008 (ADC) (€5,98)
- A recycled light
- Wood for the housing (~€15,00)
- Cables (~€6,00)
Total price tag: €145.76
Make the Circuit
First you'll have to put everything together. I included a fritzing schema.
Note: Some of the components like the RFID scanner need to be soldered.
Set Up Python
For this project I'll be using python 3 and running the code with a python server. I'll link my github with my code.
First you need make connection with your Raspberry Pi via Settings > Build, Exection, Deployment > Deployment. Then you need to make an interpreter with all the packages required. On my Raspberry Pi I use python 3.5.
When you have made the interpreter you can make a new project and select the interpreter you just made for the project. Then you'll have to chose where to save the files on you PC and RPi.
Read the Data
After you've made the circuit and every components works you need read the data from sensors. My project was made using Python 3. In python I read out most of the data from the sensors using classes.
- The RFID scanner is used with the arduino (most info on how to use it here). I read out the data from the scanner with the arduino and send it to the RPi with Serial USB.
- The GPS module is also using serial communication. The data the GPS sends to the RPi is not that well formatted I used a library to parse the data and make it a lot easier to use. (Some more info on GPS data).
- The analog values from the LDR are converted using the mcp3008 (an adc), then I transform the value to a percentage.
Note: If you want to use 'while loops' in python to constantly get data while running a python server. You'll need use threading (more info on threading). Threading is easy to use.
The Database (mySQL)
Now that you have your data from the sensors you need some place to store the data. We will store the data in a relational database in mySQL.
I run the database on my RPi for this to work I need to have mariaDB installed on my RPi. Once you installed mariaDB and have it set up you can use the mySQL workbench on your PC to connect with you database on the RPi.
You'll need to make the ERD on the PC; forward engineer the ERD and export the database. Then you can import the dump (don't forget create schema) on the RPi via mySQL workbench.
Note: The table 'Bike_has_User' isn't required and will only be used if you plan on using multiple bikes. You can drop the table 'Bike_has_User' and link the table User with 'Datahistory'.
Link Your Python With the Database
Now that you have your database installed you can link your python with the database. Click on database (to the right of the screen) and add a new data source.
The database and the python script runs on the RPi so use the localhost IP. Use the user you previously created while you where setting up mariaDB.
Send Data to the Database
When you have everything set up you can start sending data to the database. I used a class helpers.Database in python for this (see my github).
The photo shows some example code.
Use the Data
With the class helpers.Database you can insert data into the database or get data from the database.
Now that everything works you can use the data from the database to display them on a website or wherever you want.
The Housing: Bottom
About the housing
Finally the housing for this project is made out of wood (310x130x110 mm). Most of the components are screwed to the wood except for the powerbank and the breadboard.
You can make the housing smaller if you solder the components. I didn't include a way to securely connect the housing to the bike, but there are many options.
Making the housing
You'll have to start with making the bottom part of the housing. Saw out a piece of wood (130x310 mm). Then attach the RPi with screw and glue the breadboard to the bottom part.
Note: You can make an identical part for the top of the housing
The Housing: Small Sides
When you finished the bottom part. You can start sawing the sides parts. Start with making the smaller sides.
First you'll have to attach the smaller sides. I used a extra piece of wood to connect all the parts together, this extra piece makes it easier.
The Housing: Large Sides
Now you'll have to make the larger sides. Once again saw the sides and attach them to bottom part using the extra piece of wood.
Adding a Hole for the LCD & LDR
You'll also need to make a hole for the LCD so you can see the IP address and display whether a user scans in or out.
Use the measurements of the LCD to decide how the what size the hole will have.
After you have inserted the LCD you need make sure the LDR is outside the housing. I used a tiny hole so the LDR can see daylight.
Attach the Arduino & RFID Scanner to the Side
After the housing is complete, you still need to attach the arduino & RFID scanner. You can attach them wherever you have room. But I recommend attaching the RFID scanner beneath the LCD so the user can see if he scanned in or out.