Hi there,
I am looking for code to add to my sketch that switches of the esc when bluetooth is out of range or i switch bluetooth off.
Thanks so much
Hi there,
I am looking for code to add to my sketch that switches of the esc when bluetooth is out of range or i switch bluetooth off.
Thanks so much
How do you plan to determine that the bluetooth device on the other end is off or out of range?
I recommend that whatever sends data via Bluetooth does so at regular intervals. The receiving device will then know that if a message is not received at the right time it should shut down the ESC.
As you have told us almost nothing about your project I can't be more specific.
...R
Just trying to switch of my motor on my skateboard. It has a arduino board with a HC-06 module. I am using a android phone to control the speed, here is the Sketch.
#define MOTOR_PIN 9
int _pulseTime = 0; //microseconds
boolean _highSpeed = true;
void setup()
{
Serial.begin(9600);
pinMode(9, OUTPUT);
digitalWrite(9, LOW);
Serial.println("Enter 0-8 to adjust motor speed.");
Serial.println("Enter h or l to change the speed range.");
}
void loop()
{
static int timing[] = {1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500, 1550, 1600, 1650, 1700, 1750, 1800, 1850, 1900, 1950, 2000 };
// Pulse servo
digitalWrite(9, HIGH);
delayMicroseconds(_pulseTime);
digitalWrite(9, LOW);
int incomingByte = 0;
if (Serial.available() > 0)
{
incomingByte = Serial.read();
int index = incomingByte - 48;
if (index >= 0 && index < sizeof(timing) / sizeof(int))
{
setTimingParams(timing[index]);
Serial.print("Throttle: ");
Serial.print((_pulseTime - 1100) / 8);
Serial.println("%");
}
else
{
if (incomingByte == 'h')
{
_highSpeed = true;
}
else if (incomingByte == 'l')
{
_highSpeed = false;
}
}
}
// OFF time
delay(20);
}
void setTimingParams(int newPulseTimeVal) {
if (_highSpeed) {
_pulseTime = newPulseTimeVal;
}
else {
_pulseTime = 1025 + (newPulseTimeVal / 10);
}
}
Maybe this will help you help me
Maybe this will help you help me
No. The device on the other end of the connection must periodically send something that tells the Arduino that it is still alive.
The Arduino needs to read that something, and reset a "last time I heard from the boss" variable when it gets the "Boss here" message.
Periodically, it needs to check how long it has been since it heard from the boss. If it is too long, it needs to ram the speed up to max. Or stop.
Is your "boss" capable of sending that "Boss here" message periodically (at least as often as needed to keep the Arduino happy)?