Bluetooth motor control IOS

Hi Guys,
As part of a HSC Major Work, I need a component consisting of a bluetooth activated motor to open a lid. So far I am working with a Arduino Uno, Motor Servo Controller module and a bluetooth V.40 BLE. I have found an Arduino compatible app BLExAR on IOS, in which I can establish a connection between. Here u can control both analog and digital pins, view data on a graph and send and receive messages (called TX Characteristics). So basically I need code that will allow me to turn on and off the motor via the BLExaR app. Hope someone can help!! Cheers Max

Current code for motor:

#include <AFMotor.h>

AF_DCMotor Motor1(3);

void setup(){
// Open serial port
Serial.begin(9600);

}

void loop()
{
Motor1.setSpeed(255);
Motor1.run(FORWARD);
delay(2000);
Motor1.run(BACKWARD);
delay(2000);
Motor1.run(FORWARD);
delay(2000);
Motor1.run(BACKWARD);
delay(2000);
Motor1.setSpeed(0);
Motor1.run(BRAKE);
delay(1000);
}

Bluetooth Message code:

#include <SoftwareSerial.h>

SoftwareSerial ble(2, 3); // RX, TX

void setup(){
// Open serial port
Serial.begin(9600);
// begin bluetooth serial port communication
ble.begin(9600);
}


void loop()
{
Serial.println("Sending Bluetooth Message...");
ble.write("hello max");
delay(2000);
}
So, if you run your "Bluetooth Message code:" sample code on your Arduino, do you see either of

- "Sending Bluetooth Message..." in some kind of terminal within your Arduino development IDE
- "hello max" in the BLExAR app?

I guess at some point, you could try ble.read() to try and get some data back from your app.

Hi Salem,

Yes I do receive a message on my app saying "hello max" and from there I can change the frequency of the message sending.

What do you mean by sending a 'ble.read()', is this a function to tell the motor what to do??

cheers
Well the next thing to try is sending a message from your phone to the Arduino.

I would have thought that the example where you found
ble.write("hello max");
would also show an example of how to receive information.

From which you might deduce
1
2
3
4
5
6
7
8
response = ble.read();
if ( response == ? ) {
  Motor1.setSpeed(255);
  Motor1.run(FORWARD);
  delay(2000);
  Motor1.setSpeed(0); 
  Motor1.run(BRAKE);
}
Thankyou for your response.

I still unfortunately don't know exactly what you are talking about. When I paste this code it comes up with an error message for 'response'. Do I have to put my own 'response' in there.

I am still very much a beginner so this is greatly appreciated. Just from the information I've given you could you possibly try and piece something together for me and I could work around with it once you send it.
cheers!!
> response = ble.read();
This is an abstract idea which you need to make concrete by reading the manual pages.
https://www.arduino.cc/en/Reference/SoftwareSerialRead

> Do I have to put my own 'response' in there.
It's up to you to comprehend the idea, and make the result syntactically valid for the compiler.

> Just from the information I've given you could you possibly try and piece something
> together for me and I could work around with it once you send it.
That was my last post, but you still came back for more anyway.
Topic archived. No new replies allowed.