Control PikaBot Using a Phone Through Bluetooth

Introduction

Have you tried to program PikaBot:
✅ Simple Movement
✅ Follow the line
✅ Avoid Obstacles

If you have done that, you can now challenge yourself to control PikaBot using a phone.💪🏼💪🏼

Video

Watch this video for more info on how to Control Pikabot using a phone through bluetooth.

This is the hardware connection and the components needed.

Sample Code

This is the sample code used for this project.

#include "CytronMotorDriver.h"
CytronMD motorLeft(PWM_PWM, 11, 10);
CytronMD motorRight(PWM_PWM, 9, 3);
#define BT_TX 6
#define BT_RX 7
#include "SoftwareSerial.h"
SoftwareSerial BTSerial(BT_TX, BT_RX); // Maker UNO RX, TX
#define BUTTON 2
#define NOTE_G4 392
#define NOTE_C5 523
#define NOTE_G5 784
#define NOTE_C6 1047
int btConnect[] = {NOTE_G5, NOTE_C6};
int btConnectNoteDurations[] = {12, 8};
#define playBtConnectMelody() playMelody(btConnect, btConnectNoteDurations, 2)
boolean BTConnect = false;
char inChar;
void robotStop() {
motorLeft.setSpeed(0);
motorRight.setSpeed(0);
}
void robotMove(int speedLeft, int speedRight) {
motorLeft.setSpeed(speedLeft);
motorRight.setSpeed(speedRight);
}
void setup()
{
pinMode(BUTTON, INPUT_PULLUP);
Serial.begin(9600);
BTSerial.begin(9600);
delay(1000);
}
void loop()
{
inChar = 'S';
if (BTSerial.available()) {
inChar = BTSerial.read();
Serial.println(inChar);
}
if (inChar == 'F') {
robotMove(200, 200); //forward
delay(1000);
}
else if (inChar == 'B') {
robotMove(-200, –200); //reverse
delay(1000);
}
else if (inChar == 'L') {
robotMove(-200, 200); //left
delay(1000);
}
else if (inChar == 'R') {
robotMove(200, –200); //right
delay(1000);
}
else if (inChar == 'S') {
robotStop();
}
}

Thank you

Thank you for reading this tutorial and we hope it helps your project development. If you have any technical inquiries, please post at Cytron Technical Forum.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

Raspberry Pi Pico VS Arduino MKRZero
Raspberry Pi Pico VS Teensy LC
A New Challenger in MCU Platform – Raspberry Pi Pico
Raspberry Pi Pico VS Arduino UNO
Raspberry Pi Pico VS micro:bit V2
Scroll to Top