Figure 4-17. A physical-computing DC motor speed controller built on a solderless breadboard
The motor speed control, as discussed earlier, takes place through the 10KΩ potentiometer. Adjusting it will allow the Arduino’s ATmega328 microcontroller to provide a smooth string of pulses that will bias the 2N2222 transistor to efficiently drive the small DC motor. To see the PWM signal, you must connect an oscilloscope at the base of the transistor driver and attach the other test lead to ground. Figure 4-18 illustrates how an oscilloscope is connected to the 2N2222 NPN transistor’s base lead. The actual measurement setup is shown in Figure 4-19. The duty cycle (discussed in Chapter 1) for the adjusted motor speed was measured at 38.81 percent. When the potentiometer’s shaft is rotated, the duty cycle value changes proportional to the amount of resistance. As the potentiometer’s resistance increases, the duty cycle value becomes larger. At full resistance (10KΩ), the duty cycle value is at 100 percent with the small DC motor running at full-rated speed.
Figure 4-18. Circuit schematic diagram of the Arduino controlled DC motor with an oscilloscopes to observe the PWM signals
Figure 4-19. Circuit schematic diagram showing how to attach an oscilloscope to observe the PWM signals generated by the Arduino
Figure 4-20 shows a close-up of the Arduino-produced PWM control signal in which you can see a series of clean, square-wave pulses.
Figure 4-20. The Arduino-produced PWM control signal for motor speed control
The 2N2222 Transistor Pinout
An important item to note is that all NPN transistors are not created equal. The 2N3904 NPN transistor’s pinout (from the “Assembly of the Electronic Singing Bird Circuit on a Breadboard” section of Chapter 1) consists of the emitter being located to the left of the three-pin device. The base is the center lead, and the collector is located to the immediate right. For the 2N2222 transistor, the emitter is on the right side and collector is on the left side. Figure 4-21 shows the pinout for the 2N2222 transistor that will ensure proper operating function of this speed control circuit, as well as the simple motor control project.
Figure 4-21. Pinout diagram for the 2N2222 NPN transistor (courtesy of ON Semiconductor datasheet)
The Motor Speed Control Software
With the electronics hardware in place, the sketch is needed to complete the project build. The sketch allows the Arduino to read the potentiometer’s analog position and generates a PWM signal that is proportional to the angular location of the wiper arm. The sketch is well commented, so changes to the analog or digital port pins can easily be made. Listing 4-1 shows the motor speed control sketch.
Listing 4-1. The Motor Speed Control Sketch
int motorPin = 9; // motor connected to digital pin 9
int analogPin = 0; // potentiometer connected to analog pin 0
int val = 0; // variable to store the read value
void setup()
{
pinMode(motorPin, OUTPUT); // sets the pin as output
}
void loop()
{
val = analogRead(analogPin); // read the input pin
analogWrite(motorPin, val / 4); // analogRead values go from 0 to
1023, analogWrite values from 0 to 255
}
Here’s a final note regarding the operation of the physical computing–based controller: after uploading the motor speed control sketch to the Arduino, depending on the position of the 10KΩ potentiometer, the electromechanical device may start at low, medium, or high speed.
- 上一篇:拉丝机英文文献和中文翻译
- 下一篇:冲压模具英文参考文献和中文翻译
-
-
-
-
-
-
-
浅析中国古代宗法制度
现代简约美式风格在室内家装中的运用
高警觉工作人群的元情绪...
江苏省某高中学生体质现状的调查研究
g-C3N4光催化剂的制备和光催化性能研究
巴金《激流三部曲》高觉新的悲剧命运
C++最短路径算法研究和程序设计
中国传统元素在游戏角色...
NFC协议物理层的软件实现+文献综述
上市公司股权结构对经营绩效的影响研究