Introduction: Controlling a Motor an NPN Transistor on the Arduino 101

This is the tenth module in the series of lessons about applications of the Arduino 101, and will focus on the use of DC motors. DC motors are very common in the realm of mobile robotics. Most robots that require some sort of motion, usually for actuating wheels use DC motors since they are relatively cheap and easy to code. This project focus on making the simplest circuit to control a DC motor without a motor driver shield or H-bridge IC, but simply with an NPN transistor

Step 1: Tools and Materials

  • Arduino 101 or Arduino Uno
  • Breadboard
  • NPN Transistor
  • 100Ω Resistor
  • DC motor
  • 1N4148 Diode
  • Jumper Wires

Step 2: Circuitry

Connecting the Arduinopower to the breadboard

  • Connect the 3.3V pin from the Arduino to the red power rail of the breadboard using a red jumper wire.
  • Connect the ground pin from the Arduino to the black power rail of the breadboard using a black jumper wire.
  • Connect the 5V pin from the Arduino to an unconnected hole in the breadboard with an orange jumper wire. This will be used to power the DC motor.

Wiring the transistor

  • Connect the middle pin to a 100Ω resistor and insures to pin 9 on the Arduino.
  • Connect one of the other pins to the ground rail on the breadboard with a black jumper wire.
  • The remaining pin of the transistor will be connected to the motor ground with a brown jumper wire.

Wiring the the motor.

  • Connect one of the motor wires to the 5V pin you connected with the orange jumper wire previously. Note that when connecting the motors, the order of the wire connection does not matter, it simple means that the motor will turn the opposite direction.
  • Connect the other motor wire to the outer leg of the transistor not connected to the ground power rail using a brown jumper wire.
  • Connect the diode between the two motor wires with the negative pin marked by a black line on the diode connected to the 5V pin with the orange wire.

Step 3: Code

// constant pin for the transistor connected to the motor
const int motorPin = 9;

void setup() { //set motorPin as OUTPUT pinMode(motorPin, OUTPUT); }

void loop() { // milliseconds to turn the motor on int onTime = 3000; // milliseconds to turn the motor off int offTime = 3000;

// turn the motor on (full speed) digitalWrite(motorPin, HIGH); // delay for onTime milliseconds delay(onTime); // turn the motor off digitalWrite(motorPin, LOW); // delay for offTime milliseconds delay(offTime); }

Step 4: Demo

The DC motor will spin in one direction and stop for 3 seconds, then spin again in full speed. You can also change the speed by using analogWrite (motorPin, motorSpeed);

Makerspace Contest 2017

Participated in the
Makerspace Contest 2017