Hello,
I have read through a lot of posts and tried a bunch of things. Still having problems.
I am trying to connect my iphoneX to a HM10 bluetooth to control an Arduino Uno with a motor shield by Osepp.
I have downloaded and installed Blynk library v0.5.4 I can connect my phone to the HM10. And using testing code I can make the motor shield move the motors, just not by my Bluetooth commands.
I am new to coding so likely have that wrong. I am using sliders to send a virtual pin signal. trying to store that virtual pin in an integer. then set my motors to the PWM at the stored integer. The higher my slider goes the faster the motors turn.
Also I noticed that in line 9 of my code the “BlynkSimpleSerialBLE.h” does not turn orange like the rest of my included libraries. So I tried downloading and installing the libraries again. No change.
#include <Blynk.h>
#define BLYNK_PRINT Serial
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "*********";
SoftwareSerial SerialBLE(10, 11); // RX, TX
int pwm_a = 3; //PWM control for motor outputs 1 and 2
int pwm_b = 9; //PWM control for motor outputs 3 and 4
int dir_a = 2; //direction control for motor outputs 1 and 2
int dir_b = 8; //direction control for motor outputs 3 and 4
int far;
int left;
int right;
BLYNK_WRITE(V12) //Button Widget is writing to pin V12
{
int far = param.asInt(); // store V12 in intiger far
}
//int far = V12; // forward and reves are vertural input 12
BLYNK_WRITE(V5) //Button Widget is writing to pin V5
{
int left = param.asInt(); //store V5 as intiger left
}
BLYNK_WRITE(V6) //Button Widget is writing to pin V6
{
int right = param.asInt(); //store v6 as intiger right
}
void setup()
{
// Debug console
Serial.begin(9600);
SerialBLE.begin(9600);
Blynk.begin(SerialBLE, auth);
Serial.println("Waiting for connections...");
pinMode(pwm_a, OUTPUT); //Set control pins to be outputs
pinMode(pwm_b, OUTPUT);
pinMode(dir_a, OUTPUT);
pinMode(dir_b, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Blynk.run();
{
if (far == 1) //if far button is high set the motors to go forward at the speed from the sliders
{
digitalWrite(dir_a, LOW);
digitalWrite(dir_b, LOW);
analogWrite(pwm_a, left);
analogWrite(pwm_b, right);
delay(30);
}else{
digitalWrite(dir_a, HIGH); //if the far button is low set the motors to go backward at the speed from the sliders.
digitalWrite(dir_b, HIGH);
analogWrite(pwm_a, left);
analogWrite(pwm_b, right);
delay(30);
}
}
}