When I try to send my string and I verify it on arduino it won't pass any of the if statements. device.send() is a method that i am using from an asset package called Android & Microcontrollers / Bluetooth by Tech Tweaking. How can I send a string from my Unity C# Android app to my arduino and pass the if statements?
Unity C# code
device.send (System.Text.Encoding.ASCII.GetBytes("0,0"));
Arduino code
#include <Wire.h>
#include <Adafruit_MotorShield.h>
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
#include <SoftwareSerial.h>
SoftwareSerial Bluetooth(10, 9); // RX, TX
//int LED = 13; // the on-board LED
String Data; // the data received
int LED = 12; // LED on bread board
int height;
void setup() {
Bluetooth.begin(38400);
Serial.begin(38400);
Serial.println("Waiting for command...");
Bluetooth.println("Send 1 to turn on the LED. Send 0 to turn Off");
pinMode(LED,OUTPUT);
AFMS.begin(); // create with the default frequency 1.6KHz
myMotor->setSpeed(100); // 10 rpm
}
void loop() {
if (Bluetooth.available()){ //wait for data received
Data=Bluetooth.read();
if(Data == "0,1"){
digitalWrite(LED,1);
Serial.println("LED On!");
Bluetooth.println("LED On!");
Serial.println("Single coil steps");
myMotor->step(500, FORWARD, SINGLE);
}
else if(Data == "0,0"){
digitalWrite(LED,0);
Serial.println("LED Off!");
Bluetooth.println("LED Off!");
myMotor->step(500, BACKWARD, SINGLE);
}
else{;}
delay(100);
}