
아이들 장난감을 지인에게 물려 받았습니다.
그중에는 RC카도 있었습니다. 외관은 괜찮지만, 문제는 조정기도 없고 배터리도 문제가 있었습니다. ㅜㅜ
아이들이 그냥 갖고 노는 것도 좋지만, 조정해서 달리는 걸 보여주고 싶었습니다.
그래서 ‘달려라 뿡뿡이!’ 프로젝트를 진행했습니다.
우리 뿡뿡이를 움직이기 위해 블루투스카로 개조했습니다.
이때 필요한 준비물은
- MCU : 아두이노 나노 or UNO
- 모터구동 : l298n(듀얼 모터드라이버)
- 통신 : 블루투스 모듈(HC-06)
- 전원 : 스위치 있는 12v 배터리팩, AA 배터리 8개
- 기타 : 브레드보드, 케이블, 안드로이드 스마트폰
뿡뿡이에게 필요한 주요 부품과 App은 크게 3가지 입니다.
- 뿡뿡이와 스마트폰과 통신하기 위한 Bluetooth(블루투스) 모듈
- 2개의 모터 제어를 위한 모터드라이버(L298N) 모듈
- 자동차 조정을 위한 App(Arduino Bluetooth RC Car)
시스템 구조
시스템구성은 자동차, 조정기로 구분됩니다.
자동차는 무선통신을 수신받는 수신부와 제어장치로 구성됩니다.
자동차와 조정기가 블루투스로 연결되면,
조정기에서는 전진은 F, 후진은 B, 우회전 R 과 같은 문자열을 자동차의 수신기로 보냅니다.
그럼 제어장치에서는 신호는 받아 모터를 제어합니다.
만약 F와 같은 문자열을 받으면, 추진모터를 정방향으로 갈 수 있도록 전기를 보냅니다.
자동차의 구성과 제어장치에 따라 얼마든지 개조가 가능합니다.
LED를 부착해서 전진시 해드라이트를 켤수도 있고, 초음파 센서를 장착해서 장애물이 있으면 자동으로 멈출 수 있습니다.
조정기의 경우도 얼마든지 다른 형태로 응용 가능합니다. 자이로센서와 블루투스 모듈을 활용해서 장갑모양과 같은 특별한 형태의 조정기로도 제작이 가능합니다.
회로도
회로도를 그릴 수 있는 Fritzing 도구로 제작한 뿡뿡이 제어장치 회로도 입니다.
일부 모듈이 없어서 유사한 모듈로 대체하여 사용하였습니다.
제작순서
- 1단계 : 자동차 분해
- 2단계 : 제어장치 제작
- 부품결합
- 아두이노 소스 업로드
- 블루투스 테스트
- 3단계 : 자동차와 제어장치 연결
- 4단계 : 스마트폰App과 자동차 블루투스 연결 및 제어장치 작동여부 확인
아두이노 소스코드
GitHub 주소 : https://github.com/forearth/arduino-learning-sample/tree/master/BluetoothCar
#include SoftwareSerial BTSerial(2, 3); // 소프트웨어 시리얼 설정(* RX, TX 보드에 연결할때는 반대)
//모터A 컨트롤
int motorA1=7;
int motorA2=6;
int speedPinA=9;
//모터B 컨트롤
int motorB1=5;
int motorB2=4;
int speedPinB=10;
int vSpeed=255; // Default speed, from 0 to 255
void setup() {
Serial.begin(9600);
BTSerial.begin(9600);
pinMode(motorA1, OUTPUT);
pinMode(motorA2, OUTPUT);
pinMode(motorB1, OUTPUT);
pinMode(motorB2, OUTPUT);
motorStop();
}
void loop() { // run over and over
if (BTSerial.available()) { //블루투스로 데이터 수신
byte data=BTSerial.read(); //수신 받은 데이터 저장
Serial.write(data); //수신된 데이터 출력
analogWrite(speedPinA, vSpeed);
analogWrite(speedPinB, vSpeed);
switch(data){
case 'F':
motorGo();
break;
case 'B':
motorBack();
break;
case 'G':
motorRightGo();
break;
case 'I':
motorLeftGo();
break;
case 'H':
motorRightBack();
break;
case 'J':
motorLeftBack();
break;
case 'S':
motorStop();
break;
default:
return;
}
}
}
void motorGo() {
digitalWrite(motorA1, HIGH);
digitalWrite(motorA2, LOW);
digitalWrite(motorB1, LOW);
digitalWrite(motorB2, LOW);
}
void motorBack() {
digitalWrite(motorA1, LOW);
digitalWrite(motorA2, HIGH);
digitalWrite(motorB1, LOW);
digitalWrite(motorB2, LOW);
}
void motorRightGo() {
digitalWrite(motorA1, HIGH);
digitalWrite(motorA2, LOW);
digitalWrite(motorB1, HIGH);
digitalWrite(motorB2, LOW);
}
void motorLeftGo() {
digitalWrite(motorA1, HIGH);
digitalWrite(motorA2, LOW);
digitalWrite(motorB1, LOW);
digitalWrite(motorB2, HIGH);
}
void motorRightBack() {
digitalWrite(motorA1, LOW);
digitalWrite(motorA2, HIGH);
digitalWrite(motorB1, HIGH);
digitalWrite(motorB2, LOW);
}
void motorLeftBack() {
digitalWrite(motorA1, LOW);
digitalWrite(motorA2, HIGH);
digitalWrite(motorB1, LOW);
digitalWrite(motorB2, HIGH);
}
void motorStop() {
digitalWrite(motorA1, LOW);
digitalWrite(motorA2, LOW);
digitalWrite(motorB1, LOW);
digitalWrite(motorB2, LOW);
}