Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
KDPA
Published

iPhone Arduino Extension

iRobbie is the revolutionary app that brings smartphone power to your Arduino project.

IntermediateProtip8,560
iPhone Arduino Extension

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Arduino Sensor Shield v5
×1
HM-10 Bluetooth Module
×1
4WD Robot Chassis Kit
×1
L298N Dual H-Bridge DC Motor Speed Controller Board
×1
2x18650 Battery Holder
×1
Buzzer
×1
Smartphone Stand
×1
Arduino Cable kit
×1
Two-sided Mounting Tape
×1
Arduino Power Jack connector
×1
Arduino Smart Robot Car Kit (Optional)
As an alternative you can buy one of the commercially available Smart Robot Car Kits. Be sure that you use HM-10 bluetooth module. Replace it with HM-10 if the Smart Robot Car Kit has different type of Bluetooth module
×1

Software apps and online services

iRobbie-A
Arduino IDE
Arduino IDE

Story

Read more

Schematics

Assembled car

Function of each part:
1. Battery holder with a switch: provide power supply for the vehicle
2. Electric motors + wheels: drive the vehicle to move
3. Acrylic plates: the frame of the car
4. L298N motor driving board: drive the motors to rotate
5. UNO controller board: the brain of the car
6. V5 sensor expansion board: combined with the UNO, make the connection become more easier
7. Bluetooth module HM-10: provide the Bluetooth connection with iPhone and iRobbie App
8. Smartphone stand: hold the smartphone on the car

You can find an example of detailed instructions and diagrams here: https://www.elegoo.com/tutorial/Elegoo%20Smart%20Robot%20Car%20Kit%20V2.0.2019.03.19.zip

Code

Robbie_A1.ino

Arduino
Arduino code. You can also download it from https://www.robbie-app.com
#include <Servo.h>

Servo servo;
int angle = 0;
boolean forward1 = false ;
String bluetoothRead, Str_x, Str_y, Str_p, Str_s;
int x ;
int y ;
int points;
int length;
const int buzzer = 10; 
int s;
unsigned long previousMillis = millis();        // will store last time LED was updated

const long interval = 1000;           // interval at which to blink (milliseconds)

#define ENA 11
#define ENB 6
#define IN1 5
#define IN2 7
#define IN3 8
#define IN4 9
#define DELAY 20

int carSpeed = (y*3);
int speed_Coeff = (1 + (x/50));

void setup() { 
  Serial.begin(9600);
  Serial.flush();
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
  pinMode(ENA,OUTPUT);
  pinMode(ENB,OUTPUT);
  pinMode(buzzer, OUTPUT);
  stop();
  servo.attach(13);
  servo.write(angle);
}

void loop() {
 int i=0;
  char commandbuffer[200];
unsigned long currentMillis = millis();

  if(Serial.available()){
    
     delay(10);

     while( Serial.available() && i< 199) {
        commandbuffer[i++] = Serial.read();
  
      
     }
     commandbuffer[i++]='\0';
     bluetoothRead = (char*)commandbuffer;
     length = bluetoothRead.length();
     Serial.println(bluetoothRead);
  
     
     if(bluetoothRead.substring(0, 1).equals("x")){
       
       int i=1;
       while(bluetoothRead.substring(i, i+1) != ("y")){
       i++;
       }
       
       Str_x = bluetoothRead.substring(1, i);
       x = Str_x.toInt();
            
       Str_y = bluetoothRead.substring(i+1, length - 2);
       y = Str_y.toInt();

       Str_p = bluetoothRead.substring(length - 2, length - 1);
       points = Str_p.toInt();

       Str_s = bluetoothRead.substring(length - 1, length);
       s = Str_s.toInt(); 

       i = 1;
 
       Serial.println(x);
       Serial.println(y);
       Serial.println(points);
       Serial.println(s);
       Serial.println(length );        
      
       stop();
       carSpeed = (y*2.5);
       speed_Coeff = (1 + (x/50));

  
    if(points == 1){
    forward();
    }
    if(points == 0){
    stop();
    }
    if(points == 2){
    back(); 
    }
  
    if(points == 3){
    fleft(); 
    }

    if(points == 4){
    fright(); 
    }

    if(points == 5){
     left(); 
    }

    if(points == 6){
    right(); 
    }

    if(points == 7){
     bleft(); 
    }

    if(points == 8){
    bright(); 
    }

    if(points == 9){
    findo(); 
    }
     
  
    
    if (s == 7){
    play_do();
    }

    if (s == 6){
    play_re();
    }

    if (s == 5){
    play_mi();
    }

    if (s == 4){
    play_fa();
    }

    if (s == 3){
    play_sol();
    }

    if (s == 2){
    play_la();
    }

    if (s == 1){
    play_ci();
    }
//When an object is detected the iRobbie App will start sending s = 8 to the Arduino. 
//You can use it in your own Arduino code. The commented lines is an example. 

    if (s == 8){
  //    if (millis() - previousMillis >= DELAY)
  //    {previousMillis += DELAY;
 //     if (forward1)
 //     {
 //       servo.write(-- angle);
 //       if(angle == 0)
 //       forward1 = false;
//      }
 //     else
//      {
 //      servo.write(++ angle);
 //       if (angle == 30)
 //       forward1 = true;
 //     }
 //     }
 
      // scan from 0 to 180 degrees
 // for(angle = 10; angle < 90; angle++)  
 // {                                  
//    servo.write(0);               
//    delay(15);                   
//  } 
//      servo.write(90);

 //    }
 // servo.write(-90);

//    }
     
  // now scan back from 180 to 0 degrees
//  for(angle = 90; angle > 10; angle--)    
 // {                                
 //   servo.write(angle);           
 //   delay(15);       
//  } 
//     servomove(); 
    }

}
}
}

