DC Motor

Parts Used

  • 1 DC Motor

  • 2 Buttons

  • 1 H-Bridge

  • 16 Jumper Wires

  • 1 Fan

Time Spent

Approximately 1.8 hours

Key Features

  • The circuit has 2 buttons, one for reverse the direction, another for switch off the fan completely.

  • The kill switch is not connected to the arduino. I prefer to think of it as a hard wired logic gate.

The Code

int enablePin = 11;
int in1Pin = 10;
int in2Pin = 9;
int switchPin = 7;

void setup()
{
    pinMode(in1Pin, OUTPUT);
    pinMode(in2Pin, OUTPUT);
    pinMode(enablePin, OUTPUT);
    pinMode(switchPin, INPUT_PULLUP);
}

void loop()
{
    boolean reverse = digitalRead(switchPin);
    setMotor(255, reverse);
}

void setMotor(int speed_, boolean reverse)
{
    analogWrite(enablePin, speed_);
    digitalWrite(in1Pin, ! reverse);
    digitalWrite(in2Pin, reverse);
}