Yun Jin Yonggledel임동교이하늘
Published © GPL3+

Innovation Lab #20 Bluetooth_Motor

Bongilcheon High School_Innovation Lab Project.

BeginnerProtip15 minutes250
Innovation Lab #20 Bluetooth_Motor

Things used in this project

Story

Read more

Schematics

Bluetooth_Motor

Bluetooth_Motor

Code

Bluetooth_Motor

Arduino
Using the bluetooth sensor, turning the motor.
#define ENA 3 
#define EN1 2 
#define EN2 4 
#define ENB 5  
#define EN3 7 
#define EN4 6  

int carSpeed = 200; 
int carSpeed_smooth = 50; 

void setup() {
  Serial.begin(9600);  
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(EN1, OUTPUT);
  pinMode(EN2, OUTPUT);
  pinMode(EN3, OUTPUT);
  pinMode(EN4, OUTPUT);
}

void loop() {

  if (Serial.available()) {
    char command = Serial.read();
    
    if (command == 'F' || command == 'f') {
      moving_forward();
    }
    else if (command == 'B' || command == 'b') {
      moving_backward();
    }
    else if (command == 'L' || command == 'l') {
      moving_left();
    }
    else if (command == 'R' || command == 'r') {
      moving_right();
    }
    else if (command == 'S' || command == 's') {
      stop_moving();
    }
    else if (command == 'O' || command == 'o') {
      moving_smooth_right();
    }
    else if (command == 'P' || command == 'p') {
     moving_smooth_left();
    }
    else {
      stop_moving();
    }
  }
  delay(100);
}

void moving_forward() {
  digitalWrite(EN1, HIGH);
  digitalWrite(EN2, LOW);
  analogWrite(ENA, carSpeed);

  digitalWrite(EN3, HIGH);
  digitalWrite(EN4, LOW);
  analogWrite(ENB, carSpeed);
}

void moving_backward() {
  digitalWrite(EN1, LOW);
  digitalWrite(EN2, HIGH);
  analogWrite(ENA, carSpeed);

  digitalWrite(EN3, LOW);
  digitalWrite(EN4, HIGH);
  analogWrite(ENB, carSpeed);
}

void moving_left() {
  digitalWrite(EN1, LOW);
  digitalWrite(EN2, HIGH);
  analogWrite(ENA, carSpeed);

  digitalWrite(EN3, HIGH);
  digitalWrite(EN4, LOW);
  analogWrite(ENB, carSpeed);
}

void moving_right() {
  digitalWrite(EN1, HIGH);
  digitalWrite(EN2, LOW);
  analogWrite(ENA, carSpeed);

  digitalWrite(EN3, LOW);
  digitalWrite(EN4, HIGH);
  analogWrite(ENB, carSpeed);
}

void stop_moving() {
  analogWrite(ENA, LOW);
  analogWrite(ENB, LOW);
}

void moving_smooth_left() {
  digitalWrite(EN1, HIGH);
  digitalWrite(EN2, LOW);
  analogWrite(ENA, carSpeed_smooth);

  digitalWrite(EN3, HIGH);
  digitalWrite(EN4, LOW);
  analogWrite(ENB, carSpeed);
}

void moving_smooth_right() {
  digitalWrite(EN1, HIGH);
  digitalWrite(EN2, LOW);
  analogWrite(ENA, carSpeed);

  digitalWrite(EN3, HIGH);
  digitalWrite(EN4, LOW);
  analogWrite(ENB, carSpeed_smooth);
}

Credits

Yun Jin Yong

Yun Jin Yong

3 projects • 8 followers
gledel

gledel

7 projects • 84 followers
Looking back on my childhood, I was happy when I was making something and I was proud of myself. "Making is instinct!"
임동교

임동교

3 projects • 8 followers
이하늘

이하늘

2 projects • 3 followers

Comments