김선미gledeleunhee
Published

Bluetooth RC Car

This time we learn Bluetooth RC Car

IntermediateProtip2 hours610
Bluetooth RC Car

Things used in this project

Hardware components

Bluetooth Low Energy (BLE) Module (Generic)
×1
DC motor (generic)
×1
9V battery (generic)
9V battery (generic)
×1
Motor Adapter for NI myRIO
Digilent Motor Adapter for NI myRIO
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Arduino Nano R3
Arduino Nano R3
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

rc_car

 (1) 8fi2gq5fkg

rc_car

 0ezz0bvaqj

Code

rc_car

Arduino
#include <SoftwareSerial.h>

SoftwareSerial BTSerial(11, 12);

#define EN1 3 
#define EN2 4 

#define EN3 6  
#define EN4 7 

int carSpeed = 200; 

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

  pinMode(EN1, OUTPUT);
  pinMode(EN2, OUTPUT);

  pinMode(EN3, OUTPUT);
  pinMode(EN4, OUTPUT);
}

void loop() {

  if (BTSerial.available()) {

    char command = BTSerial.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(EN1, HIGH);
  digitalWrite(EN2, LOW);

  // B  
  digitalWrite(EN3, HIGH);
  digitalWrite(EN4, LOW);
}

void moving_backward() {
  // A  
  digitalWrite(EN1, LOW);
  digitalWrite(EN2, HIGH);

  // B  
  digitalWrite(EN3, LOW);
  digitalWrite(EN4, HIGH);
}

void moving_left() {
  // A  
  digitalWrite(EN1, HIGH);
  digitalWrite(EN2, LOW);

  // B  
  digitalWrite(EN3, LOW);
  digitalWrite(EN4, HIGH);
}

void moving_right() {
  // A  
  digitalWrite(EN1, LOW);
  digitalWrite(EN2, HIGH);

  // B  
  digitalWrite(EN3, HIGH);
  digitalWrite(EN4, LOW);
}

void stop_moving() {
  digitalWrite(EN1, LOW);
  digitalWrite(EN2, LOW);
  digitalWrite(EN3, LOW);
  digitalWrite(EN4, LOW);
}   

Credits

김선미

김선미

8 projects • 1 follower
gledel

gledel

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

eunhee

3 projects • 1 follower

Comments

Add projectSign up / Login