Note
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
👉 Ready to explore and create with us? Click [here] and join today!
Lesson 34: TT Motor
In this lesson, you will learn how to control a motor using an Arduino Uno R3 or R4 and an L9110 motor control board. We’ll cover defining motor pins and setting their speed through programming. This tutorial will walk you through the process of connecting and controlling a motor, demonstrating the basic principles of motor operation and control in Arduino projects. Geared towards beginners, this lesson provides a hands-on approach to understanding output operations on the Arduino platform.
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
Name |
ITEMS IN THIS KIT |
LINK |
|---|---|---|
Universal Maker Sensor Kit |
94 |
You can also buy them separately from the links below.
Component Introduction |
Purchase Link |
|---|---|
Arduino UNO R3 or R4 |
|
- |
|
- |
Wiring
Code
Code Analysis
The first part of the code defines the motor control pins. These are connected to the L9110 motor control board.
// Define the motor pins const int motorB_1A = 9; const int motorB_2A = 10;
The
setup()function initializes the motor control pins as output using thepinMode()function. Then it usesanalogWrite()to set the speed of the motor. The value passed toanalogWrite()can range from 0 (off) to 255 (full speed). Adelay()function is then used to pause the code for 5000 milliseconds (or 5 seconds), after which the motor speed is set to 0 (off).void setup() { pinMode(motorB_1A, OUTPUT); // set motor pin 1 as output pinMode(motorB_2A, OUTPUT); // set motor pin 2 as output analogWrite(motorB_1A, 255); // set motor speed (0-255) analogWrite(motorB_2A, 0); delay(5000); analogWrite(motorB_1A, 0); analogWrite(motorB_2A, 0); }