Hello,
I am trying to make a remote control for my electronic longboard using a bluetooth module HC06, and app inventor. I success in making a code, however it is not secured, if I loose the bluetooth connexion the skate will continue to run. That is why I tried other things. I change the app, and ask it to send every second the value of the speed, and made this code :
#include <SoftwareSerial.h>
#include <Servo.h>
#define bluetoothTx 10
#define bluetoothRx 11
SoftwareSerial HC06(bluetoothTx,bluetoothRx);
Servo mot;
int t1 = 0;
int t2;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
HC06.begin(9600);
mot.attach(6);
mot.write(0);
}
void loop() {
// put your main code here, to run repeatedly:
if (HC06.available()>0)
{
t1 = millis();
Serial.println( 5 * HC06.read());
mot.write( 5 * HC06.read());
delay(1005); //motor will continue to run for a second until a new data
t2 = millis();
//Serial.println ( t2 - t1);
}
else
{
mot.write(0);
}
The speed of the motor doesn't even math what I have ordered him.
Does anyone have an idea why it doesn't work ? Or how I can fix it ?