Hardware Reference
In-Depth Information
If that's the case, we will read out the content of this command. This is simply done using
the following line of code:
byte c = Serial.read ();
If we receive a measurement command, simply denoted as m , we proceed further in the
sketch:
if (c == 'm'){
The first thing we do when the measure command is received is to measure the data from
the DHT sensor:
float h = dht.readHumidity();
float t = dht.readTemperature();
Note that if you are using another sensor or two different sensors, this is where you have
to do your own measurements.
Then, we want to return some data to the serial port. For this project, we'll use a very
simple protocol and return the data in the format temperature,humidity . This is
done by printing these values on the serial port:
Serial.print(t);
Serial.print(",");
Serial.println(h);
This means that if Arduino receives the correct character, the measurements will be re-
turned to the computer via the Bluetooth module.
Note
The complete Arduino sketch is available on the GitHub repository of the project at the
following web page:
https://github.com/openhomeautomation/arduino-home-automation/tree/master/chapter3
Search WWH ::




Custom Search