Skip to content

Instantly share code, notes, and snippets.

@johnschimmel
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnschimmel/1767b0c01ed36df62b1a to your computer and use it in GitHub Desktop.
Save johnschimmel/1767b0c01ed36df62b1a to your computer and use it in GitHub Desktop.
Ardunio + Hbridge motor control
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