- Arduino Electronics Blueprints
- Don Wilcher
- 2727字
- 2021-07-16 13:48:44
Let's build it!
In order to build the programmable DC motor controller, follow the following steps:
- Wire the programmable DC motor controller with the LCD circuit on a solderless breadboard, as shown in the previous image as well as the circuit's schematic diagram that is shown in the next image.
- Upload the software of the programmable motor controller to the Arduino by using the sketch shown next.
- Close both the Program and Enables switches. The motor will spin.
- When you open the Enable switch, the motor stops.
The LCD message tells you how one can set the Program switch for an ON and OFF motor control. The Program switch allows you to select between the ON and OFF motor control functions. With the Program switch closed, toggling the Enable switch will turn the motor ON and OFF. Opening the Program switch will prevent the motor from turning on. The next few sections will explain additional details on the I/O interfacing of discrete digital logic circuits and a small DC motor that can be connected to the Arduino.
Note
A sketch is a unit of code that is uploaded to and run on an Arduino board.
/* * programmable DC motor controller w/LCD allows the user to select ON and OFF operations using a slide switch. To * enable the selected operation another slide switch is used to initiate the selected choice. * Program Switch wired to pin 6. * Output select wired to pin 7. * LCD used to display programming choices (ON or OFF). * created 24 Dec 2012 * by Don Wilcher */ // include the library code: #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // constants won't change. They're used here to // set pin numbers: const int ProgramPin = 6; // pin number for PROGRAM input control signal const int OUTPin = 7; // pin number for OUTPUT control signal // variable will change: int ProgramStatus = 0; // variable for reading Program input status void setup() { // initialize the following pin as an output: pinMode(OUTPin, OUTPUT); // initialize the following pin as an input: pinMode(ProgramPin, INPUT); // set up the LCD's number of rows and columns: lcd.begin(16, 2); // set cursor for messages andprint Program select messages on the LCD. lcd.setCursor(0,0); lcd.print( "1. ON"); lcd.setCursor(0, 1); lcd.print ( "2. OFF"); } void loop(){ // read the status of the Program Switch value: ProgramStatus = digitalRead(ProgramPin); // check if Program select choice is 1.ON. if(ProgramStatus == HIGH) { digitalWrite(OUTPin, HIGH); } else{ digitalWrite(OUTPin,LOW); } }
The schematic diagram of the circuit that is used to build the programmable DC motor controller and upload the sketch to the Arduino is shown in the following image:

Interfacing a discrete digital logic circuit with Arduino
The Enable switch, along with the Arduino, is wired to a discrete digital Integrated Circuit (IC) that is used to turn on the transistor motor driver. The discrete digital IC used to turn on the transistor motor driver is a 74LS08 Quad AND gate. The AND gate provides a high output signal when both the inputs are equal to +5 V. The Arduino provides a high input signal to the 74LS08 AND gate IC based on the following line of code:
digitalWrite(OUTPin, HIGH);
The OUTPin
constant name is declared in the Arduino sketch by using the following declaration statement:
const int OUTPin = 7; // pin number for OUTPUT control signal
The Enable switch is also used to provide a +5V input signal to the 74LS08 AND gate IC. The Enable switch circuit schematic diagram is as follows:

Both the inputs must have the value of logic 1 (+5 V) to make an AND logic gate produce a binary 1 output. In the following section, the truth table of an AND logic gate is given. The table shows all the input combinations along with the resultant outputs. Also, along with the truth table, the symbol for an AND logic gate is provided. A truth table is a graphical analysis tool that is used to test digital logic gates and circuits. By setting the inputs of a digital logic gate to binary 1 (5V) or binary 0 (0 V), the truth table will show the binary output values of 1 or 0 of the logic gate. The truth table of an AND logic gate is given as follows:

Another tool that is used to demonstrate the operation of the digital logic gates is the Boolean Logic expression. The Boolean Logic expression for an AND logic gate is as follows:

A Boolean Logic expression is an algebraic equation that defines the operation of a logic gate. As shown for the AND gate, the Boolean Logic expression circuit's output, which is denoted by C, is only equal to the product of A and B inputs. Another way of observing the operation of the AND gate, based on its Boolean Logic Expression, is by setting the value of the circuit's inputs to 1. Its output has the same binary bit value. The truth table graphically shows the results of the Boolean Logic expression of the AND gate.
A common application of the AND logic gate is the Enable circuit. The output of the Enable circuit will only be turned on when both the inputs are on. When the Enable circuit is wired correctly on the solderless breadboard and is working properly, the transistor driver circuit will turn on the DC motor that is wired to it. The operation of the programmable DC motor controller's Enable circuit is shown in the following truth table:

The basic computer circuit that makes the decision to operate the DC motor is the AND logic gate. The previous schematic diagram of the Enable Switch circuit shows the electrical wiring to the specific pins of the 74LS08 IC, but internally, the AND logic gate is the main circuit component for the programmable DC motor controller's Enable function. Following is the diagram of 74LS08 AND Logic Gate IC:

