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.
上一篇:拉丝机英文文献和中文翻译
下一篇:冲压模具英文参考文献和中文翻译

旋转式伺服电机的柔性电...

智能城市物流云计算模型英文文献和中文翻译

云计算服务英文文献和中文翻译

直流电机英文文献和中文翻译

电-气动驱动的垂直计算机...

金属板料冲压模具计算机...

计算机辅助工艺规划CAPP系...

压疮高危人群的标准化中...

基于Joomla平台的计算机学院网站设计与开发

从政策角度谈黑龙江對俄...

STC89C52单片机NRF24L01的无线病房呼叫系统设计

提高教育质量,构建大學生...

上海居民的社会参与研究

浅谈高校行政管理人员的...

AES算法GPU协处理下分组加...

浅论职工思想政治工作茬...

酵母菌发酵生产天然香料...