CHAPTER 3
METHODOLOGY
3.0 Introduction
This chapter describes the design of a digital vehicle speed governor electronic vehicle speed governor system using the RF and RF modules as speed sensor. It also covers the design specification and implementation of the speed governor unit using Arduino Uno microcontroller both at the transmitter and receiver sections and circuit simulations on Proteus software. The Arduino Uno IDE software was used for programming the microcontrollers. This software uses C programming language.
The design of the digital vehicle speed governor prototype follows as closely as possible standard designs of existing electronic vehicle speed governors. The design is made of the transmitter and the receiver units. Fig.3.1 below is the flow chat diagram of the design functionality.
44
Fig.3.1: Design functionality flow chat diagram
45
3.1 Brief Overview of the Design
According to this design of the RF speed governor, two separate units have been made namely:
• Transmitter and
• Receiver
According to the design, the RF transmitter and receiver modules are connected to two separate Arduino Uno microcontrollers for data transfer (433 MHz). The idea of the design receiver end generated speed to be limited, by sending a signal with the desired speed from the transmitter to influence the receiver speed. The potentiometer at the transmitter, generates some analog signals between 0V and 5 V, which will then be varied to obtain various readings. The signals will then be converted to digital signals by the built-in ADC (Analog to Digital Converter) of the microcontroller. Each signal generated at the transmitter, will be mapped to a certain desired speed.
The receiver unit also has its own potentiometer for generating its own speed as well, which this design seeks to control. The digital data generated through the potentiometer variations (at the transmitter), is transmitted through an RF transmitter antenna connected on digital pin D2 of the microcontroller to the receiver. The receiver antenna connected on analog pin A2 of the microcontroller, receives these digital pulses carrying the desired speed limit from the transmitter unit. Once the digital data is received by the receiver module, it is pulse width modulated by the microcontroller to get an equivalent of the analog form since the Arduino Uno microcontroller does not have a digital to analog conversion (DAC) mechanism. By making variations of the duty cycle of the PMW pulses of the received signal at the receiver end, the speed of the DC motor will also be varied accordingly.
3.2 Arduino Integrated Development Environment (IDE)
For the purposes of programming in this design, the open source Arduino IDE software was used to write and upload both the transmitter and receiver programs to the Arduino microcontroller boards. It can be used with Windows, macOS, Linux that is written in functions from C and C++.
The source code for the IDE is released under the GNU General Public License, version 2. The Arduino IDE supports the languages C and C++ using special rules of code structuring. The image of the Arduino software is as show in Fig.3.2 below.
46
Fig.3.2: Arduino IDE Software
The void keyword is used only in function declarations. It indicates that the function is expected to return no information to the function from which it was called.
This one is the setup function which is a preparatory stage.
void setup(){
}
And this one is the loop function which is the execution stage.
void loop(){
}
47
3.3 The Transmitter Unit
Fig 3.3: The Transmitter Unit Snap Shot
This unit comprises of three basic hardware elements namely the:
• Potentiometer
• Arduino Uno Microcontroller
• RF Transmitter (433 MHz)
The software used is the Arduino Uno IDE software for programming the microcontroller. This software uses C programming as its language.
48 Transmitter Block Diagram
Fig.3.4: The Transmitter Design Block Diagram for RF Vehicle Speed Governor
49 Transmitter Circuit Diagram
Fig.3.5: The transmitter circuit diagram
50 Potentiometer
Fig.3.6: The Potentiometer
This varies the voltage by providing variable resistance in this design, which the Arduino board can read as an analog value. In this design, that value controls the vehicle speed.
The potentiometer comprises of three wires. One of the wires goes to ground (GND 0V), 𝐴4 𝑝𝑖𝑛.
The second wire (𝑉𝑐𝑐 5 𝑣𝑜𝑙𝑡𝑠) goes from 5 volts to, 𝐴0 𝑝𝑖𝑛. The third goes from analog input 2 (𝐴2) to the middle pin of the potentiometer and it gives the variable resistance.
In this design pins 𝐴0− 𝐴5 on the microcontroller were devoted for the potentiometer with the following values:
Pin Number Purpose
𝐴0 𝑉𝑐𝑐 – 5 volts
𝐴2 Potentiometer signal 𝐴4 Ground- 0 volts
Table: 3.1: Potentiometer pin values and their purpose.
Pins 𝐴1, 𝐴3 and𝐴5, were left as redundant pins.
Turning the potentiometer shaft, causes the resistance to vary. This shaft connected to the center pin of the potentiometer, can be turned on either side of the wiper. So different analog input signals are obtained by varying this shaft between 0 V and 5 V. We are able to read 0 whenever the shaft is turned all the way to the 0V and when turned all the way to the 5 V (meaning 5 V going into the
51
pin), we read 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.
The Arduino is able to give input and output analog signals and digital signals also.
An analog signal takes any value whereas digital signals take only 2 values 1 (HIGH) and 0 (LOW). To measure the value of analog signals, the Arduino has a built-in analog-to-digital converter (ADC). The ADC turns the analog voltage into a digital value. The function that is used to map the input voltages into the integer values is the analogRead(pin) where pin is the pin where the potentiometer wiper is connected. In this case the wiper is connected on Analog pin 2 i.e. A2.
This function converts the value of the voltage on an analog input pin and returns a digital value from 0 to 1023, relative to the reference value. The default reference voltage is 5 V (for 5 V Arduino boards) according to this design. It has one parameter which is the pin number.
The 433 MHz Transmitter Module
Fig. 3.7: The Transmitter Module [34]
[34], It is made up of a Saw Resonator, switching transistor, antenna and some other inactive components. Inside the 433 MHz Transmitter module, there is a SAW resonator which is set at 433 MHz, and is the one that takes the center stage in the operation of the module. This 433 MHz transmitter module however has 3 pins which are the data, Vcc and the ground pins. Any digital data that needs to be transmitted, is done through the data pin. Whenever the data pin receives a logic 1, then the oscillator will become active or ON thereby producing a constant RF output carrier wave at 433 MHz. Conversely, when the data pin receives a logic 0, then the oscillator goes OFF which is the concept of Amplitude shift keying as already highlighted in Chapter 2. The Vcc pin
52
is the one that then powers the module and its power ranges between 3.5 V and 12 V. The range to be covered by the module as it transmits, is determined by amount power supplied meaning that the higher the power, the longer the range and vice versa.
In this design however, the data module was connected to the digital pin 2 of the Arduino Uno and Vcc across was 5V.
Transmitter Code
The transmitter code is to generate the desired speed which can be sent to influence the receiver speed. At the transmitter, obtain the desired speed limit values from the corresponding potentiometer voltage signal values and send via the RF transmitter to the receiver. At the receiver, receive the speed value sent by the transmitter and display on the LCD.
The library called the RH_ASK, (Radio Head Amplitude Shift Keying) was used to send and received message between the RF transmitter and receiver modules. The SPI (Serial Peripheral Interface) library was also used for the communication between two microcontrollers, although it is not used in the code but was needed to compile it.
After this, we defined two variables pwr and grd that we assign to pins 𝐴0 (for power) and 𝐴4 (for ground) respectively. These are the Arduino Uno microcontroller pins onto which the potentiometer is connected.
The next step was to create the RH_ASK object that was named “driver”. The Rx was set on pin 4 which is the pin number onto which the receiver module was connected at the receiver microcontroller, Tx is set on pin 2 at the transmitter and Ptt is set on pin 5. However, the kind of RF modules used do not have the Ptt function, so this function could be ignored. 2000 bps is the baud rate or the speed.
53
Finally, the float det, defines a non-integer variable for varying the speed limit using the potentiometer. It is the variable for storing the desired vehicle speed of that particular zone.
Next, we move to the void setup () function where the pwr and gnd pins were set to OUTPUT mode and applied the output voltages to HIGH and LOW respectively. For serial communication (debugging) between the microcontroller and the serial monitor, the Serial.begin () function was set with a baud rate of 9600.
Finally, still in this mode, if the RF modules fail to initialize, then “init failed” message should be executed as show by the code below:
Next, in the void loop () mode, the code that handles the reception of requests and the transmission of the data was defined.
In the loop () function, variables *msg were declared and initiated by assigning message values and sent the ultimate messages. The message is saved on the *msg variable and the message needs to be of type char.
We then declare the RF Transmitter on digital pin 2 (𝐷2) to read the float analog values from the potentiometer as output digital values (0-1023) and store them in the det variable shown by det = analogRead(2), i.e. the function analogRead (2) returns an integer value between 0 and 1023.
Depending on the varied voltage by the potentiometer, the minimum 0 V represent 0 and the maximum 5 V represent 1023 value.
54
Up next in the void loop () function, all left to do, was to then send the message. This was done by using the send method of the driver object to a message in the uint8_t format. The uint8_t format is the same as a byte, and means unsigned integer of length 8 bits. The waitPacketSent method was used to make sure that the data was fully sent before executing the rest of the code.
A 200ms delay time was implemented to create an interval between the data and ensure one was sent before the other i.e. to wait 200 ms before repeating. Print the speed limit value to a serial monitor using the serial.println () functions
55 The Complete Transmitter Code
56
57
The potentiometer in this design is the unit used to generate the desired speed at the transmitter.
58
3.4 The Receiver Unit
This unit comprises of the following hardware elements:
• Arduino Uno Microcontroller
• RF Receiver unit
• DC motor drive unit
• LCD Screen
• 2 x Potentiometers
This section involves signal demodulation and decoding.
Fig.3.8: The Receiver Unit Snap Shot
59 Receiver Block Diagram
Fig.3.9: The Receiver Design Block Diagram for RF Vehicle Speed Governor
60 Fig.3.10 below is the detailed circuit diagram of the receiver unit.
61 Receiver Printed Circuit Board (PBC) View
Fig.3.11, 3.12, 3.13 and 3.14, show the receiver printed circuit board in different views.
Fig.3.11 Receiver PCB Design
62 Track Layout
Fig.3.12: PCB Track Layout
63 3D View
Fig.3.13: PCB 3D View
64 3D Bottom Copper
Fig.3.14: PCB 3D Bottom Copper
65 Pulse Width Modulation in DC Motors
Now, because the Arduino microcontroller does not have a built-in digital-to-analog converter (DAC), it can pulse-width modulate (PWM) a digital signal from the transmitter, to achieve some form of the output equivalent to an analog output as shown in Fig.3.15 below. Pulse Width Modulation or PWM is a technique for supplying electrical power to a load (DC motor) that has a relatively slow response. It is also a technique where average value of the input voltage is adjusted by sending a series of ON-OFF pulses. The speed of a DC motor can then be controlled by varying its input voltage through PWM (Pulse Width Modulation) i.e. the speed controller PWM for a DC motor works by varying the average voltage supplied to that motor. The average voltage is proportional to the width of the pulses known as Duty Cycle. The DC motor speed in general is directly proportional to the supply voltage and the speed controller PWM for a DC motor works by varying the average voltage supplied to the motor. The higher the duty cycle, the greater the average voltage being applied to the dc motor(High Speed) and the lower the duty cycle, the less the average voltage being applied to the dc motor(Low Speed).The supply signal consists of a train of voltages pulses such that the width of individual pulses controls the effective voltage level to the DC motor at the receiver in this design. The DC motor resembles the vehicle engine in this design. The PWM pulse train acts like a DC signal when the receiver has an electromechanical response time that is slower than the frequency of the pulses. For this DC motor, the energy storage in the motor windings effectively smooths out the energy bursts delivered by the input pulses so that the motor experiences a lesser or greater electrical power input depending on the widths of the pulses. For a DC motor at the receiver, using PWM causes the motor turning speed to be increased or reduced at a frequency that our eyes can detect. The speed variations of the motor are perceived, depending on the widths of the pulses in the PWM output.
66 t0
tc Vs
Fig.3.15: PWM Duty Cycle
Fig.3.15 above shows a voltage signal comprised of pulses of duration 𝑡0 that repeat every 𝑡𝑐 units of time. The output of a PWM channel is either 𝑉𝑠 volts during the pulse or zero volts otherwise.
If this signal is supplied as input to a device that has a response time much larger than 𝑡𝑐 , the device will experience the signal as an approximately DC input with an effective voltage of:
𝑉𝑒𝑓𝑓 = 𝑉𝑠 𝑡0
𝑡𝑐 3.1 The ratio 𝑡0
𝑡𝑐 is called the duty cycle of the square wave pulses. The effective DC voltage supplied to the load is controlled by adjusting the duty cycle.
The Arduino Uno microcontroller used in this design has 14 digital input/output (I/O) pins.
Conventional, i.e., not PWM, operation of the digital I/O pins is controlled with the pinMode, digitalRead and digitalWrite functions. The pinMode function was used to configure a pin as an input or output. When a digital I/O pin is configured as an input, digitalRead reads the state of the pin, which will be either HIGH or LOW.
On the used Arduino Uno microcontroller for this design, PWM output is possible on digital I/O pins 3, 5, 6, 9, 10 and 11. On these pins the analogWrite function was used to set the duty cycle of a PWM pulse train that operates at approximately 500 Hz. Thus, with a frequency 𝑓𝑐 = 500 Hz, and the period can be calculated as:
𝑡𝑐 = 1
𝑓𝑐 ≈ 2𝑚𝑠.
67
The digital output voltage of an Arduino Uno is either 0V or 5 V. Thus, in Equation (3.1), Vs = 5 V.
The PWM output level specified with the analogWrite is an 8-bit value that corresponds to an effective voltage range of 0 to 5 V. Thus,
𝑃𝑊𝑀𝑜𝑢𝑡𝑙𝑒𝑣𝑒𝑙 = 255 ×𝑡0
𝑡𝑐 = 255 ×𝑉𝑒𝑓𝑓
𝑉𝑠 3.2
where, 𝑉𝑠 = 5𝑉
𝑉𝑒𝑓𝑓 𝑟𝑎𝑛𝑔𝑒𝑠 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 0 𝑡𝑜 5 𝑉
Fig.3.16: Scaling relationship for PMW parameters
PWM out level is the 8-bit value used as the second parameter to the analogWrite function as shown in Fig.3.17 below:
In reality, the voltage is being applied and then removed many times in an interval, but the experience is like an analog-like response.
There is an abrupt stop in power if the motor is driven by PWM. The length of time that a pulse is in a given state (high/low) is the “width” of a pulse wave.
Therefore, to supply an effective voltage of say 3V use from the transmitter, then:
68 PWM_out_level = 3 ×255
5 = 153 , which is around 60% duty cycle.
The function used to output a PWM signal is analogWrite(pin, value) where pin is the pin number used for the PWM output and value is a number proportional to the duty cycle of the signal. To get varying analog values, the pulse width was changed or modulated. PMW frequency on Arduino is 500 Hz. So a call to AnalogWrite () is a scale of 0 to 255, such that AnalogWrite(255) requests a 100% duty cycle (always ON). When value = 0, the signal is always off. When value = 255, the signal is always on. In this design, the PWM function is available on pins 9 and 10 at the DC motor.
To map an analog input value, with digital value range 0-1023 to a PWM output signal, which ranges from 0 - 255, the map(value, fromLow, fromHigh, toLow, toHigh) function is used. This function has five parameters, one is the variable in which the analog value is stored, while the others are 0, 1023, 0 and 255 respectively.
L293D Dual H-bridge and Arduino Uno Microcontroller
As discussed in Chapter 2, the L293D DC motor driver was used for this design. In order to have a complete control over DC motor which represents the real motor vehicle engine in this prototype, its speed and rotation direction must be controlled. According to this design, this was achieved by combining these two techniques:
• PWM – For controlling speed.
The speed of a DC motor was be controlled by varying its input voltage using the potentiometer where average value of the input voltage was adjusted by sending a series of ON-OFF pulses. The average voltage is proportional to the width of the pulses known as Duty Cycle as explained above.
The higher the duty cycle, the greater the average voltage being applied to the dc motor (High Speed) and the lower the duty cycle, the less the average voltage being applied to the dc motor (Low Speed).
69
• H-Bridge – For controlling rotation direction
In this design an L293D dual H-bridge motor driver was used as a small Current Amplifier whose function in the circuit was to take a low-current control signal and then turn it into a higher-current signal that can drive a motor, because motors relatively require higher voltages and current. The current cannot be supplied to the motors directly by the microcontroller.
The motor in this model, represents a real vehicle engine whose speed can be varied by the potentiometer at the receiver side, according to the receiver block diagram shown in Fig.3.9 above.
Fig.3.17: shows the L293D dual H-bridge IC used in the design
The L293D is a 16 pin IC, with eight pins, on each side, dedicated to the controlling of a motor.
There are 2 INPUT pins, 2 OUTPUT pins and 1 ENABLE pin for each dc motor. L293D consist of two H-bridge, as shown in Fig.3.17 above. In this design, two DC motors were used.
L293D IC Pin Out Used
The driver is capable of connecting 2 dc motors, but in this design only one motor was used for the sake of presentation and as such only the left-hand side of the dc motor driver was used.
Pin 1: The Enable1,2 pin on the left part of the IC and was connected to digital pin 8 of the microcontroller which was set on HIGH i.e. on voltage of 5V;
Pin 2: Input 1, when this pin is HIGH the current will flow though output 1 and was connected to the digital pin 9 (defined as pmw1) of the microcontroller;
Pin 3: Output 1, this pin was connected to one terminal of the motor;