I am trying to get a simple Bluetooth car working but I can’t seem to get the arduino101 to connect with my iPhone. The name shows up on the ble list but just will not connect.
This is the code:
#include <BlynkSimpleCurieBLE.h>
#include <CurieBLE.h>
char auth[] = "zYM2d4iJywPkD-pSL_KS80oJDebdToB-";
BLEPeripheral blePeripheral;
const int DIR_A1 = 7;
const int DIR_B1 = 6;
const int PWM1 = 8;
const int DIR_A2 = 5;
const int DIR_B2 = 4;
const int PWM2 = 3;
//const int luz = 13;
int throttle=0,steer=0,temp=0;
//bool cambio=LOW;
byte random1;
const byte pin1=10,pin2=11,pin3=12,pin4=13;
long currentMillis;
long previousMillis = 0;
bool estado=LOW;
int val = 0;
int left = throttle + steer;
int right = throttle - steer;
int Maxleft = min(left, 255);
int Maxright = min(right, 255);
int Minleft = max(left, -255);
int Minright = max(right, -255);
BLYNK_WRITE(V1)
{
throttle = param[1].asInt(); // assigning incoming value from pin V1 to a variable
}
BLYNK_WRITE(V2)
{
steer = param[0].asInt(); // assigning incoming value from pin V1 to a variable
}
BLYNK_READ(V3)
{
Blynk.virtualWrite(V3, val); // assigning incoming value from pin V1 to a variable
}
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(DIR_A1, OUTPUT);
pinMode(DIR_B1, OUTPUT);
pinMode(PWM1, OUTPUT);
pinMode(DIR_A2, OUTPUT);
pinMode(DIR_B2, OUTPUT);
pinMode(PWM2, OUTPUT);
// pinMode(luz, OUTPUT);
pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
pinMode(pin3,OUTPUT);
pinMode(pin4,OUTPUT);
delay(1000);
blePeripheral.setLocalName("Vacuum");
blePeripheral.setDeviceName("Vacuum");
blePeripheral.setAppearance(384);
Blynk.begin(blePeripheral, auth);
blePeripheral.begin();
Serial.println("Waiting for connections...");
}
void loop()
{
blePeripheral.poll();
Blynk.run();
// digitalWrite(luz, HIGH);
if(throttle > 0)
{
digitalWrite(DIR_A1, LOW);
digitalWrite(DIR_B1, HIGH);
digitalWrite(DIR_A2, LOW);
digitalWrite(DIR_B2, HIGH);
analogWrite(PWM1, Maxleft);
analogWrite(PWM2, Maxright);
}
else if(throttle < 0)
{
// cambio=HIGH;
digitalWrite(DIR_A1, HIGH);
digitalWrite(DIR_B1, LOW);
digitalWrite(DIR_A2, HIGH);
digitalWrite(DIR_B2, LOW);
analogWrite(PWM1, Minleft);
analogWrite(PWM2, Minright);
}
else if(throttle==0 && steer==0)
{
digitalWrite(DIR_A1, HIGH);
digitalWrite(DIR_B1, LOW);
digitalWrite(DIR_A2, HIGH);
digitalWrite(DIR_B2, LOW);
analogWrite(PWM1, 0);
analogWrite(PWM2, 0);
}
}```