To test the Enable circuit function of the programmable DC motor controller, the Program switch is required. The schematic diagram of the circuit that is required to wire the Program Switch to the Arduino is shown in the following diagram. The Program and Enable switch circuits are identical to each other because two 5 V input signals are required for the AND logic gate to work properly. The Arduino sketch that was used to test the Enable function of the programmable DC motor is shown in the following diagram:

The program for the discrete digital logic circuit with an Arduino is as follows:
// constants won't change. They're used here to // set pin numbers: const int ProgramPin = 6; // pin number for PROGRAM input control signal const int OUTPin = 7; // pin number for OUTPUT control signal // variable will change: int ProgramStatus = 0; // variable for reading Program input status void setup() { // initialize the following pin as an output: pinMode(OUTPin, OUTPUT); // initialize the following pin as an input: pinMode(ProgramPin, INPUT); } void loop(){ // read the status of the Program Switch value: ProgramStatus = digitalRead(ProgramPin); // check if Program switch is ON. if(ProgramStatus == HIGH) { digitalWrite(OUTPin, HIGH); } else{ digitalWrite(OUTPin,LOW); } }
Connect a DC voltmeter's positive test lead to the D7 pin of the Arduino. Upload the preceding sketch to the Arduino and close the Program and Enable switches. The DC voltmeter should approximately read +5 V. Opening the Enable switch will display 0 V on the DC voltmeter. The other input conditions of the Enable circuit can be tested by using the truth table of the AND Gate that was shown earlier. Although the DC motor is not wired directly to the Arduino, by using the circuit schematic diagram shown previously, the truth table will ensure that the programmed Enable
function is working properly.
Next, connect the DC voltmeter to the pin 3 of the 74LS08 IC and repeat the truth table test again. The pin 3 of the 74LS08 IC will only be ON when both the Program and Enable switches are closed. If the AND logic gate IC pin generates wrong data on the DC voltmeter when compared to the truth table, recheck the wiring of the circuit carefully and properly correct the mistakes in the electrical connections. When the corrections are made, repeat the truth table test for proper operation of the Enable circuit.
Interfacing a small DC motor with a digital logic gate
The 74LS08 AND Logic Gate IC provides an electrical interface between reading the Enable switch trigger and the Arduino's digital output pin, pin D7. With both the input pins (1 and 2) of the 74LS08 AND logic gate set to binary 1, the small 14-pin IC's output pin 3 will be High
. Although the logic gate IC's output pin has a +5 V source present, it will not be able to turn a small DC motor. The 74LS08 logic gate's sourcing current is not able to directly operate a small DC motor.
To solve this problem, a transistor is used to operate a small DC motor. The transistor has sufficient current gain hfe to operate the DC motor. The DC motor will be turned on when the transistor is biased properly. Biasing is a technique pertaining to the transistor circuit, where providing an input voltage that is greater than the base-emitter junction voltage (VBE) turns on the semiconductor device. A typical value for VBE is 700 mV. Once the transistor is biased properly, any electrical device that is wired between the collector and +VCC (collector supply voltage) will be turned on. An electrical current will flow from +VCC through the DC motor's windings and the collector-emitter is grounded.
The circuit that is used to operate a small DC motor is called a Transistor motor driver, and is shown in the following diagram:

