Wouldn’t it be cool if the government promoted environmental sustainability by offering rebates for distance biked? This would encourage people to bike rather than drive, which would decrease our carbon emissions. This was the idea behind our project. We imagined that we could create a bike odometer that would measure distance traveled, and then at the end of each month, the government could in return issue a cash rebate dependent upon distance traveled to encourage sustainability.
For this project, we created a bike odometer using the Agilent Basys3 Board. Using a hall sensor and a magnet, the sensor detects each rotation of the bike wheel and then shows the distance traveled on the Basys seven-segment display. The magnet is attached to the wheel and every time the magnet passes the hall sensor it closes the gate in the hall sensor, making the voltage that it outputs equal to zero.
The total distance traveled is calculated by multiplying the number of wheel rotations by 2*pi*r, where r is the radius of the bike tire in centimeters, which is input by the user in binary using the Basys switches. There is also a reset button (bottom button on the basys board), that allows the odometer to reset to 0 when pressed.
The 7-segment display on the basys3 board displays the total distance traveled from 0-9999 meters. Once the number of rotations reaches 9999, it resets to 0000.
Basys 3 Board
Hall Sensor(non-latching, U58 337)
4.5 - 5.5 V power supply
Solder and Soldering Iron (optional)
Here is a link to all of our VHDL: https://drive.google.com/open?id=0B_-Bu2KKfEn1RVFEYWx6VTh6R3c
Step 1: Wiring Up the Hall Sensor
First start by setting up your hardware. For this step, you will need four wires, a breadboard, your hall sensor, and a 10,000 ohm resistor. Connect these components as shown above in the schematic. The 1st picture shows what the set up should look like on the breadboard.
If you have a soldering iron at your disposal, you can solder components together, as shown in the 2nd picture. This makes it easier to attach the system onto the bike, which is what we ended up doing.
Step 2: Connect Sensor to Basys3 Board
In order for the hall sensor to work, we first need to supply a voltage to it. The way the hall sensor works is while there is no magnetic field, the entire voltage supplied to it can be measured across the sensor. For example, if we supply the sensor with 3 volts, using a voltmeter, we would find that there are 3 volts across it. However, if the magnet is placed in front of the sensor, then there would be approximately 0 v across it. (the magnet must be placed in front of the labelled side of the sensor in order for it to work properly).
For all the wiring, we have included a Basys3 port diagram (from the Basys3 Reference on digilentinc.com) that labels each of the ports. We have included which wires need to go to which port.
V+: Start by connecting the far left pin of the sensor (pin 1) to the 3V3 pin on the JA port of the Basys3 (JA12). This is pictured as the top red wire.
V-: Connect the far right pin (pin 3) to JXAC1. This is pictured as the bottom red wire. This will read the voltage of the hall sensor into the Basys3 digital to analog converter. Then connect the negative of this port to ground by connecting the JXAC5 to the ground port, which is shown as the yellow wire.
GROUND: Then connect the middle pin of the sensor (pin 2) to the GND pin on the board. This is represented by the two black wires. You will need to connect one of the wires to the GND pin in the JA port (top left port, JA11) and connect the other wire to GND pin in the JXAC port (bottom left port, JXAC11).
At this point, all of the hardware setup for this project should be completed.
Step 3: Black Box Diagram for VHDL
With the majority of our hardware set up, here is a brief overview of how the components we designed work together to produce the desired functions.
The voltage from the hall sensor will be continuously read into the internal analog to digital converter (XADC) and will be converter to a usable binary number. This binary signal then functions as the clock signal for the counter module (counter16), which will count one rotation every time a voltage of roughly 0V passes from the hall sensor. The distcalc module preforms the calculations necessary to turn the number of rotations from the counter into the number of meters traveled. Finally, the calculated distance is displayed on the board's 7 segment display.
Here is our black box diagram for our project, we have four modules, distcalc, sseg_dec, counter16, and our analog to digital converter.
Step 4: Create Counter Module
Our counter module is a sixteen bit counter that takes in two inputs, a clock signal and a reset, and has an output q. When reset is 1, the counter resets to 0000. Otherwise, on the rising edge of clock, the counter counts up by 1. Our clock signal actually is our bike wheel, for every time the bike rotates once and the hall sensor is activated, that is considered one cycle of clock.
The reason why we chose a 16 bit counter is because our display can only represent up to 9999, which requires 14 bits to write in binary. However, we had the VHDL for a 16 bit counter so we just used that. Once the display gets to 9999, it will reset to 0000.
Above is our VHDL for the counter.
Step 5: Create Distance Calculator Module
Our distance calculator module has two inputs, number (which is the number of bike wheel rotations), and radius (wheel radius in centimeters), and one output, distance.
We calculated distance travelled by multiplying the number of rotations by 2 * pi * r. This distance is output every time the magnet passes the hall sensor (every time the wheel spins).
One issue we ran into was trying to calculate the distance using decimal numbers. VHDL doesn’t accept decimal numbers and 2pi = 6.28.The way we got around this was by multiplying 2 pi by 100, making it 628. VHDL only accepts binary, so we converted 628 to binary, multiplied it by the number of rotations, and then divided it by 10,000 in binary. This coverts the final distance travelled measurements to meters.
The VHDL for this module is included above.
Step 6: Seven Segment Module
Our seven segment display was not entirely designed by us, rather we modified a previous component we had been given by our professor, Andrew Danowitz. This original component can be seen in the first file attached to this page. This original component was designed to handle 8 bit inputs, so we had to modify this cad to accommodate for 16 bit values, which is necessary in our design in order to display up to 9999 meters. The modified file is attached as well (sseg_dec(1)). Most of the modifications lie within adding an additional msb that allows for more bits to be inputted in the module. The modifications to our 7 segment display were also largely made possible with help from Professor Danowitz.
Step 7: Analog to Digital Module
This module reads in the analog voltage from our hall sensor, and converts this signal to a 16 bit binary number that is representative of the voltage. We chose to use roughly 0.18 V as our threshold voltage, but it can be any value just above 0. When the hall sensor gives a reading less than the threshold voltage we return a '1' and when the reading is greater than the threshold voltage we return a '0'. This signal then functions as our clock signal. This is then read in by the counter as the number of rotations of the bike wheel.
This is a fairly complicated step if you have never used the basys3's XADC before. In order to get more information on how the XADC works and how to set it up, see this instructable made by a past group of Cal Poly students: https://www.instructables.com/id/FPGA-Solar-Panel-Optimizer/step4/Analog-to-Digital-Converter-ADC/
Step 8: Attach Sensor to Bike
Before attaching the sensor and magnet to your bike, it is important to determine the correct orientation of your magnet to your sensor. Your hall sensor will only work (as desired) if the correct pole of the magnet passes the correct side of the sensor. We recommend testing your sensor and wiring before attaching the device to your bike. This is very easy to determine. Do this by wiring your sensor as explained above, then grab your magnet and move it in front of the face of your sensor (the labeled side), passing by it in slow controlled sweeps. This could take a minute to figure out since every magnet is different, but after a short while of doing this, paying attention to which side you are orientating towards the front of the sensor, you will soon find the desired result. Mark your magnet to know which part should sweep by your sensor when attached to the bike.
You can now mount your sensor to your bike (make sure you leave enough wire length to reach your basys). Lay a piece of tape on the front fork of your bike, close to where the fork meets the wheel, towards the inside of the spokes. You place the tape down as a foundation to prevent unintentional grounding on the bike frame fro when you actually place your sensor there. You want to mount the sensor in a location where the spinning magnet mounted to your spokes has the smallest radius while still passing correctly by your sensor. You do this to slow down the speed of the magnet passing by your sensor. This increases accuracy. In other words, you do not want to mount any components near the outside radius of your wheel because the magnet will pass your sensor much too fast.
Now, place your sensor on top of the first piece of tape, with the face pointed toward the wheel. Make sure all wires leaving your sesnor are running up towards the handle bars. This step can be done in a number of different ways. We simply taped the sensor down to the front fork of the bike. See the first picture (bike is orientated upside down).
Once this is done, it is now time to mount your magnet to your spokes. Take into consideration the correctly marked side, determined earlier, that you want to pass by your sensor's face. Simply place the magnet on the spokes, correctly orientated, and wrap a piece of tape around it. For us, this method was plenty secure, because the magnet stuck very securely on its own to the spokes just magnetically. See Picture 2.
Your sensor is now attached! Now just run your wires up towards the handle bars, avoiding moving objects and securing loose wire with tape to the frame of your bike.
Step 9: Attach Basys to Bike
This step is very easy and can be done by the method of your choice. We chose to place the basys board directly on to the handle bars, wrapping it in tape, safely securing the board. Attach the wires leaving your sensor to the correct ports of the basys board. Secure with tape to your judgement.
Step 10: Add Power Supply
We used 3 AAA batteries as a 4.5 volt power supply, you can use whatever you would like to power the Basys 3 board. We shorted one of the battery slots of our battery holder because we only needed 3 batteries opposed to four.
For connecting our voltage supply to the Basys3 we used this link for information: https://reference.digilentinc.com/basys3/refmanual
There is also a screenshot of this info above.
This allows us to ride the bike wherever we want without having to connect the basys to the computer for power.
Mount your power supply to your handle bars (we luckily had a very conveniently flashlight mount that held our power supply perfectly onto the handle bars) and attach the two wires leaving your power supply to the two correct pins of your basys explained above. You can chose to solder these directly to the board, but we just wrapped them around the pins and taped them securely, see picture 3.
Step 11: Ride Away!
Now you're ready to use your odometer! After generating your bitstream and programming your Basys3, enter your bike tire radius and you are all set.
Once again, for any additional questions, here is a link to all of our VHDL: https://drive.google.com/open?id=0B_-Bu2KKfEn1RVFEYWx6VTh6R3c