Hi all,
Im new to arduino (got my first this afternoon) and havent touched progamming since QBasic in my early teens way back in the 90s so i appoligise if this is a stupid question.
I intend to make a data logger and then possibly play with a bit of home automation. Anyway after messing around with the examples and watching a couple of youtube videos I wrote/copy and pasted the following to try my dht22 sensors :
#include "DHT.h"
#define DHTPIN_A 2 // what pin we're connected to
#define DHTPIN_B 3
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht1(DHTPIN_A, DHTTYPE);
DHT dht2(DHTPIN_B, DHTTYPE);
void setup() {
// pinMode(led, OUTPUT);
Serial.begin(9600);
Serial.println("DHTxx test!");
dht1.begin();
dht2.begin();
}
String command;
void loop() {
if(Serial.available())
{
char c = Serial.read();
if(c == '\n')
{
parseCommand(command);
command = "";
}
else
{
command += c;
}
}
}
void parseCommand(String com)
{
float h1 = dht1.readHumidity();
float t1 = dht1.readTemperature();
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature();
if(com == "temp")
{
Serial.print("Temperature: ");
Serial.print(t1, 2);
Serial.print("*C\t");
Serial.print(t2, 2);
Serial.println("*C");
} else if(com == "humidity")
{
Serial.print("Humidity: ");
Serial.print(h1, 2);
Serial.print("%\t");
Serial.print(h2, 2);
Serial.println("%");
}
else{
Serial.println(com);
}
}
When used connected to my computer the programme works fine, you type "temp" it returns the two temp readings, "humidity" does the same for the relative humidity. All is good. Except when i try to use my HC-06 bluetooth module the whole thing breaks down. The 'else' case in paseCommand returns whatever you have sent if it isnt a reconised command. I send "temp" i get "temp" back, I send "humidity" i get it echoed back. Infact it'll echo whatever you send at it. I'm lost as to why it works when connected to my laptop but not through bluetooth not connected to the pc. Any Ideas would be much appreciated?