I'm new to the forum and a Arduino novice.
I am trying to measure 3 temperatures on a UNO prototype board. I have created the code from a number of sources including a running average. The code works when UNO is connected to a PC through a USB cable but it doesn't with bluetooth. I can talk to the bluetooth device, a Sparkfun BlueSMiRF, by calling up the CMD function etc but isn't transferring data.
The code is
const int sensorPin0 = A0;
const int sensorPin1 = A1;
const int sensorPin3 = A2;
const float baselineTemp = 25.0;
#include "RunningAverage.h"
RunningAverage RAT0(10);
RunningAverage RAT1(10);
RunningAverage RAT3(10);
int samples = 0;
#include <SoftwareSerial.h>
int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup(void){
Serial.begin(9600);
Serial.println(FILE);
Serial.print("Version: ");
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
// explicitly start clean
RAT0.clear();
RAT1.clear();
RAT3.clear();
//bluetooth.println("c,90A4DE9DEB95");
delay(1000); // Short delay, wait for the Mate to send back CMD
//bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
bluetooth.begin(9600); // Start bluetooth serial at 9600
bluetooth.print("$$$");
delay(2000);
bluetooth.println("c,90A4DE9DEB95");
delay(1000);
bluetooth.println("U,9600,N");
delay(2000);
bluetooth.println("---");
}
void loop(){
// RAT0.addValue(temperature0);
// RAT1.addValue(temperature1);
// RAT3.addValue(temperature3);
//if(bluetooth.available())
int sensorVal0 = analogRead(sensorPin0);
Serial.print(sensorVal0);
bluetooth.print(sensorVal0);
// convert the ADC reading to voltage
float voltage0 = (sensorVal0/1024.0) * 5;
float temperature0 = (voltage0 - .5) * 100;
Serial.print(", ");
bluetooth.print(", ");
Serial.print(temperature0);
bluetooth.print(temperature0);
RAT0.addValue(temperature0);
Serial.print(", ");
bluetooth.print(", ");
Serial.print(RAT0.getAverage());
bluetooth.print(RAT0.getAverage());
int sensorVal1 = analogRead(sensorPin1);
Serial.print(sensorVal1);
bluetooth.print(sensorVal1);
// convert the ADC reading to voltage
float voltage1 = (sensorVal1/1024.0) * 5;
float temperature1 = (voltage1 - .5) * 100;
Serial.print(", ");
bluetooth.print(", ");
Serial.print(temperature1);
bluetooth.print(temperature1);
RAT1.addValue(temperature1);
Serial.print(", ");
bluetooth.print(", ");
Serial.print(RAT1.getAverage());
bluetooth.print(RAT1.getAverage());
int sensorVal3 = analogRead(sensorPin3);
Serial.print(sensorVal3);
bluetooth.print(sensorVal3);
// convert the ADC reading to voltage
float voltage3 = (sensorVal3/1024.0) * 5;
float temperature3 = (voltage3 - .5) * 100;
Serial.print(", ");
bluetooth.print(", ");
Serial.print(temperature3);
bluetooth.print(temperature3);
RAT3.addValue(temperature3);
Serial.print(", ");
bluetooth.print(", ");
Serial.println(RAT3.getAverage());
bluetooth.print(RAT3.getAverage());
delay(2000);
}