Hello!
I made an arduino based remote for my electric skateboard. I am using two hc-05 for communication between receiver and transmitter. The reason to have an arduino on each end is to add additional features later such as controlling lights. I used simple rf transmitters and receivers in the past, but it seems to get interference at certain places outside. The hc-05 has problems as well. I am getting a few second delay after a while, which is fixed by resetting the arduino. I think it’s something related to losing connection and building some kind of buffer, but i’m not sure. Anyway, if anybody has experienced this before, I would love some advice.
Transmitter
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
int pot=A0;
int val=0;
void setup()
{
BTserial.begin(9600);
}
void loop()
{
val=map(analogRead(pot),0,1048,0,255);
BTserial.write(val);
delay(80);
}
Receiver
#include <Servo.h>
int val = 0;
Servo esc;
int throttle = 0;
int i = 0;
void setup()
{
Serial.begin(9600);
esc.attach(5);
}
void loop()
{
if (Serial.available())
{
i = 0;
val = Serial.read();
throttle = map(val, 26, 105, 1000, 2000);
}
else {
i += 1;
}
if (i > 3) { //failsafe
throttle = 1000;
}
if (throttle < 1000) {
throttle = 1000;
}
if (throttle > 2000) {
throttle = 2000;
}
esc.write(throttle);
delay(80);
}