void servomove(){
    unsigned long currentMillis = millis();
 if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
  
   for(angle = 0; angle < 60; angle++)  
  {                                  
    servo.write(angle); 
      previousMillis = currentMillis;              
    delay(10);                   
  } 
  // now scan back from 180 to 0 degrees
 for(angle = 60; angle > 0; angle--)    
  {                                
    servo.write(angle); 
  }
      previousMillis = currentMillis;          
    delay(10);  
}
}


void forward(){ 
  analogWrite(ENA,carSpeed);
  analogWrite(ENB,carSpeed);
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH);
  delay(25);
//  Serial.println("Forward");
}

void forwards(){ 
  analogWrite(ENA,carSpeed);
  analogWrite(ENB,carSpeed);
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH);
  delay(25);
 // Serial.println("Forward_slow");
}

void back(){
  analogWrite(ENA,(carSpeed - 20));
  analogWrite(ENB,(carSpeed - 20));
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  delay(25);
 // Serial.println("Back");
}

void backs(){
  analogWrite(ENA,(carSpeed - 20));
  analogWrite(ENB,(carSpeed - 20));
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  delay(25);
//  Serial.println("Back_slow");
}
void left(){
  analogWrite(ENA,x);
  analogWrite(ENB,x);
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  delay(25); 
//  Serial.println("Left");
}

void right(){
  analogWrite(ENA,x);
  analogWrite(ENB,x);
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH);
  delay(25);
 // Serial.println("Right");
}


void fright(){
  analogWrite(ENA,carSpeed);
  analogWrite(ENB,carSpeed/speed_Coeff);
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH);
  delay(25);
//  Serial.println("Forward_right");
}



void fleft(){
  analogWrite(ENA,carSpeed/speed_Coeff);
  analogWrite(ENB,carSpeed);
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH);
  delay(25);
//  Serial.println("Forward_left");
}

void bright(){
  analogWrite(ENB,carSpeed);
  analogWrite(ENA,carSpeed/speed_Coeff);
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  delay(25);
//  Serial.println("Back_right");
}



void bleft(){
  analogWrite(ENB,carSpeed/speed_Coeff);
  analogWrite(ENA,carSpeed);
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  delay(25);
 // Serial.println("Back_left");
}

void findo(){
  analogWrite(ENA,90);
  analogWrite(ENB,90);
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH);


  delay(25) ;    


 }


void stop(){
  digitalWrite(ENA,LOW);
  digitalWrite(ENB,LOW);
 // Serial.println("Stop!");
}


void play_do(){
  tone(buzzer, 533);
  delay(500);        
  noTone(buzzer);     
}

void play_re(){
  tone(buzzer, 587);
  delay(500);        
  noTone(buzzer); 
}

void play_mi(){
  tone(buzzer, 659);
  delay(500);        
  noTone(buzzer); 
}

void play_fa(){
  tone(buzzer, 698);
  delay(500);        
  noTone(buzzer); 
}

void play_sol(){
  tone(buzzer, 784);
  delay(500);        
  noTone(buzzer); 
}

void play_la(){
  tone(buzzer, 880);
  delay(500);        
  noTone(buzzer); 
}

void play_ci(){
  tone(buzzer, 987);
  delay(500);        
  noTone(buzzer); 
}

Credits

KDPA
5 projects • 19 followers

Comments