Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Muhammad_Munir
Published © GPL3+

Bidirectional Motor Control

Bidirectional Motor Control with Arduino and push buttons

BeginnerFull instructions provided1 hour143
Bidirectional Motor Control

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Relay module
×1
Push buttons
×1
Bread board
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Motor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Code

Arduino
// set pin numbers:
const int btn_Clock_wise = 8;
const int btn_Anti_Clock_wise = 10;
const int btn_Stop = 9;
const int Relay1 =  A0;
const int Relay2 = A1;


void setup() {
  Serial.begin(9600);

  pinMode(Relay1, OUTPUT);
  pinMode(Relay2, OUTPUT);
  pinMode(btn_Clock_wise, INPUT_PULLUP);
  pinMode(btn_Anti_Clock_wise, INPUT_PULLUP);
  pinMode(btn_Stop, INPUT_PULLUP);
  digitalWrite(Relay1, HIGH);
  digitalWrite(Relay2, HIGH);
}

void loop() {

  if (digitalRead(btn_Clock_wise) == LOW) {
    digitalWrite(Relay2, HIGH);
    delay (500);
    digitalWrite(Relay1, LOW);
    Serial.println("Rotate motor anti-Clock wise");
    delay (500);
  }
  else if (digitalRead(btn_Anti_Clock_wise) == LOW) {
    digitalWrite(Relay1, HIGH);
    delay (500);
    digitalWrite(Relay2, LOW);
    Serial.println("Rotate motor Clock wise");
    delay (500);
  }
    else if (digitalRead(btn_Stop) == LOW) {
    digitalWrite(Relay1, HIGH);
    digitalWrite(Relay2, HIGH);
    Serial.println("Stop the motor");
    delay (500);
  }
}

Credits

Muhammad_Munir
77 projects • 50 followers
I am Arduino programmer, also expertise in ESP32 and 8266 wifi modules.

Comments