Monitoring and Speed Control of E-Bike Using STM Controller
Monitoring and Speed Control of E-Bike Using STM Controller
Abstract: E-bikes are the transport medium of our future. We are moving towards the electric
vehicles era leaving behind the fuel based mechanisms. Well in case of e-bikes there are 3 major
components required.
• E-bike Motor
• E-bike Battery
• E-bike Controller
We here propose to develop and test a working e-bike controller. The e-bike controller will be
performing the following operations:
The system makes use of an STM32 controller along with a throttle input, speed sensor for tyer
speed, switch, motor driver, e-bike motor, battery and OLED display to develop the system. We
will hereby focus on throttling and speed display part of e-bikes while developing this controller.
The STM controller constantly monitors the throttle values. The throttle consists of a throttle
position sensor (TPS). Non contact type TPS work on the principle of Hall effect or inductive
sensors, or magnetoresistive technologies, wherein by and large the magnet or inductive circle is
the unique part which is mounted on the butterfly valve choke spindle/shaft gear and the sensor
and sign handling circuit board is mounted inside the ETC gear box cover and is stationary. At the
point when the magnet/inductive circle mounted on the spindle which is rotated from the lower
mechanical stop to WOT, there is an adjustment of the magnetic field for the sensor. The
adjustment of the magnetic field is detected by the sensor and the voltage created is given as the
input to the ECU.
The Throttle signal is processed by the controller and it then operates the motor through motor
driver. The motor voltage is varied as per throttle values in order to control its power and speed.
Also the controller constantly monitor speed sensor values. The peed sensor works on hall effect
principle to constantly transmit the wheel RPM.
This RPM value is displayed on the LCD display by the controller. The motor speed and sensor
monitoring is turned off when the main switch s turned off. The complete process restarts as soon
as the switch is turned on. Thus we successfully develop and test our own E-bike controller using
STM
STM32 CONTROLLER
This is STM32F103C8T6 Minimum System STM32 ARM Core Board. This board is a low-cost
Minimum System Development Board for ARM Microcontroller STM32F103C8T6.
Board is suitable for learners that want to learn the STM32 microcontroller with ARM Cortex-M3
32-bit core.
• The STM32 is a very common type of microcontroller used in numerous types of devices. It
also provides facilities to linking with other types of microcontrollers.
• The STM32 series of MCUS which created by the STMicroelectronics consists of ARM
Cortex-M thirty two-bit processor core.
• In this microcontroller series and parallel communication system exit through which numerous
external devices such as camera, sensors, motors, etc can be connected.
• Every STM32 MCU also consists of inner flash memory and random access memory.
• The operation range offered by the STM32 is a little bit costly. There are subseries of STM32
like STM32F0 and STM32f1 which operate with the clock signal of having frequency twenty
four megahertz and exits in a casing having sixteen pinouts.
• Another category of STM32 series is STM32H7 which works at the four hundred megahertz
frequency and exits in a casing having two forty pinouts.
• There are some types of STM32 exits which used are exists with the floating-point unit or FPU
and used in high-level numerical processing applications.
• These modern categories of MCU have some features of microprocessor with the
microcontroller.
• For such applications that operate on less power or are portable devices STM32L series is
created.
Features of STM32
• These are some features of STM32 which are described here with the details.
• In this module flash memory, up to the one megabyte is used.
• An OTP of five hundred twelve is used in this module.
• Static random access memory of one twenty-eight byte is used in these modules.
• To provide support to the flash memory static RAM PSRAM flexible static memory controller
is used.
• Its operating voltage is from 1.8 volts to 3.6 volts.
• The crystal oscillator of four to twenty-six megahertz is used in this module.
• It has an inner sixteen megahertz factory trimmed RC.
• It uses a thirty-two-kilo hertz oscillator for RTC (Real-Time Clock).
• It has an inner thirty-two kilohertz RC after calibration.
• The modes which it has are sleep stop and standby modes.
• The battery is used to provides back to the RTC, 20 by 32 backup registers, and four kilobytes
static ram.
• This module consists of 3 by 12-bit o.5 microsecond analog to digital converter having twenty-
four channels.
• It consists of 12 sixteen-bit and 2 thirty bits timers.
• It comprises of one thirty-six inputs and outputs having a frequency of sixty hertz.
• It has one thirty-eight input and outputs operating at five volts
• This module consists of 3 I2c interfacings.
• It has 4 USART and 2 UART and 3 SPI.
STM32 PINOUT
• The main pinouts of the STM32 microcontroller are described here with the details.
CN6
• It is a power supply pinout at this pinout 3.3 volts are provided.
RESET PIN
• This pinout is used to reset the microcontroller.
+3.3 volts pin
• From this pinout, 3.3 volts are taken out as output and used to provided power microcontroller.
+5 volt
• It is a five-volt output pinout.
GND
• It is ground pinout.
CN5
• it is combination of pinout D8 to D15 these are digital pinouts and used for SPI.
D13, D12. D11 and D10 Pinouts
• These pinouts operate as a serial clock, master in slave out, master out slave in, and SC pinout
for SPI (Serial Peripheral Interface) transmission.
CN9
• These are digital pinouts and comprises of D0 to D7 pins.
D0 and D1
• These 2 pinouts operate as receiver and transmitter for USART (Universal Synchronous
Asynchronous Receiver Transmitter) transmission.
CN7
• These are digital port C pinouts and comprises of PC0, PC1, PC2, PC3, PC10, PC11, PC12,
PC13, PC14, PC15.
PD2
• It is port D input-output pinouts.
PA0, PA1, PA4, PA13, PA14, PA15 pinouts
• These are pinouts of port A.
PB7, PB8, and PB9
• These are pinouts of port B.
PH0 and PH1
• These are pinouts of port H.
18-0-18 5A Center Tapped Step Down Transformer is a general purpose chassis mounting mains
transformer. Transformer has 230V primary winding and center tapped secondary winding. The
transformer has flying colored insulated connecting leads ( Approx 100 mm long ). The Transformer
act as step down transformer reducing AC - 230V to AC - 18V.
The Transformer gives outputs of 18V, 18V and 0V. The Transformer's construction is written below
with details of Solid Core and Winding.
The transformer is a static electrical device that transfers energy by inductive coupling between its
winding circuits. A varying current in the primary winding creates a varying magnetic flux in the
transformer's core and thus a varying magnetic flux through the secondary winding. This varying
magnetic flux induces a varying electromotive force (E.M.F) or voltage in the secondary winding. The
transformer has cores made of high permeability silicon steel. The steel has a permeability many
times that of free space and the core thus serves to greatly reduce the magnetizing current and
confine the flux to a path which closely couples the winding.
it features linear control over E-Bike motor and lets you change the speed of the vehicle
according to your requirement. It obtains a direct connection with the E-Bike Controller
Circuitry through the wire attached to it.
Wire Configurations:
Red Supply
Black GND
Green Signal
Specifications :-
Type Twist Throttle
Inner diameter of handle 23 mm.
Inner Total length 120 mm.
Connection Wire: Red Supply, Black GND, Green Signal.
OLED Display
This is a 0.96 inch blue OLED display module. The display module can be interfaced with any
microcontroller using SPI/IIC protocols. It is having a resolution of 128x64. The package includes
display board,display, 7 pin male header presoldered to board.
OLED (Organic Light-Emitting Diode) is a self light-emitting technology composed of a thin,
multi-layered organic film placed between an anode and cathode. In contrast to LCD technology,
OLED does not require a backlight. OLED possesses high application potential for virtually all
types of displays and is regarded as the ultimate technology for the next generation of flat-panel
displays.
OLEDs basic structure consists of organic materials positioned between the cathode and the anode,
which is composed of electric conductive transparent Indium Tin Oxide (ITO). The organic
materials compose a multi-layered thin film, which includes the Hole Transporting Layer (HTL),
Emission Layer (EML) and the Electron Transporting Layer (ETL). By applying the appropriate
electric voltage, holes and electrons are injected into the EML from the anode and the cathode,
respectively. The holes and electrons combine inside the EML to form excitons, after which electro
luminescence occurs. The transfer material, emission layer material and choice of electrode are the
key factors that determine the quality of OLED components.
Setting up SPI/I2C Connection with GMS096A OLED Module
Being a new entry to the market, only limited resources are available on this small piece of miracle
(GMS096A). I2C/SPI configuration always demands helpful resources as in any case. For the SPI
setup, the module comes in 4 wire SPI configuration by default and to make it work with the
arduinos you can use these libraries from Adafruit.
For the I2C setup it demands a little bit of work on the module. Actually it was one of our customers
who shared these simple configuration steps with us, start with resoldering the resistor from
position R3 to R1 and then short the R8 resistor with some solder tin (0 Ohm resistor). The R6 and
R7 pullup resistors are already soldered, nothing to do there. Once done, the module is ready for
I2C communication! The CS Pin is not necessarily needed, so just connect it to GND. The DC Pin
selects the address. For standard address wire it to GND. The RES-pin needs a low pulse at startup
and high voltage during operation (as in SPI mode), a 100nF capacitor to GND and a 10k res to
VCC would be ideal!
Features:
The organic light-emitting diode (OLED) display that we’ll use in this tutorial is the SSD1306
model: a monocolor, 0.96-inch display with 128×64 pixels as shown in the following figure.
The OLED display doesn’t require backlight, which results in a very nice contrast in dark
environments. Additionally, its pixels consume energy only when they are on, so the OLED
display consumes less power when compared with other displays.
The model we’re using here has only four pins and communicates with the Arduino using I2C
communication protocol. There are models that come with an extra RESET pin. There are also
other OLED displays that communicate using SPI communication.
Pin wiring
Because the OLED display uses I2C communication protocol, wiring is very simple. You just need
to connect to the Arduino Uno I2C pins as shown in the table below.
Vin 5V
GND GND
SCL A5
SDA A4
If you’re using a different Arduino board, make sure you check the correct I2C pins:
Libraries
To control the OLED display you need the adafruit_SSD1306.h and the adafruit_GFX.h libraries.
Follow the next instructions to install those libraries.
1. Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The
Library Manager should open.
2. Type “SSD1306” in the search box and install the SSD1306 library from Adafruit.
3. After installing the SSD1306 library from Adafruit, type “GFX” in the search box and install
the library.
If you are wandering to build an E-bike and don't know what will be the best Motor for you then
worry no more, we have got your back.
Ebike MY6812 120W 12V DC Motor is a popular reduction dc motor & its simply the most
commonly used motor for scooters, bikes, and quads available in the market! Also due to its
robustness, it is also in many DIY projects like Segway, e-cars, etc, and in many robots like ATV
robots, combat robots, etc.
This motor is great for those who want to make their own custom electric vehicle, whether its a
scooter, electric bicycle, or something the world isnt even ready for. This electric motor produces
more low-end torque than your standard motor. You can change motor direction to left or right by
just reversing wires. You can also use the following recommended products with this motor.
This MY6812 150W 24V 2750RPM DC Motor for E-bike Bicycle is popular as a scooter motor
or general application motor. Extremely durable and reliable.
Commonly found in 24V scooters or even small kiddies carts and It’s also been a proven motor in
robotics! 100% Ball Bearing construction!
The belt drive is fitted to an 8mm d-cut shaft with a circlip. If you wish to remove it, you can
simply remove the circlip and slide it off. Some companies glue these in place, but its not required
as the fit is firm.
Operating Voltage (VDC) 24
No-Load Current (mA) 1000
Loaded RPM 2600-3000
Sprocket 9 tooth, #25 bicycle chain
Efficiency 70%
Shipment Weight 1.45 kg
P55NF06 - 55NF06 (STP55NF06) MOSFET - 60V 50A N-Channel Power
MOSFET
P55NF06 power MOSFETs have been developed using STMicroelectronics’ unique STripFET
process, which is specifically designed to minimize input capacitance and gate charge. This
renders the devices suitable for use as primary switch in advanced high-efficiency isolated
DCDC converters for telecom and computer applications, and applications with low gate
charge driving requirements.
Features:-
• 100% avalanche tested
• Application oriented characterization
• Switching application
Detailed Specifications:-
By controlling the motor, we mean controlling its speed and direction of rotation. We can
control the motor using the Arduino and the L298N driver. Before we learn how to control a
DC motor with the Arduino, we need to understand some basic concepts of motor control.
The speed of the DC motor can be easily controlled by adjusting the input voltage supplied
to the motor. We can control the input voltage with a PWM signal.
Arduino has a PWM output pin, and we can just connect this PWM output to a transistor base (or
to the gate of a MOSFET). One end of the power supply will be connected to the motor terminal,
and the other motor terminal will be connected to the collector. The emitter of the transistor will
be connected to ground. We can control the motor speed by controlling the PWM signal of the
Arduino. The MOSFET acts like a switch that turns on and off with a PWM signal from Arduino.
Arduino cannot control the motor directly, because the signal has low power, in addition, Arduino
will burn out due to excessive current consumption of the motor. Thus, we will use this low power
signal only to turn the transistor / field effect transistor on and off. In this way, we can control the
speed of the DC motor using the Arduino.
System Block Diagram / Methodology:
Circuit Diagram
Circuit -1
Circuit -2
Circuit -3
Program
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
int brake=2;
int key=3;
int value = 0;
int p=5;
int rpm;
int acceleration;
float voltage;
float R1 = 47000.0;
float R2 = 33000.0;
void setup() {
Serial.begin (9600);
pinMode(brake,INPUT);
pinMode(key,INPUT);
pinMode(p,OUTPUT);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C
(128x64)
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("!!WELCOME!!");
display.setTextSize(1);
display.setTextColor(WHITE);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("Control of E-Bike");
display.display();
delay(3000);
void loop()
acceleration = analogRead(A0);
value = analogRead(A1);
/*
Serial.print("Key=");
Serial.print(keys);
Serial.print(" ");
Serial.print("Brake=");
Serial.print(brakes);
Serial.print(" ");
Serial.print("Acceleration:");
Serial.print(acceleration);
Serial.print(" ");
Serial.print("RPM:");
Serial.print(rpm);
Serial.print(" ");
Serial.print("Voltage =");
Serial.println(voltage);
*/
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("SPEED - ");
display.setTextSize(1);
display.setTextColor(WHITE);
display.println(rpm);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("RPM");
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("BATTERY- ");
display.setCursor(55,20); //oled display
display.setTextSize(1);
display.setTextColor(WHITE);
display.println(voltage);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("V");
display.display();
forward();
//delay(200);
else if (brakes==HIGH)
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("BRAKE IS APPLIED");
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("BATTERY- ");
display.setTextSize(1);
display.setTextColor(WHITE);
display.println(voltage);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("V");
display.display();
//stop1();
else
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("ON / OFF");
display.setTextSize(1);
display.setTextColor(WHITE);
display.display();
//stop1();
void forward()
analogWrite(p,rpm);
void stop1()
analogWrite(p,rpm);