Bird
0
0
Arduinoprogramming~10 mins

DC motor with transistor driver in Arduino - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - DC motor with transistor driver
Start
Set pinMode for transistor control pin
Loop start
Write HIGH to transistor pin -> Motor ON
Delay for motor run time
Write LOW to transistor pin -> Motor OFF
Delay for motor stop time
Back to Loop start
The program sets a pin to control the transistor, then repeatedly turns the motor on and off with delays.
Execution Sample
Arduino
int motorPin = 9;

void setup() {
  pinMode(motorPin, OUTPUT);
}

void loop() {
  digitalWrite(motorPin, HIGH); // Motor ON
  delay(1000);                  // Run 1 sec
  digitalWrite(motorPin, LOW);  // Motor OFF
  delay(1000);                  // Stop 1 sec
}
This code turns a DC motor on for 1 second, then off for 1 second, repeatedly using a transistor driver.
Execution Table
StepActionPin StateMotor StateDelay(ms)
1Setup: pinMode(motorPin, OUTPUT)LOW (default)OFF0
2Loop start: digitalWrite(motorPin, HIGH)HIGHON0
3Delay(1000)HIGHON1000
4digitalWrite(motorPin, LOW)LOWOFF0
5Delay(1000)LOWOFF1000
6Loop repeats from step 2LOWOFF0
💡 Loop runs forever; motor toggles ON and OFF every 1 second.
Variable Tracker
VariableStartAfter Step 2After Step 4After Step 6 (Loop)
motorPin9999
Pin StateLOWHIGHLOWHIGH (next loop)
Motor StateOFFONOFFON (next loop)
Key Moments - 3 Insights
Why do we set pinMode to OUTPUT in setup()?
Because in execution_table step 1, setting pinMode to OUTPUT allows the Arduino to control the transistor pin voltage to turn the motor ON or OFF.
What happens if we skip digitalWrite(motorPin, LOW)?
As shown in execution_table step 4, without setting LOW, the motor would stay ON continuously, not turning OFF between cycles.
Why do we use delay(1000) after turning motor ON and OFF?
Delays in steps 3 and 5 keep the motor running or stopped for 1 second each, making the ON/OFF visible and controlled.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the motor state at step 3?
AOFF
BON
CStarting
DUndefined
💡 Hint
Check the 'Motor State' column at step 3 in the execution_table.
At which step does the transistor pin go LOW to turn the motor OFF?
AStep 4
BStep 2
CStep 3
DStep 5
💡 Hint
Look for 'digitalWrite(motorPin, LOW)' in the Action column of execution_table.
If delay(1000) after turning motor ON is changed to delay(2000), what changes in the execution_table?
AMotor State changes to OFF at step 3
BPin State changes to LOW at step 3
CDelay at step 3 changes to 2000 ms
DNo change in delay values
💡 Hint
Check the Delay(ms) column at step 3 and imagine increasing the delay time.
Concept Snapshot
Arduino controls a DC motor via a transistor by setting a digital pin HIGH or LOW.
Use pinMode(pin, OUTPUT) in setup to prepare the pin.
Turn motor ON with digitalWrite(pin, HIGH), OFF with digitalWrite(pin, LOW).
Use delay(ms) to keep motor ON or OFF for visible time.
Loop repeats to toggle motor continuously.
Full Transcript
This example shows how an Arduino controls a DC motor using a transistor driver. First, the motor control pin is set as an OUTPUT in setup. Then, in the loop, the pin is set HIGH to turn the motor ON, followed by a delay of 1 second to keep it running. Next, the pin is set LOW to turn the motor OFF, followed by another 1 second delay. This cycle repeats forever, making the motor turn ON and OFF every second. The execution table tracks each step, showing pin states and motor states. Key points include setting pinMode to OUTPUT, using digitalWrite to control the transistor, and using delay to control timing.