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?
#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);
}
}
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?
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?
#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();
}
}
}