Hi, I'm new to electronics and everything Arduino related, but I have made a device that detects movement with an accelerometer and an Arduino Micro which then should send the data(what it reads from the accelerometer) via Bluetooth to my phone. For some reason it doesn't do the last part (sending the data to my phone). I'm using the Serial Bluetooth Monitor by Kai Morich, and the module connection works fine with the phone. The serial monitor part of the code also works fine(in that it prints the data). Any ideas, what the problem is?
#include <SoftwareSerial.h> // this is for BT
SoftwareSerial Bluetooth(2,3); // this is for BT PINS: 2,3
String device_name = "ShockCheck";
char c = ' '; // this is for BT stores response of BT
const char *pin = "1234";
const int groundpin = A1; // analog input pin 4 -- ground
const int powerpin = A0; // analog input pin 5 -- voltage
const int zpin = A2; // z-axis (only on 3-axis models)
const int ypin = A3; // y-axis
const int xpin = A4; // x-axis of the accelerometer
const int led1Pin = 4 ;
const int led2Pin = 5;
const int MeasurableDifference = 100;
int previousValue = 0;
int currentValue = 0;
void setup() {
Serial.begin(9600);
Serial.begin(9600);
// Serial.begin(device_name); THIS IS FOR LATER TO NAME THE DEVICE
Serial.println("ready"); // this is for BT
Bluetooth.begin(38400); // this is for BT
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
#ifdef USE_PIN
SerialBT.setPin(pin);
Serial.println("Using PIN");
#endif
previousValue = analogRead(zpin);
}
void loop() {
if (Bluetooth.available())
{
c=Bluetooth.read();
Serial.write(c);
}
if(Serial.available())
{
c= Serial.read();
Bluetooth.write(c);
}
currentValue = analogRead(zpin);
int difference = abs(currentValue - previousValue);
Serial.print(difference);
Serial.print("\t");
if (difference > MeasurableDifference) {
digitalWrite(led1Pin, HIGH);
if (difference > MeasurableDifference + 50) {
digitalWrite(led2Pin, HIGH);
}
}
else {
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
}
previousValue = currentValue;
Bluetooth.print(analogRead(xpin)); //THIS IS THE PART I AM INTERESTED IN
Serial.print(analogRead(xpin));
Bluetooth.print("\t");
Serial.print("\t");
Bluetooth.print(analogRead(ypin));
Serial.print(analogRead(ypin));
Bluetooth.print("\t");
Serial.print("\t");
Bluetooth.print(analogRead(zpin));
Serial.print(analogRead(zpin));
Bluetooth.println();
Serial.println();
delay(2000);
}