Ardunio + Hbridge motor control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int cloudModulePin = 2; // switch input from cloud module JST connector <-----> Arduino pin 2 | |
const int motor1Pin = 6; // H-bridge pin 2 <-----> Arduino pin 6 | |
const int motor2Pin = 7; // H-bridge pin 7 <-----> Arduino pin 7 | |
// note - arduino and JST connector share common ground | |
void setup() { | |
// set the switch as an input: | |
pinMode(cloudModulePin, INPUT); | |
// set all the other pins you're using as outputs: | |
pinMode(motor1Pin, OUTPUT); | |
pinMode(motor2Pin, OUTPUT); | |
} | |
void loop(){ | |
if (digitalRead(cloudModulePin) == HIGH) { | |
//have motor reel line up | |
digitalWrite(motor1Pin, LOW); | |
digitalWrite(motor2Pin, HIGH); | |
delay(4000); | |
//turn motor off briefly | |
digitalWrite(motor1Pin, LOW); | |
digitalWrite(motor2Pin, LOW); | |
//have motor reel line to starting position | |
digitalWrite(motor1Pin, HIGH); | |
digitalWrite(motor2Pin, LOW); | |
delay(4000); | |
//turn motor off | |
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low | |
digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge high | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment