
Beginners Guide to Robotics
Robo Explorers 1
Motor
What are Motors
A DC motor is like a little machine that makes things spin when you give it electricity. Imagine it as a tiny fan inside a toy car: when you connect it to a battery, the motor turns and makes the wheels move. This kind of motor is called "DC" because it runs on Direct Current, which is the type of electricity you get from batteries. DC motors are used in lots of fun projects, like robots, toy cars, and even in household appliances like fans!
Motor applications in real world
Motors are like the engines that make many everyday things move and work. Here are some fun examples of how motors are used in the real world:
Toy Cars and Robots:
Tiny motors help toy cars zoom around and robots move their arms or wheels.Fans:
Motors spin the blades in fans to keep you cool on a hot day.Electric Vehicles:
Cars, buses, and bikes can use electric motors to drive without gasoline.Household Appliances:
Many kitchen gadgets like blenders, washing machines, and vacuum cleaners have motors to help them do their jobs.Power Tools:
Electric drills, saws, and other tools use motors to make work easier.Drones:
Small motors help drones fly high in the sky for fun and photography.Computers and Electronics:
Some parts of computers, like cooling fans or hard drives, use motors.Helicopters and Airplanes:
Motors (or engines) help these vehicles move through the air.Conveyor Belts in Factories:
Motors move products along belts so they can be packaged or assembled.Household Curtains and Blinds:
Motors can automatically open or close curtains, making life more convenient.
In all these examples, motors turn electrical energy into movement, helping make our lives easier and a lot more fun!How to connect Motor to Yellow tyro board
Existing Motor Code
Explanation
What This Code Does:
When you press the button connected to the motor (the "motor switch"), the Arduino checks which way the motor should spin. It uses a memory spot calledmotorState
to decide:If
motorState
is 0:
The motor spins forward. This means the code turns on the "forward" control (turning a specific pin on) for 2 seconds.If
motorState
is 1:
The motor spins in reverse. The code turns on the "reverse" control for 2 seconds instead.
How It Works:
The code reads the button. When the button is pressed, it looks at
motorState
:If it's 0, the motor goes forward for 2 seconds, then
motorState
changes to 1.If it's 1, the motor goes in reverse for 2 seconds, then
motorState
changes back to 0.
After running the motor, the code turns both controls off and waits a short time before checking the button again.
Why It's Cool:
This snippet lets you change the motor's direction every time you press the button, so your motor can spin one way and then switch the other way on the next press. It's like having a toy car that goes forward, then reverses when you tap it!
Fun Activity!
Controlling the Motor Speed
Welcome to the Motor Speed Challenge using your Yellow Tyro Board from JumpLabs®! In this activity, you'll explore how you can control a motor's speed by turning numbers into motion. Here's what you'll do:
Set Your Speed:
Open the Serial Monitor on your computer and enter a number between 0 and 255. This number represents the speed at which your motor will run—the higher the number, the faster it goes!Press the Button:
When you press the button connected to A0 on your Yellow Tyro Board, your motor (wired to pins D9 and D10) will spring into action and run forward at the speed you set.Watch It Go:
See how changing the speed value affects the motor's performance. It's like having a remote control for a mini car, where you decide exactly how fast it moves!
Code Explanation
Header Comment:
The purpose of the sketch: you enter a speed value (from 0 to 255) in the Serial Monitor, and when you press the button (on A0), the motor runs forward at that speed.
Pin Definitions:
motorForwardPin
(D9) is used for PWM speed control.motorReversePin
(D10) is set LOW to ensure the motor runs in the forward direction.buttonPin
(A0) is used to trigger the motor when pressed (assumed to use an external pull-down resistor so it reads LOW when not pressed and HIGH when pressed).
Setup:
Insetup()
, the Serial Monitor is started so you can input the motor speed. The motor pins and button pin are configured as outputs or inputs accordingly. The motor is initialized to the off state.Loop:
Inloop()
, the program:Checks if a speed value is entered via Serial and updates
speedValue
.Checks the state of the button:
If the button is pressed (reads HIGH), it sends a PWM signal on D9 using
analogWrite()
with the given speed value, turning on the motor.If the button is not pressed, the motor remains off.
This sketch allows you to experiment with motor speed control interactively—enter a speed value, press the button, and see your motor run at that speed. Enjoy exploring motor control with your Yellow Tyro Board!