Hey there,
here's a tutorial of how to plot a real-time graph of values from a micro-controller such as an Arduino to the app. It uses a Bluetooth module such as the HC-05 to act as an messaging device to transmit and receive the data between the Arduino and Android.
The app is simple to use and can be used for other purposes such as a controller to control a robot car, a serial monitor, similar to that of offered by the Arduino IDE, to receive serial messages and send serial data.
ENOUGH CHIT-CHAT LET'S GETS STARTED
#include < SoftwareSerial.h >
// Connect bluetooth module HC-05 or HC-06 to arduino and declare the pins used if you plan on using the software serial
SoftwareSerial mySerial(12, 11);
// Used to identify graphing values
String graphTag = "Graph:";
// Used to identify the separation of values inside the stream
char valueSeparatorCharacter = '&';
// Used to identify the end of the stream. This will apply for both the serial monitor and graph
char terminationSeparatorCharacter = '$';
void setup() {
// Declare the baud rate. The app only supports 9600
mySerial.begin(9600);
}
void loop() {
// An example loop of plotting a sine wave
for (float x = -2 * PI; x <= 2 * PI; x = x + PI / 50) {
mySerial.print(graphTag);
mySerial.print(240 * sin(x));
mySerial.print(valueSeparatorCharacter);
mySerial.print(240 * sin(x + (2 * PI / 3)));
mySerial.print(valueSeparatorCharacter);
mySerial.print(240 * sin(x + (4 * PI / 3)));
mySerial.print(terminationSeparatorCharacter);
}
}
#include < SoftwareSerial.h >
SoftwareSerial mySerial(12,11); // Like usual set upp the tx and rx pins
void setup() {
// Baud rate of the bluetooth module has to be set to 9600 to communicate with the app
mySerial.begin(9600);
// Can be set to whatever baud rate you want
Serial.begin(9600);
}
void loop() {
if(mySerial.available()>0){
// Upon receiving data read string upto new line
String inputString = mySerial.readStringUntil('\n'); // Read input upto new line
// Print string
Serial.println(inputString);
}
}
If you are finding difficulties, please follow the above video tutorial