The project’s elaboration consisted in the assembly of a “game” with the objective to pedal in an ergometer bike connected to a generator and a tower of lamps that are activated as the engine speed increases – which occurs accorded to the bicycle pedaling. The system was based on reading – through an analog port of an Arduino Mega – the instant voltage generated, then transmitting this data to a Raspberry Pi 3 via serial RX-TX communication and the subsequent activation of the lamps via relay.
Step 1: Materials:
- 1 Raspberry Pi 3;
- 1 Arduino Mega 2560;
- 1 Relay Shield with 10 Relays 12 V;
- 10 Incandescent Lamps 127 V;
- 1 Ergometer Bike;
- 1 Electrical Machine (Generator) 12 V;
- Resistors (1x1kΩ, 2x10kΩ);
- 1 Electrolytic Capacitor 10 µF;
- 1 Zener Diode 5.3 V;
- 1.5 mm Cable (red, black, brown);
- 1 MDF tower with support for 10 lamps.
Step 2: System Blocks Diagram:
Step 3: System Operation:
The system is based on the transformation of the kinetic energy generated when cycling the bicycle in electric energy responsible for the activation of the relays that will turn the lamps on.
The voltage generated by the generator is read by an analog pin of Arduino and is sent via RX-TX to the Raspberry Pi. The activation of the relays is proportional to the voltage generated - the higher the voltage, the more relays will be triggered and more lamps will light up.
Step 4: Mechanics Aspects
In order to mechanically couple the DC generator to the bicycle, the belt system had to be replaced by the system used on common bicycles (consisting of a crown, chain and pinion). A metal plate was welded to the bicycle frame so that the engine could be secured by screws. After that, the pinion was welded to the generator shaft so that the chain could be placed, interconnecting the pedal system to the generator.
Step 5: Voltage Reading:
To read the generator’s voltage using Arduino is necessary to connect the positive pole of the electrical machine to the A0 pin of the controller and the negative pole to the GND – to avoid that the maximum voltage of the generator is greater than the 5 V of the Arduino pins, a voltage filter using a capacitor of 10 µF, a resistor of 1 kΩ and a Zener diode of 5.3 V was constructed and connected between the controller and the generator. The firmware loaded in Arduino is very simple and consists only of reading an analog port, multiply the value read by the constant 0.0048828125 (5/1024, that is the Arduino’s GPIO voltage divided by the number of bits of its analog port) and sending the variable to the Serial – the code will be available in the article.
The procedure for enabling RX-TX communication in Raspberry Pi is a bit more complex, and you must follow the procedure described in the link. Briefly, you need to edit a file called “inittab” – located in “/etc/inittab” –, comment the line “T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100” (if the file isn’t founded in Raspberry’s OS, you must enter the command: “sudo leafpad /boot/config.txt” and append the line “enable_uart=1” to the end of file). Once this is done, you must reopen the LX Terminal and disable the Serial with the commands "sudo systemctl stop serial-getty@ttyS0.service" and "sudo systemctl disable serial-getty@ttyS0.service". After that you have to execute the command "sudo leafpad /boot/cmdline.txt", delete the line "console = serial0,115200", save the file and restart the device. In order for RX-TX communication to be possible, the Serial library must be installed on Raspberry Pi with the command "sudo apt-get install -f python-serial" and import the library into the code by inserting the "import serial" line, initializing the serial by inserting the line "ser = serial.Serial (" / dev / ttyS0 ", 9600)" and the read of the voltage sent by the Arduino using the command “ser.readline()” – the full code used in Raspberry will be made available at the end of the article.
Following the procedure described above, the read and send voltage step is complete.
Step 6: Arduino Programming:
As previously stated, the code responsible for reading the voltage generated when cycling is very simple.
Firstly, it’s necessary to choose the A0 pin as the responsible for reading the voltage.
In the "void setup ()" function, you need to set pin A0 to INPUT with "pinMode(sensor, INPUT)" command and select the serial port transmission speed using the "Serial.begin(9600)" command.
In the "void loop ()", the "Serial.flush ()" function is used to clear the buffer every time it terminates sending information via serial; the voltage reading is performed by the function "analogRead (sensor)" – remembering that it is necessary to convert the value read by the analog port to Volts – process cited in the "reading voltage" section of the article.
Also, in the "void loop ()" function, it is necessary to convert the variable x from float to string, since this is the only way to send the variable via RX-TX. The last step in the loop function is to print the string in the serial port so that it can be sent to Raspberry - for this you must use the "Serial.println (y)" function. The line "delay (100)" has been added to the code only so that the variable is sent in intervals of 100 ms - if this time is not respected, the Serial overload will occur, generating possible crashes in the program.
Step 7: Raspberry Pi 3 Programming:
Step 8: Electric Scheme:
The Arduino and the Raspberry Pi 3 are powered by a 5V source with 3A current.
The electrical circuit starts with the connection of the DC generator (coupled to the bicycle) to the Arduino through a voltage filter composed of a Zener diode of 5.3V, a capacitor of 10μF and a resistor of 1kΩ – the filter input is connected to the generator terminals and the output is connected to the A0 port and the GND of the controller.
The Arduino is connected to Raspberry via RX-TX communication – performed through a resistive divider using 10kΩ resistors (required by the controllers' ports operating at different voltages).
Raspberry Pi's GPIOs are connected to the relays responsible for turning on the lamps. The “COM” of all relays was interconnected and connected to the phase (AC grid) and the “N.O” (normally open) of each relay was connected to each lamp and the neutral of the AC grid was interconnected to all the lamps. Thus, when the GPIO responsible for each relay is activated, the relay is switched to the phase of the AC network and turn on the respective lamp.
Step 9: Results:
After the final assembly of the project, it was verified that it worked as expected – according to the speed that the user pedals on the bike, more voltage is generated and more lamps light up.