0% found this document useful (0 votes)
92 views

Arduino Motor DC

This document discusses interfacing DC motors with an Arduino board. There are three types of motors discussed - DC motor, servo motor, and stepper motor. It provides instructions on connecting a DC motor to an Arduino board using a transistor, diode, and resistor. The code examples show how to control the motor speed and direction of a DC motor connected in this way. Precautions are provided regarding proper transistor and diode orientation in the circuit.

Uploaded by

Isna
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

Arduino Motor DC

This document discusses interfacing DC motors with an Arduino board. There are three types of motors discussed - DC motor, servo motor, and stepper motor. It provides instructions on connecting a DC motor to an Arduino board using a transistor, diode, and resistor. The code examples show how to control the motor speed and direction of a DC motor connected in this way. Precautions are provided regarding proper transistor and diode orientation in the circuit.

Uploaded by

Isna
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

In this chapter, we will interface different types of motors with the Arduino board (UNO) and

show you how to connect the motor and drive it from your board.

There are three different type of motors −

DC motor

Servo motor

Stepper motor

A DC motor (Direct Current motor) is the most common type of motor. DC motors normally have
just two leads, one positive and one negative. If you connect these two leads directly to a battery,
the motor will rotate. If you switch the leads, the motor will rotate in the opposite direction.

Warning − Do not drive the motor directly from Arduino board pins. This may damage the board.
Use a driver Circuit or an IC.

We will divide this chapter into three parts −

Just make your motor spin

Control motor speed

Control the direction of the spin of DC motor

Components Required

You will need the following components −

1x Arduino UNO board

1x PN2222 Transistor

1x Small 6V DC Motor

1x 1N4001 diode

1x 270 Ω Resistor

Procedure

Follow the circuit diagram and make the connections as shown in the image given below.

Precautions

Take the following precautions while making the connections.


First, make sure that the transistor is connected in the right way. The flat side of the transistor
should face the Arduino board as shown in the arrangement.

Second, the striped end of the diode should be towards the +5V power line according to the
arrangement shown in the image.

Spin ControlArduino Code

int motorPin = 3;

void setup() {

void loop() {

digitalWrite(motorPin, HIGH);

Code to Note

The transistor acts like a switch, controlling the power to the motor. Arduino pin 3 is used to turn
the transistor on and off and is given the name 'motorPin' in the sketch.

Result

Motor will spin in full speed when the Arduino pin number 3 goes high.

Motor Speed Control

Following is the schematic diagram of a DC motor, connected to the Arduino board.

Arduino Code

int motorPin = 9;

void setup() {

pinMode(motorPin, OUTPUT);

Serial.begin(9600);

while (! Serial);

Serial.println("Speed 0 to 255");

}
void loop() {

if (Serial.available()) {

int speed = Serial.parseInt();

if (speed >= 0 && speed <= 255) {

analogWrite(motorPin, speed);

Code to Note

The transistor acts like a switch, controlling the power of the motor. Arduino pin 3 is used to turn
the transistor on and off and is given the name 'motorPin' in the sketch.

When the program starts, it prompts you to give the values to control the speed of the motor.
You need to enter a value between 0 and 255 in the Serial Monitor.

In the 'loop' function, the command 'Serial.parseInt' is used to read the number entered as text
in the Serial Monitor and convert it into an 'int'. You can type any number here. The 'if'
statement in the next line simply does an analog write with this number, if the number is
between 0 and 255.

Result

The DC motor will spin with different speeds according to the value (0 to 250) received via the
serial port.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy