joeydream
Published © Apache-2.0

Bluetooth Boat in doubleA

An Android-control(BT) system is added in a motor toy boat and it can go any direction slowly.

IntermediateShowcase (no instructions)8,825
Bluetooth Boat in doubleA

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Motor Control driver chip L9110
×1
HC-06 Bluetooth Module
×1
Simple motor
×1
Servos (Tower Pro MG996R)
×1

Story

Read more

Schematics

circuit_RkmZDUJZHn.jpeg

Schematic design

by Designspark

Code

finish.ino

Arduino
#include <SoftwareSerial.h> 
#include <Wire.h>  //SoftwareSerialWire SoftwareSerial 
#include <Servo.h>
SoftwareSerial I2CBT(A0,A1); //PIN10PIN11RXTX 
Servo myservo;  // create servo object to control a servo


int pos = 0;    // variable to store the servo position
int INA = 9; 
int INB = 10;
//int LED = 13;

void setup() {
  Serial.begin(9600); //Arduino9600 
  I2CBT.begin(9600); //57600
  myservo.attach(3);  // attaches the servo on pin 3 to the servo object
  pinMode(INA,OUTPUT); 
  pinMode(INB,OUTPUT); 
}

void loop() { 
  byte cmmd[20]; 
  int insize; 
  servo(90);
  while(1){ 
    if ((insize=(I2CBT.available()))>0){
       Serial.print("input size = "); 
       Serial.println(insize);  // 
       for (int i=0; i<insize; i++) {
           Serial.print(cmmd[i]=char(I2CBT.read()));//
           //Serial.print("\n");
       }  //for
     switch (cmmd[0]) {
        case 97: //'a'     
          //digitalWrite(LED,HIGH);
          motorforward();
          Serial.print("  go");
        break;  

        case 98: //'b'
          //digitalWrite(LED,LOW);
          motorstop();
          Serial.print("  stop");
        break;

        case 102: //'f'
          //digitalWrite(LED,LOW);
          motorback();
          Serial.print("  back");
        break;






        case 99: //'c'
          servo(150);
          Serial.print("  Left");
        break;

         case 100: //'d'
          servo(90);
          Serial.print("  Ctr");
        break;
       
        case 101: //'e'
          servo(30);
          Serial.print("  Right");
        break;
               
     } //Switch     
     Serial.print("\n");
     
     
     } //if 
          
 
  
  
  } //while
}




//**************************
void servo(int servopos) {
  myservo.write(servopos);              // tell servo to go to position in variable 'pos'
  delay(15);                       // waits 15ms for the servo to reach the position
}

void motorforward() { 
  digitalWrite(INA,LOW);
  digitalWrite(INB,HIGH); 
  //delay(1000); 
}

void motorstop() { 
  digitalWrite(INA,LOW);
  digitalWrite(INB,LOW); 
  //delay(1000); 
}

void motorback() { 
  digitalWrite(INA,HIGH);
  digitalWrite(INB,LOW); 
  //delay(1000); 
}

Credits

joeydream

joeydream

0 projects • 3 followers

Comments