Tag Archives: motor

Arduino 9: The H-Bridge

An H-Bridge is like an electric double-switch, or double-relay. A small current from the Arduino at one of two pins can turn on a much larger current at two other pins. This is useful for controlling two-state devices, like motors that you want to run both forwards and backwards. For this project I used an SN75441 H-bridge chip.


Have the Arduino read the state of a switch to control a high-voltage motor running forwards and backwards. Use a 9V battery to power the Arduino (remember to change the jumper pin), so Vin is 9V. Connect the two motor wires directly to the H-bridge chip pins labeled “Motor”, and connect both pins 4 and 5 of the H-bridge to ground.


D2, D3 and D4 are digital pins on the Arduino


int motorPin0 = 2;

int motorPin1 = 3;

int switchPin = 4;

int state = 0;

void setup() {

pinMode(motorPin0, OUPUT);

pinMode(motorPin1, OUTPUT);

pinMode(switchPin, INPUT);


void loop() {

state = digitalRead(switchPin);

switch(state) {

case 0:

digitalWrite(motorPin0, HIGH);

digitalWrite(motorPin1, LOW);


case 1:

digitalWrite(motorPin0, LOW);

digitalWrite(motorPin1, HIGH);




Note the use of the switch statement:


case value1:

(code block here);


case value2:

(code block here);


case value3:

(code block here);



(code block here);



Where variable can take on the values value1, value2, value3, etc. (which are usually integer values), and based on the value of variable, different code is run. The default option is run if the value of variable doesn’t match any of the other cases. The keyword break tells the program to jump to the end of the switch statement, skipping the code in between.