I'm very new to coding with arduino so please excuse my naivety, For an electronics assignment I am making a servo turn back and forth using a HM10 BLE however each time I press a button that sends '0' or '1' to the serial it also sends '200, '0' (being whatever i pressed), 250' all on different lines, so the servo tries turning to 200, 0, then 150 in a quick burst, making it spas out for a split second.

Is there any way i can get rid of the 200 and 250 in the serial or somehow make it only send the '0' or '1'

This is my code so far if needed:

Servo x;
int bttx=9;    //tx of bluetooth module is connected to pin 9 of arduino
int btrx=10;    //rx of bluetooth module is connected to pin 10 of arduino
SoftwareSerial bluetooth(bttx,btrx); //defines bluetooth as a dim and reads tx and rx from above

void setup()
  x.attach(11);        // servo is connected to pin 11 of arduino
void loop()
  if(bluetooth.available()>0)    //if bluetooth module is transmitting data
    int pos=bluetooth.read(); // store the data in pos variable

Thankyou for the help and sorry again for the inconvenience, as I said I am only about a week into arduino :) anything helps

  • Sounds like the sending code on your smartphone isn't working correctly. You will have to fix that. As a workaround, if this sequence of bytes is always the same, you can read the whole sequence from the buffer, and only then set the servo to the desired position. – chrisl Aug 13 '19 at 6:09
  • I agree with crisl, you should look at how your bluetooth signal is generated. Another good practice is to filter your input signal, not send it straight through to an output. In your case that could be as simple as "if I get anything other than a 0 or a 1, discard and don't use it as a position". – ChrisH Aug 13 '19 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.