The Arduino code that is responsible for the operation of the transistor motor driver circuit is as follows:
void loop(){ // read the status of the Program Switch value: ProgramStatus = digitalRead(ProgramPin); // check if Program switch is ON. if(ProgramStatus == HIGH) { digitalWrite(OUTPin, HIGH); } else{ digitalWrite(OUTPin,LOW); } }
Although the transistor motor driver circuit was not directly wired to the Arduino, the output pin of the microcontroller prototyping platform indirectly controls the electromechanical part by using the 74LS08 AND logic gate IC. A tip to keep in mind when using the transistors is to ensure that the semiconductor device can handle the current requirements of the DC motor that is wired to it. If the DC motor requires more than 500 mA of current, consider using a power Metal Oxide Semiconductor Field Effect Transistor (MOSFET) instead.
A power MOSFET device such as IRF521 (N-Channel) and 520 (N-Channel) can handle up to 1 A of current quite easily, and generates very little heat. The low heat dissipation of the power MOSFET (PMOSFET) makes it more ideal for the operation of high-current motors than a general-purpose transistor. A simple PMOSFET DC motor driver circuit can easily be built with a handful of components and tested on a solderless breadboard, as shown in the following image. The circuit schematic for the solderless breadboard diagram is shown after the breadboard image as well. Sliding the Single Pole-Double Throw (SPDT)switch in one position biases the PMOSFET and turns on the DC motor. Sliding the switch in the opposite direction turns off the PMOSFET and the DC motor.

Tip
Once this circuit has been tested on the solderless breadboard, replace the 2N3904 transistor in the programmable DC Motor controller project with the power-efficient PMOSFET component mentioned earlier.
As an additional reference, the schematic diagram of the transistor relay driver circuit is as follows:

A sketch of the LCD selection cursor
The LCD provides a simple user interface for the operation of a DC motor that is wired to the Arduino-based programmable DC motor controller. The LCD provides the two basic motor operations of ON and OFF. Although the LCD shows the two DC motor operation options, the display doesn't provide any visual indication of selection when using the Program switch. An enhancement feature of the LCD is that it shows which DC motor operation has been selected by adding a selection symbol. The LCD selection feature provides a visual indicator of the DC motor operation that was selected by the Program switch. This selection feature can be easily implemented for the programmable DC motor controller LCD by adding a > symbol to the Arduino sketch.
After uploading the original sketch from the Let's build it section of this chapter, the LCD will display two DC motor operation options, as shown in the following image:

The enhancement concept sketch of the new LCD selection feature is as follows:

The selection symbol points to the DC motor operation that is based on the Program switch position. (For reference, see the schematic diagram of the programmable DC motor controller circuit.)
The partially programmable DC motor controller program sketch that comes without an LCD selection feature
Comparing the original LCD DC motor operation selection with the new sketch, the differences with regard to the programming features are as follows:
void loop(){ // read the status of the Program Switch value: ProgramStatus = digitalRead(ProgramPin); // check if Program switch is ON. if(ProgramStatus == HIGH) { digitalWrite(OUTPin, HIGH); } else{ digitalWrite(OUTPin,LOW); } }
The partially programmable DC motor controller program sketch with an LCD selection feature
This code feature will provide a selection cursor on the LCD to choose the programmable DC motor controller operation mode:
// set cursor for messages and print Program select messages on the LCD. lcd.setCursor(0,0); lcd.print( ">1.Closed(ON)"); lcd.setCursor(0, 1); lcd.print ( ">2.Open(OFF)"); void loop(){ // read the status of the Program Switch value: ProgramStatus = digitalRead(ProgramPin); // check if Program select choice is 1.ON. if(ProgramStatus == HIGH) { digitalWrite(OUTPin, HIGH); lcd.setCursor(0,0); lcd.print( ">1.Closed(ON)"); lcd.setCursor(0,1); lcd.print ( " 2.Open(OFF) "); } else{ digitalWrite(OUTPin,LOW); lcd.setCursor(0,1); lcd.print ( ">2.Open(OFF)"); lcd.setCursor(0,0); lcd.print( " 1.Closed(ON) "); } }
The most obvious difference between the two partial Arduino sketches is that the LCD selection feature has several lines of code as compared to the original one. As the slide position of the Program switch changes, the LCD's selection symbol instantly moves to the correct operating mode. Although the DC motor can be observed directly, the LCD confirms the operating mode of the electromechanical device. The complete LCD selection sketch is shown in the following section. As a design-related challenge, try displaying an actual arrow for the DC motor operating mode on the LCD. As illustrated in the sketch, an arrow can be built by using the keyboard symbols or the American Standard Code for Information Interchange (ASCII) code.
/* * programmable DC motor controller w/LCD allows the user to select ON and OFF operations using a slide switch. To * enable the selected operation another slide switch is used to initiate the selected choice. * Program Switch wired to pin 6. * Output select wired to pin 7. * LCD used to display programming choices (ON or OFF) with selection arrow. * created 28 Dec 2012 * by Don Wilcher */ // include the library code: #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // constants won't change. They're used here to // set pin numbers: const int ProgramPin = 6; // pin number for PROGRAM input control signal const int OUTPin = 7; // pin number for OUTPUT control signal // variable will change: int ProgramStatus = 0; // variable for reading Program input status void setup() { // initialize the following pin as an output: pinMode(OUTPin, OUTPUT); // initialize the following pin as an input: pinMode(ProgramPin, INPUT); // set up the LCD's number of rows and columns: lcd.begin(16, 2); // set cursor for messages andprint Program select messages on the LCD. lcd.setCursor(0,0); lcd.print( ">1.Closed(ON)"); lcd.setCursor(0, 1); lcd.print ( ">2.Open(OFF)"); } void loop(){ // read the status of the Program Switch value: ProgramStatus = digitalRead(ProgramPin); // check if Program select choice is 1.ON. if(ProgramStatus == HIGH) { digitalWrite(OUTPin, HIGH); lcd.setCursor(0,0); lcd.print( ">1.Closed(ON)"); lcd.setCursor(0,1); lcd.print ( " 2.Open(OFF) "); } else{ digitalWrite(OUTPin,LOW); lcd.setCursor(0,1); lcd.print ( ">2.Open(OFF)"); lcd.setCursor(0,0); lcd.print( " 1.Closed(ON) "); } }
Congratulations on building your programmable motor controller device!
- JavaScript高效圖形編程
- Android Application Development Cookbook(Second Edition)
- Windows Presentation Foundation Development Cookbook
- Java程序設計與實踐教程(第2版)
- Jupyter數據科學實戰
- 小學生C++創意編程(視頻教學版)
- Spring Boot Cookbook
- PLC應用技術(三菱FX2N系列)
- Service Mesh實戰:基于Linkerd和Kubernetes的微服務實踐
- C++寶典
- Java Fundamentals
- MySQL入門很輕松(微課超值版)
- Java7程序設計入門經典
- Training Systems Using Python Statistical Modeling
- Arduino電子設計實戰指南:零基礎篇