BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

HM10 to arduino Uno to run a motor shield

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);
   }
  
 }

}

The colour coding is an IDE thing that relates to whether the library is locally embedded or something?? I can’t remember… Google it :stuck_out_tongue_winking_eye: Anyhow, it is irrelevant to it’s general operation, so nothing to worry about.

You need to change how your code fits… use Blynk functions like BLYNK_WRITE() to contain the slider info and the motor commands.

Search this forum for keywords like Car, Rover, Motor, etc. to see how others have done it. Whether WiFi or BT/BLE, the process is the same.

Here is a basic H-bridge controlled rover I made ages ago and converted to Blynk control…

Also, do not not dump all your code in the void loop() as that is not good for the Blynk timing.

Thank you very much Gunner. Both links were very helpful. I have reorganized. :grinning:

After googling I found that the included library not lighting up in the code is a problem. It means that the sketch tool can not see the library. I found an article here that talks about adding it the the keyword text.

http://forum.arduino.cc/index.php?topic=199491.0

I have tried adding it, but not sure if it is a keyword 1 or keyword 2 or if where I add it make a difference. Anyone familer with the BlynkSimpleSerialBLE.h not being found by Arduino sketch tool?

Again, it is NOT a real problem :slight_smile: It is just referring to whether that library is included in some keyword file… not if the sketch can find the library or not. If the library is not found or valid, then the sketch will not compile.

Here is another explanation about it…

https://forum.arduino.cc/index.php?topic=329092.0

The video article I was referring to (and still can’t find) was about how to make your own library of common code that you might use in multiple sketches… then instead of always duplicating code, simple refer to your library. It was mentioned then you can add in that library to your keyword list… again, not necessary, but potentially helpful for organisation or something.