A
Arduino2mo ago
Ben

New to arduino, my bluetooth code keeps breaking after a bit, also would like to improve efficiency

Hi! I have never intensely worked with arduino, but I'm currently working on a project to turn on a vinyl player remotely via a servo and an iphone app + bluetooth, as the person I'm working on it for has MS. I followed a youtube tutorial to get code that works, but after a second it tends to break, though the amount of time and actions that cause it to break are not reliable. Additionally, since it's a battery powered device (2x 14500 in series stepped down to 5v) I'd love pointers on how to avoid draining the batteries excessively. Thanks for checking this out!
6 Replies
Ben
BenOP2mo ago
#include <SoftwareSerial.h>
#include <Servo.h>
Servo myServo;
SoftwareSerial softSerial(2, 3); // RX, TX

char appData;
String inData = "";

void setup()
{
Serial.begin(9600);
Serial.print("Sketch: "); Serial.println(__FILE__);
Serial.print("Uploaded: "); Serial.println(__DATE__);

softSerial.begin(9600);
Serial.println("softSerial started at 9600");

Serial.println("Set line endings to 'Both NL & CR'");
myServo.attach(9);
}

void loop()
{
// Read from the UART module and send to the Serial Monitor
softSerial.listen(); // listen the HM10 port

while (softSerial.available() > 0) { // if HM10 sends something then read

appData = softSerial.read();

inData = String(appData); // save the data in string format

Serial.write(appData);

}
if (Serial.available()) { // Read user input if available.

delay(10);

softSerial.write(Serial.read());

}
if (inData == "U") {
Serial.write("To Far");
myServo.write(180);
delay(500);
}
if (inData == "M") {
Serial.write("To Middle");
myServo.write(90);
delay(500);
}
if (inData == "D"){
Serial.write("To Zero");
myServo.write(0);
delay(500);
}

} // void loop()
#include <SoftwareSerial.h>
#include <Servo.h>
Servo myServo;
SoftwareSerial softSerial(2, 3); // RX, TX

char appData;
String inData = "";

void setup()
{
Serial.begin(9600);
Serial.print("Sketch: "); Serial.println(__FILE__);
Serial.print("Uploaded: "); Serial.println(__DATE__);

softSerial.begin(9600);
Serial.println("softSerial started at 9600");

Serial.println("Set line endings to 'Both NL & CR'");
myServo.attach(9);
}

void loop()
{
// Read from the UART module and send to the Serial Monitor
softSerial.listen(); // listen the HM10 port

while (softSerial.available() > 0) { // if HM10 sends something then read

appData = softSerial.read();

inData = String(appData); // save the data in string format

Serial.write(appData);

}
if (Serial.available()) { // Read user input if available.

delay(10);

softSerial.write(Serial.read());

}
if (inData == "U") {
Serial.write("To Far");
myServo.write(180);
delay(500);
}
if (inData == "M") {
Serial.write("To Middle");
myServo.write(90);
delay(500);
}
if (inData == "D"){
Serial.write("To Zero");
myServo.write(0);
delay(500);
}

} // void loop()
hmm, it does actually seem to break most often when sent to zero i'll send some serial monitor output in a sec
Ben
BenOP2mo ago
No description
Ben
BenOP2mo ago
this is the tutorial I followed https://www.youtube.com/watch?v=SosEZTOwPD0
MYBOTIC
YouTube
Tutorial: How to use HM-10 BLE Module with Arduino to control an LE...
This small size Bluetooth 4.0 TTL transceiver module allows your target device communicate with, your IPhone/iPAD, IOS 6 or Android 4.3 above devices, It's easy to use and completely encapsulated, you can set it as slave or master, you can use AT command set the baudrate. Website: https://www.mybotic.com.my/ Facebook: https://www.facebook.com/...
Ben
BenOP2mo ago
occasionally it seems to reset, could that be because of overdrawing current? the power is 2x 14500s sent through a basic 5v step down to power the nano, servo, and hm-10 in parallel the servo is an aliexpress sg90 actually addendum it breaks the most when moving furthest from whatever i press first if it is because of overloading, is there anything I can do? nothing feels hot
Ben
BenOP2mo ago
Wiring
No description
Ben
BenOP2mo ago
No description

Did you find this page helpful?