Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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);
//turn motor off briefly
digitalWrite(motor1Pin, LOW);
digitalWrite(motor2Pin, LOW);
//have motor reel line to starting position
digitalWrite(motor1Pin, HIGH);
digitalWrite(motor2Pin, LOW);
//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