Hello,
I am trying to control a robot remotely via an HC-06 Bluetooth Module and an Arduino Mega 2560. I have tested all of the code via USB and it worked just fine. When I connected via the HC-06, however, the app is not communicating properly. I changed the communication to bluetooth in the app and connected to the module via the bluetooth widget. The app even says that the module is online but my sensor read-outs are not updating on my app panel. Does anyone have any suggestions?
Code is below (note that some of the functions called are not shown as they are in another tab):
/* Comment this out to disable prints and save space */
//#define BLYNK_PRINT Serial1
//Libraries
#include <Servo.h>
#include "IRTemp.h"
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>
//Authorization
//char auth[] = "e18af7a4357043819a84cf9c074e226a"; //Wynelle's Phone
char auth[] = "af30119367fd4b9ea111f78318fd9b14"; //Isabelle's Phone
//UR Pins and Vars
#define trigPin 10
#define echoPin 13
long duration, distance; // Duration used to calculate distance
//IR Pins and Vars
static const byte PIN_DATA = 2; // Choose any pins you like for these
static const byte PIN_CLOCK = 3;
static const byte PIN_ACQUIRE = 4;
static const TempUnit SCALE=FAHRENHEIT; // Options are CELSIUS, FAHRENHEIT
IRTemp irTemp(PIN_ACQUIRE, PIN_CLOCK, PIN_DATA);
float irTemperature, ambientTemperature;
//Alarm Pins and Vars
#define Buzz_PIN 6
int t1;
//Motor Pins and Vars
#define LeftMotorSpeed 5 // Enable Pin for motor 1
#define RightMotorSpeed 7 // Enable Pin for motor 2
//H,L = Forward; L,H = Backward; H,H = Stop
#define I1 8 // Control pin 1 for motor 1
#define I2 11 // Control pin 2 for motor 1
#define I3 12 // Control pin 1 for motor 2
#define I4 22 // Control pin 2 for motor 2
int x=0;
int y=0;
int minRange = 312;
int maxRange = 712;
int minSpeed = 450;
int maxSpeed = 1023;
int noSpeed = 0;
//Servo Variables
int servpos =0;
int servpos_new;
Servo servo;
//Timer Variables
BlynkTimer timer;
//Servo write
BLYNK_WRITE(V3){
servpos_new = param.asInt();
}
//Joystick write
BLYNK_WRITE (V0){
int x1 = param[0].asInt();
x=x1;
int y1 = param[1].asInt();
y=y1;
}
// Enable/disable blinking using virtual pin 4
BLYNK_WRITE(V4)
{
if (param.asInt()) {
timer.enable(t1);
} else {
timer.disable(t1);
digitalWrite(Buzz_PIN, LOW);
}
}
// Change blink interval using virtual pin 5
BLYNK_WRITE(V5){
long interval = param.asLong();
boolean wasEnabled = timer.isEnabled(t1);
timer.deleteTimer(t1);
t1 = timer.setInterval(interval, alarmBlynk);
if (!wasEnabled) {
timer.disable(t1);
}
}
void Ultrasonic_Read(){
Blynk.virtualWrite(8,distance);// virtualpin 8 distance
}
void IR_Read(){
Blynk.virtualWrite(1,irTemperature);// virtualpin 1 ir temperature
}
void Ambient_Read(){
Blynk.virtualWrite(2,ambientTemperature);// virtualpin 2 ambient temperature
}
void setup(){
// Debug console
Serial.begin(9600);
SoftwareSerial SerialBLE(29,31); // RX, TX
SerialBLE.begin(9600);
Blynk.begin(SerialBLE, auth);
Serial.println("Waiting for connections...");
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LeftMotorSpeed, OUTPUT);
pinMode(RightMotorSpeed, OUTPUT);
pinMode(I1, OUTPUT);
pinMode(I2, OUTPUT);
pinMode(I3, OUTPUT);
pinMode(I4, OUTPUT);
pinMode(Buzz_PIN, OUTPUT);
timer.setInterval(1000L, measureDistance);
timer.setInterval(2005L, IR_temp);
timer.setInterval(1000L, Ultrasonic_Read);
timer.setInterval(2010L, IR_Read);
//timer.setInterval(2005L, Ambient_Read);
timer.setInterval(50L, Motor_Control);
//timer.setInterval(500L, Servo_Control);
t1 = timer.setInterval(500L, alarmBlynk);
timer.disable(t1);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates SimpleTimer
}