Table of Contents

How to Control a Motor Using Arduino

Arduino Motor Controller
Example Description
Learn how to control the direction of a DC motor using Arduino Uno and PictoBlox. In this beginner-friendly Grade 7 STEM project, you will program the motor to rotate forward for 5 seconds and reverse for 5 seconds while learning motor driver interfacing, robotics, and Arduino programming.

Introduction

DC motors are essential components in robots, automated machines, and smart devices. Since Arduino cannot directly power a motor, we use an L298N Motor Driver to control the motor safely. In this project, Arduino sends commands to the motor driver through PictoBlox, causing the motor to rotate forward and reverse repeatedly.

This project helps students understand:

  1. Motor Driver Interfacing
  2. Forward and Reverse Motor Control
  3. Loops and Timing
  4. Robotics Fundamentals
  5. Arduino Hardware Programming

Setting Up the Stage / Sprite

Before creating the program, we need to add the Arduino extension and connect the motor driver circuit.

Adding the Arduino Extension

  1. Open PictoBlox.

  2. Select Arduino Uno.
    Arduino Connect
  3. Connect the Arduino board using a USB cable.
  4. Select the correct COM Port.
    Serial port Connection for Quarky Intellio
  5. Switch to Upload Mode.
    Switch to Upload Mode

Circuit Connections

Components Required

  1. Arduino Uno
  2. L298N Motor Driver
  3. DC Motor
  4. Jumper Wires
  5. External Battery (6V–12V)
  6. USB Cable

Arduino to L298N Connections

Arduino D4 → L298N IN1

Arduino D5 → L298N IN2

Arduino D3 (PWM) → L298N ENA

Arduino GND → L298N GND

DC Motor Connections

Motor Terminal 1 → L298N OUT1

Motor Terminal 2 → L298N OUT2

Power Connections

Battery Positive (+) → L298N 12V

Battery Negative (-) → L298N GND

Arduino GND → L298N GND

Important Note

All GND connections must be common.

Arduino GND → L298N GND → Battery Negative (-)

This common ground ensures proper communication between Arduino and the motor driver.

Connections :

arduino connect with motor

Step-by-Step Block Coding Guide

Let’s create the script that makes the motor rotate forward and reverse continuously.

Step 1: Start the Program

Go to the Arduino Uno Extension and drag the when Arduino Uno starts up block into the scripting area.

This block starts the program automatically when the Arduino powers on.

Step 2: Configure the Motor Driver

From the Actuators section, drag the connected motor block.

Set:

  1. Motor = 1
  2. Direction 1 = 4
  3. Direction 2 = 5
  4. PWM = 3

This tells Arduino which pins are connected to the motor driver.

Block Used:

arduino pins connect with motor driver

Step 3: Create the Forever Loop

From the Control palette, drag a forever block.
forever block add

The motor control commands will be placed inside this loop so that they run continuously.

Step 4: Rotate the Motor Forward

Inside the forever block:

  1. Drag the run motor block.
  2. Select:
    1. Motor 1
    2. Forward
    3. Speed 100%
  3. Add a wait of 5 seconds.

This rotates the motor forward at full speed for 5 seconds.

Block Used:

rotate motor forward at full speed for 5 seconds

Step 5: Rotate the Motor in Reverse

Below the first wait block:

  1. Add another run motor block.
  2. Select:
    1. Motor 1
    2. Reverse
    3. Speed 100%
  3. Add a wait of 5 seconds.

This changes the motor direction and rotates it in reverse for 5 seconds.

Block Used:

rotate motor reverse at full speed for 5 seconds

Complete Program Flow.

Output

After uploading the code:

  1. The motor starts rotating in the forward direction.
  2. It continues rotating for 5 seconds.
  3. The motor changes direction automatically.
  4. It rotates in reverse for 5 seconds.
  5. The process repeats continuously.

Expected Output Sequence

Forward Rotation

Wait 5 Seconds

Reverse Rotation

Wait 5 Seconds

Repeat Forever

Conclusion

This project demonstrates how Arduino and the L298N motor driver can be used to control the direction of a DC motor. Students learn about motor interfacing, direction control, and automation using PictoBlox. The project provides a strong foundation for robotics and intelligent machine design. It also introduces concepts that are widely used in real-world automation and robotic systems.