The Regular Motor
The regular motor is simple. You can test if it will work by just plugging in one side to a voltage source and the other side to a ground. The more volts sent to it, the harder it spins. Test it out!
Controlling the motor with Arduino
Just plug the positive into one of the output Arduino pins and the negative into the breadboard. Here is a sample code to get the motor to turn on and off.
#define Motor A5 //defines "Motor" and uses the A5 pin to turn on or off (You can use any A pin)
void setup() {
pinMode(Motor,OUTPUT); //Defines the pin for the motor on "A5" to be an output
}
void loop() {
digitalWrite(Motor, HIGH); //this just turns the motor on
delay (400);
digitalWrite(Motor, LOW); //This turns the motor off
delay (400);
}
void setup() {
pinMode(Motor,OUTPUT); //Defines the pin for the motor on "A5" to be an output
}
void loop() {
digitalWrite(Motor, HIGH); //this just turns the motor on
delay (400);
digitalWrite(Motor, LOW); //This turns the motor off
delay (400);
}
Did your motor work? Figure out if and how you want to use this motor in your device. Install it and play with your code to get it to do what you want.
Once you are happy with it, add that code to your main mechatronic code.
Once you are happy with it, add that code to your main mechatronic code.