Вы находитесь на странице: 1из 7

Computational Robotics

Engineering

Microcontrollers
Programming U2

Product 3
PWM Control
Students
Esquivar Genesta Efrain Enrique
Balam Poot Carlos José

January 31th – 2021


Index
Introduction ........................................................................................................................................ 3
List of Materials ................................................................................................................................... 5
Development ....................................................................................................................................... 5
Results ................................................................................................................................................. 6
Conclusion ........................................................................................................................................... 7
References........................................................................................................................................... 7

Table of images
Fig. 1 Pulse Modulation example........................................................................................................ 3
Fig. 2 Motor Speed Control with 2N222 example .............................................................................. 3
Fig. 3 Diode rectifier main use ............................................................................................................ 4
Fig. 4 Schematic circuit for PWM and 2n2222 ................................................................................... 5
Fig. 5 Built circuit ............................................................................................................................... 6
Introduction

This document is intended to explain the work done during practice 3 microcontroller unit 2,
which involves converting an analog data input to a pwm output to control the speed of a DC
motor. From 3300mv of data input to 0mv, we have to control said motor, with the help of
an external 9V source and a rectifier diode and a 2n2222 transistor. With a potentiometer, we
are modifying the pulse width that the ESP32 will receive as a signal, and depending on the
size of that pulse width, it will be relative to the speed at which the motor is going.

Later in the development I will explain the connection made. But briefly, I will explain a
little about the terms and components of this circuit early in development.

Pulse Width Modulation, or PWM, is a technique for


getting analog results with digital means. Digital control
is used to create a square wave, a signal switched between
on and off. This on-off pattern can simulate voltages in
between the full Vcc of the board (e.g., 5 V on Uno, 3.3
V on a MKR board) and off (0 Volts) by changing the
portion of the time the signal spends on versus the time
that the signal spends off. The duration of "on time" is
called the pulse width. To get varying analog values, you
change, or modulate, that pulse width. If you repeat this
on-off pattern fast enough with an LED for example, the
result is as if the signal is a steady voltage between 0 and
Vcc controlling the brightness of the LED [1].
Fig. 1 Pulse Modulation example
2N2222A is a NPN
transistor hence the collector and emitter will be left open
(Reverse biased) when the base pin is held at ground and will
be closed (Forward biased) when a signal is provided to base
pin. 2N2222A has a gain value of 110 to 800, this value
determines the amplification capacity of the transistor. The
maximum amount of current that could flow through the
Collector pin is 800mA, hence we cannot connect loads that
consume more than 800mA using this transistor. To bias a
transistor we have to supply current to base pin, this current
(IB) should be limited to 5mA.

This transistor like all can be used either as a switch or as an


amplifier. The Base-Emitter voltage of this transistor is 6V so
you just have to supply this voltage across the base and
emitter of the transistor to induce a base current into the
Fig. 2 Motor Speed Control with
transistor. This transistor will make it forward biased and thus 2N222 example
closes the connection between collector and emitter [2].
The key component in any
rectifier circuit is naturally the
diode or diodes used. These
devices are unique in only
allowing current through in one
direction. Interestingly
Ambrose Fleming who
invented the first form of diode
Fig. 3 Diode rectifier main use called his version a valve
because of its one-way action.
Semiconductor diodes now perform the same function but occupy a fraction of the space and
are normally only a small fraction of the cost [3].

We will show the schematic with which we elaborate the circuit, and of course, the armed
circuit. The code we use will also be explained in the development section. We will have a
results section, where although the motor cannot be seen turning well, we will explain what
we obtained in this practice. At the end, we attach a conclusion from this practice, and a
section of attachments where we place the datasheets of some components used.
List of Materials
• Protoboard of 6,4 x 17,2 cm with 830 perforation
• Computer.
• ESP32.
• 1 220 Ohm Resistances.
• 2 electrical cramps
• Du-pont wire.
• 1 Diode rectificater
• 1 2n2222 Transistor
• 1 DC motor
• 1 9V battery

Development

Below is the schematic used for the


realization of this circuit. From the
ESP32, we get a signal one square,
varied by a potentiometer. The width of
this signal is shortened or lengthened
depending on the potentiometer, this is
known as PWM.

The signal taken from ESP32, passes Fig. 4 Schematic circuit for PWM and 2n2222
through a 220 ohm resistor, which in
turn reaches the base of the 2N2222 transistor, this signal will act as the one that opens the
gate to let the current pass between the collector and emitter of the transistor. From the
collector, we have a rectifier diode that will prevent the passage of current from the battery
to the ESP32, in parallel we have the DC motor to control. Finally, we will join the
microcontroller and battery grounds.

Finally, we show how the circuit assembly was left on the board:
Fig. 5 Built circuit

The code for this practice has to define the pin for the motor and the value for the ADC.
Next, in the void setup, we define the function for the ledcSetup, where we declare the
ledChannel, frequency and resolution. Also, the ledcAttachPin function was declared.
Finally, in the void loop, a variable for the reading of the ADC and the pin of this was defined,
this corresponds to the signal from the potentiometer; as a next point, the equation for the
conversion was declared as “operation”.

Code
#define Motor 4
int ADC=0;

void setup (){


ledcSetup(0, 1000, 16);
ledcAttachPin(Motor, 0);
}

void loop(){
ADC=analogRead(36);
float operation= ADC*65535/4095 ;
ledcWrite(0,operation);
delay(1000);
}

Results
The results for this practice was shown in the video, were we can see that the speed of the
motor is increased and decreased by the potentiometer, thanks to the configuration planted
by schematic. We need to distinguish the movement of the rotor of the motor, which is tied
up with a red wire only for visualization.
Conclusion

Throughout this practice, we mainly learned the function of the ADC. After all an analog to
digital converter, as the name suggest converts any analog signal into quantifiable data, which
makes it easier to process and store, as well as more accurate and reliable by minimizing
errors, also, learning about related concepts as the resolution give the possibility to use the
resolution and accuracy to different activities in the industrial environment.

In this practice we also saw the use of the transistor as a speed regulator for a DC motor. It
is a utility that we did not know about the transistor since we had previously handled it in
other matters in its switch mode. But I find this configuration of the 2n2222 transistor
together with the diode quite useful. It allows a more compact circuit than a module that
performs the same function and gives the possibility of controlling the output pwm of the
ESP32.

References

[1] Arduino. (2018). PWM. January 31th, from Arduino Web site:
https://www.arduino.cc/en/Tutorial/Foundations/PWM

[2] Componentes 101. (2017). 2N2222A –NPN Transistor. January 31th, from Componentes
101 Web site: https://components101.com/2n2222a-pinout-equivalent-datasheet

[3] Electricnotes. (2018). Diode Rectifier Circuits. January 31th, from Electricnotes Web
site: https://www.electronics-notes.com/articles/analogue_circuits/diode-rectifiers/circuits-
basics-primer.php

Вам также может понравиться