ArduinoStudio

DC motor

Spin a small DC motor at the speed you choose, through a motor driver and the ArduinoStudio Bridge.

A DC motor spins whenever current flows through it. Use one for a fan, a spinning display or the wheels of a small robot. An Arduino pin can’t power a motor, so a driver module sits in between: the pin tells the driver how fast, and a battery pack supplies the current.

On a real board, the DC Motor block runs only through the ArduinoStudio Bridge desktop app today. USB direct doesn’t support it yet. The block turns the motor on at a Speed, or off. It always runs forward; to change direction, swap the motor wires.

Wiring

DC motor on an L298N-style driver, with speed on pin 3 and a separate battery packArduino 5V to L298N-style driver IN1; Arduino pin 3 to L298N-style driver ENA (speed); Arduino GND to L298N-style driver IN2; Arduino GND to L298N-style driver GND; L298N-style driver Motor supply (+) to Battery pack Plus (+); L298N-style driver GND to Battery pack Minus (−); L298N-style driver OUT1 to DC motor Terminal 1; L298N-style driver OUT2 to DC motor Terminal 2.Arduino Uno5V3GNDL298N-style driverENA jumper cap removedIN1ENA (speed)IN2GNDMotor supply (+)OUT1OUT2Battery packMotor power onlyPlus (+)Minus (−)DC motorSwap wires to reverseTerminal 1Terminal 2
DC motor on an L298N-style driver, with speed on pin 3 and a separate battery pack. Wire colours: blue for digital signals, orange for power, grey dashed for ground, yellow for motor and load wiring.
FromThroughToNote
Arduino 5V—L298N-style driver IN1IN1 high and IN2 low fix the direction
Arduino pin 3—L298N-style driver ENA (speed)Digital pin 3, a PWM (~) pin, sets the speed
Arduino GND—L298N-style driver IN2
Arduino GND—L298N-style driver GNDAll grounds joined
L298N-style driver Motor supply (+)—Battery pack Plus (+)The battery powers the motor, never the Arduino 5V
L298N-style driver GND—Battery pack Minus (−)
L298N-style driver OUT1—DC motor Terminal 1
L298N-style driver OUT2—DC motor Terminal 2

The block drives a single pin, so it has no direction pins. Holding IN1 at 5V and IN2 at GND fixes the direction in the wiring. Pull the jumper cap off ENA first, or the driver ignores pin 3 and runs at full speed.

Never power the motor from the Arduino’s 5V pin. Check your driver’s minimum supply voltage: an L298N-style module loses about 2 V, so pick a battery pack about 2 V above your motor’s rating.

Block settings

SettingNew block starts atIn the settings panel
Digital pin3Editable
On/OffonEditable
Speed50%Editable
DirectionforwardComing soon

Step by step

  1. Install the Bridge

    Download, install and start the ArduinoStudio Bridge desktop app. On a real board, the DC Motor block runs only through the Bridge.

  2. Wire the driver and motor
    • Pull the jumper cap off ENA and wire ENA to pin 3.
    • Wire IN1 to 5V and IN2 to GND.
    • Put the motor on OUT1 and OUT2.
    • Battery plus goes to the driver’s motor-supply terminal, battery minus to driver GND.
    • Join driver GND to Arduino GND.
  3. Connect through the Bridge

    Plug in the Uno. If this tab is already connected with USB direct, press Disconnect on that row first. Then click USB direct in the toolbar, press Connect on the Browser-agnostic — for Firefox/Safari/etc. row (that’s the Bridge), and follow the setup until the board is ready.

  4. Add a DC Motor block

    Click + on the sequence, open the Components tab, open Motion and choose DC Motor. Keep Digital pin 3, On/Off on and Speed 50. Direction shows “Coming soon” and stays forward.

  5. Speed up, then stop

    Add a Wait of 3000 ms, a DC Motor block with On/Off on and Speed 100, a Wait of 2000 ms, and a last DC Motor block with On/Off off. The block doesn’t wait for the motor, so the Waits set how long each speed lasts.

  6. Press Play

    The motor runs at half speed for 3 seconds, full speed for 2 seconds, then stops. Pressing Stop also stops it. If it only hums at 50, raise Speed: small motors need a push to get started.

  7. Try it without a board

    With no board connected, Play runs the simulator. Each DC Motor block shows a label like “ON Speed 50% forward”, and pin 3 on the Virtual Board switches between 1 and 0. Speed is not simulated.

Mini-project: sunlight fan

