Download presentation
Presentation is loading. Please wait.
1
Arduino Motor Lab Inspired by NYU ITP project
CTY SAR FCPS Shawn Lupoli, Elliot Tan
2
Let’s understand what we are working with…
3
How to change a Motor’s Directions?
Working with a DC motor, which is a high-current DC load Can reverse the direction of the current in the motor using an H-bridge H-bridge is a circuit that enables voltage to be applied in either direction
4
Visual of the H-Bridge
5
Get the motor running, then turn the motor’s direction with a switch
Goal Get the motor running, then turn the motor’s direction with a switch
6
Programming the Motor Turn
7
Motor Part 1 Initializing global variables Setup()
Need a switch input, H-bridge leg1 (pin 2, 1A), H-bridge leg2 (pin7, 2A), and an H-bridge enable pin “const int switchPin = 2” , “const int motor1Pin = 3” , “const int motor2Pin = 4” , “const int enablePin = 9” Setup() pinMode(pin, mode) – configures the specified pin to behave either as an input or an output digitalWrite(pin, value) – write a HIGH or LOW value to a digital pin
8
Motor Part 2 Loop() Functions Things to consider digitalWrite()
What happens when “digitalRead(switchPin) == High” ? What happens if this is not true?
9
CODE
10
Building the Motor circuit
11
Supplies 1 Arduino Leonardo board 1 breadboard
7 short wires (2 red, 5 black) 6 medium wires (3 brown, 2 red, 1 black) 2 long wires (1 red, 1 black) 1 H-Bridge 1 switch 1 9V battery 1 resistor (1 kΩ) 1 motor * Notes: Wires are 22 or 24 AWG, solid Short wires = 5 cm Medium wires = 12 cm Long wires = 16 cm
12
Diagram of Motor Circuit
13
Connecting Code and Circuit
14
Putting it All Together
UPLOAD! Remember to check for the flashing RX and TX lights, and a “Successful upload” message in your console Understanding the process First, set up constants for the switch pin, the two H-bridge pins, and the enable pin of the H-bridge Second, set all pins for the H-bridge as outputs, and the pin for the switch as input Third, turn the motor on by setting the enable pin high so the H-bridge turns the motor on Fourth, read the switch in loop(). If input = “high”, turn the motor one way by making one H-bridge pin high and the other low. If input = “low” reverse the states of the two H-bridge pins.
15
Troubleshooting Make sure the H-bridge is in the right place!
Check connection of wires between battery and circuit board! Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.