Motor controller app to Arduino

Hi all, i have used MIT app 2 developer to make an app to control a motor, the app works fine. I have used a HC-05 Bluetooth module and they are connecting fine.
The problem i encountered is when I read from the serial monitor using println every second line is a zero.
the position on the slider is numbered 0-255, and will be printed on the serial monitor as it is on my android phone. But like i said every second line is a zero.

I'm not sure about the baud rate, the data sheet says that it is preset to 38400 but when I run at that I get random numbers in the serial monitor. I have set it to 9600 and all the numbers come out when they should except for the zeros which are showing up, in other words if the zeros were not there it would be exactly what the phone is transmitting via Bluetooth, as the phone displays these numbers on its screen as the slider bar is moved right or left.

Anyone have an idea to whats going on?

MIT app 2 pic.jpg

#include <SoftwareSerial.h>

int ledPin = 6;
int RX = 11;
int TX = 10;
SoftwareSerial bluetooth(RX,TX);
int state = 0;


void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600); 
  bluetooth.begin(9600);
  
}
void loop() {
  if (bluetooth.available() > 0) { // Checks whether data is comming from the serial port
    state = bluetooth.read(); // Reads the data from the serial port
    analogWrite (ledPin, state);
    Serial.println (state); //analogWrite (ledPin, state);
    
  }
}

MIT app 2 pic.jpg

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

Hi Tom

Sorry about that i haven't been on here for awhile and I was trying to remember how to post a pic :o
I can do one on proteus and take a screenshot if that is ok?

Hi,
I haven't used Bluetooth much, but check if you are sending a carriage return or new line character from your phone when you hit the send button.

Tom... :slight_smile:
PS Screen shot was okay, you should be able to export a jpg file directly from the CAD.

since every send you only need 8 bits Try Clearing your serial buffer between reads
See added line:

    while(bluetooth.available() > 0) {
       bluetooth.read();
    }
#include <SoftwareSerial.h>

int ledPin = 6;
int RX = 11;
int TX = 10;
SoftwareSerial bluetooth(RX,TX);
int state = 0;


void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  bluetooth.begin(9600);
  
}
void loop() {
  if (bluetooth.available() > 0) { // Checks whether data is comming from the serial port
    state = bluetooth.read(); // Reads the data from the serial port
    analogWrite (ledPin, state);
    Serial.println (state); //analogWrite (ledPin, state);
    while(bluetooth.available() > 0) {
       bluetooth.read();
    }
  }
}

Z

Thanks guys, I’ll try that at the weekend, tied up with work all week