When the room gets bright, a fan runs for five seconds. Keep the motor wired as above and add a photoresistor divider on A0, exactly as in the photoresistor guide. Run the whole project through the Bridge.

Photoresistor divider on A0 and a DC motor driver with speed on pin 3Arduino 5V to Photoresistor Leg 1; Arduino A0 to Photoresistor Leg 2; Arduino A0 to 10 kΩ resistor End 1; Arduino GND to 10 kΩ resistor End 2; Arduino 5V to L298N-style driver IN1; Arduino pin 3 to L298N-style driver ENA (speed); Arduino GND to L298N-style driver IN2; Arduino GND to L298N-style driver GND; L298N-style driver Motor supply (+) to Battery pack Plus (+); L298N-style driver GND to Battery pack Minus (−); L298N-style driver OUT1 to DC motor (fan) Terminal 1; L298N-style driver OUT2 to DC motor (fan) Terminal 2.Arduino Uno5VA03GNDPhotoresistorLeg 1Leg 210 kΩ resistorEnd 1End 2L298N-style driverWired as in the guideIN1ENA (speed)IN2GNDMotor supply (+)OUT1OUT2Battery packMotor power onlyPlus (+)Minus (−)DC motor (fan)Fan blade on the shaftTerminal 1Terminal 2
Photoresistor divider on A0 and a DC motor driver with speed on pin 3. Wire colours: blue for digital signals, green for analog readings, orange for power, grey dashed for ground, yellow for motor and load wiring.
FromThroughToNote
Arduino 5V—Photoresistor Leg 1
Arduino A0—Photoresistor Leg 2Analog pin 0 in the block means A0
Arduino A0—10 kΩ resistor End 1
Arduino GND—10 kΩ resistor End 2
Arduino 5V—L298N-style driver IN1IN1 high and IN2 low fix the direction
Arduino pin 3—L298N-style driver ENA (speed)Digital pin 3, a PWM (~) pin, sets the speed
Arduino GND—L298N-style driver IN2
Arduino GND—L298N-style driver GNDAll grounds joined
L298N-style driver Motor supply (+)—Battery pack Plus (+)The battery powers the motor, never the Arduino 5V
L298N-style driver GND—Battery pack Minus (−)
L298N-style driver OUT1—DC motor (fan) Terminal 1
L298N-style driver OUT2—DC motor (fan) Terminal 2
  1. Read the light

    Build one sequence and turn on Infinity Loop. Add a Photoresistor block from Inputs with Analog pin 0.

  2. Check for brightness

    Add a Check with If set to >, To set to % and Choose set to 70.

  3. Run the fan

    Add a DC Motor block with On/Off on and Speed 80, a Wait of 5000 ms, then a DC Motor block with On/Off off.

  4. Test it

    Press Play and shine a torch on the photoresistor. Through the Bridge, the Photoresistor block waits until the light is above 70%, then the fan runs for five seconds and the cycle starts again.

If the light stays below 70% for 30 seconds, the Bridge stops holding up the sequence but keeps listening. With Infinity Loop on the next pass starts straight away, and the fan can run more than once when the light comes up.

Questions

Can I connect the motor straight to an Arduino pin?

No. A pin supplies about 20 mA, but even a small motor needs hundreds of milliamps and sends voltage spikes back when it stops. Put a driver module, or a transistor with a flyback diode, between the pin and the motor. Power the motor from its own battery, with the grounds joined.

How do I make the motor run in reverse?

Not from the block yet. Direction is marked Coming soon in the settings panel and stays forward, and the block stores only one pin, so it has no direction pin to switch. With the wiring on this page, swap the two motor wires on OUT1 and OUT2.

Why doesn’t the DC Motor block run over USB direct?

The install-free USB direct connection doesn’t support it yet. When you press Play, a message says USB direct does not support DC yet, and the sequence doesn’t run on the board. Connect through the ArduinoStudio Bridge desktop app instead, or try the sequence in the simulator.

What does Speed actually set?

Through the Bridge, Speed is the PWM duty cycle on the Digital pin: 50 means the driver’s enable input is on half the time. Motors don’t respond in a straight line, and many won’t start below about 30 to 40%. Below 12%, the Bridge sends no power at all.

My Arduino resets when the motor starts. Why?

The motor’s start-up current is dragging the supply down or putting noise on the ground. Power the motor from its own battery, never from the Arduino’s 5V pin. Join the grounds, and keep the motor wires short and twisted together.

See the editor in action with a guided demo, no account or install needed: open the demo