Leesounghoongledel케인
Published © GPL3+

Arduino (6) (FabLab)

I made an RC car to use with a Bluetooth module.

BeginnerProtip1 hour531
Arduino (6) (FabLab)

Things used in this project

Hardware components

Motor Adapter for NI myRIO
Digilent Motor Adapter for NI myRIO
×1
Arduino Nano R3
Arduino Nano R3
×1
Breadboard (generic)
Breadboard (generic)
×1
DC motor (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
9V battery (generic)
9V battery (generic)
×1
Solid V Wheel Kit
OpenBuilds Solid V Wheel Kit
×1
SparkFun Bluetooth Modem - BlueSMiRF Silver
SparkFun Bluetooth Modem - BlueSMiRF Silver
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

rc car

This circuit constitutes rc car

Code

rc car

Arduino
this code is that drive a rc car
// 모터B의 핀배열 
#define B1A 5// motor B 속도조절
#define B1B 6// motor B 방향조절

// 모터A의 핀배열
#define A1A 9  // motor A 속도조절
#define A1B 10 // motor A 방향조절

int carSpeed = 200; // RC카의 속도

void setup() {
  Serial.begin(9600);    // 시리얼 통신 초기화(0번:RX, 1번:TX로 사용), 하드웨어 시리얼 포트로 블루투스와 통신

  pinMode(A1A, OUTPUT);
  pinMode(A1B, OUTPUT);
  pinMode(B1A, OUTPUT);
  pinMode(B1B, OUTPUT);
}

void loop() {

  if (Serial.available()) {
    
    char command = Serial.read(); // 블루투스로 수신된 명령어를 command에 저장
    
    if (command == 'F' || command == 'f') {
      // F 또는 f를 입력으로 받는 경우 RC카를 전진시키는 함수 호출
      moving_forward();
    }
    else if (command == 'B' || command == 'b') {
      // B 또는 b를 입력으로 받는 경우 RC카를 후진시키는 함수 호출
      moving_backward();
    }
    else if (command == 'L' || command == 'l') {
      // L 또는 l을 입력으로 받는 경우 RC카를 왼쪽으로 회전시키는 함수 호출
      moving_left();
    }
    else if (command == 'R' || command == 'r') {
      // R 또는 r을 입력으로 받는 경우 RC카를 오른쪽으로 회전시키는 함수 호출
      moving_right();
    }
    else if (command == 'S' || command == 's') {
      // S 또는 s를 입력으로 받는 경우 RC카를 정지시키는 함수 호출
      stop_moving();
    }
    else {
      // 인식하지 못하는 명령어 수신시 RC카를 정지시키는 함수 호출
      stop_moving();
    }
    
  }

  // 일정시간 지연
  delay(100);
}

void moving_forward() {
  // 모터A를 정방향으로 회전
  digitalWrite(A1B, HIGH);
  analogWrite(A1A, 255-carSpeed);

  // 모터B를 정방향으로 회전
  digitalWrite(B1B, HIGH);
  analogWrite(B1A, carSpeed);
}

void moving_backward() {
 // 모터A를 역방향으로 회전
  digitalWrite(A1B, LOW);
  analogWrite(A1A, carSpeed);

  // 모터B를 역방향으로 회전
  digitalWrite(B1B, LOW);
  analogWrite(B1A, carSpeed);
}

void moving_left() {
  // 모터A를 정방향으로 회전
  digitalWrite(A1B, HIGH);
  analogWrite(A1A, carSpeed);

  // 모터B를 역방향으로 회전
  digitalWrite(B1B, LOW);
  analogWrite(B1A, carSpeed);
}

void moving_right() {
 // 모터A를 역방향으로 회전
  digitalWrite(A1B, LOW);
  analogWrite(A1A, carSpeed);

  // 모터B를 정방향으로 회전
  digitalWrite(B1B, HIGH);
  analogWrite(B1A, carSpeed);
}

void stop_moving() {
  // 모터A와 모터B를 비활성화
  analogWrite(A1A, LOW);
  analogWrite(A1B, LOW);
  digitalWrite(B1A, LOW);
  digitalWrite(B1B, LOW);
}

Credits

Leesounghoon

Leesounghoon

9 projects • 4 followers
Hi my name is sung hoon lee. I`m a student at Bongilcheon High School. I want to learn 3D Printing and how to use arduino code(+python code)
gledel

gledel

100 projects • 115 followers
Looking back on my childhood, I was happy when I was making something and I was proud of myself. "Making is instinct!"
케인

케인

7 projects • 2 followers
I'm 17-year old. also I'm bongilcheon high school student. I'm study 3D print.

Comments