I have successfully compiled a sketch that collects and displays an analog temperature, 2 (of 4) DS18B20 sensors, and a digital temperature and humidity output from a DHT11 sensor. All sensor data mirrors on the COM port, but 2 of the DS18B20 fields do not display on ThingSpeak. When I include those fields no data is updated on ThingSpeak. When I comment them out all other data is updated.
The sketch follows:
/*
WriteMultipleSensors
This sketch builds upon V5 by trying to incorporate 2 more DS18B20 sensors for Field 4 and 5
independant of the Field 2 and 3 sensors
This sketch successfully logs 1 analog, 2 DS18B20 signals, and 1 set of DHT11 data.
It doesn't transmit Field 3 and Field 4 from the DS18B20 sensor. Don't know if it is a voltage issue or a
String composition limitation
*/
#include "ThingSpeak.h"
#include <OneWire.h>
#include <SPI.h>
#include <DallasTemperature.h>
#include <DHT.h>
// Use wired ethernet shield
#include <SPI.h>
#include <Ethernet2.h> // Make sure there is a 2 after Ethernet!
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
EthernetClient client;
// Analog Pin setup -
// On Arduino: 0 - 1023 maps to 0 - 5 volts
#define VOLTAGE_MAX 5.0
#define VOLTAGE_MAXCOUNTS 1023.0
// Define DHT11 for room temperature and humidity measurement
#define DHTPIN 4 // what digital pin we're connected to.. Digital Pin 4 in this case
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
// DS1820 Setup.... A oneWire instance to communicate with any OneWire devices
// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3
//#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the addresses of 1-Wire temp sensors.
DeviceAddress HPWH_TempOut = { 0x28, 0x37, 0x08, 0x1E, 0x07, 0x00, 0x00, 0x1F }; // Tested
DeviceAddress HPWH_TempIn = { 0x28, 0x80, 0x8D, 0x1C, 0x07, 0x00, 0x00, 0x83 }; // Tested
DeviceAddress DWH_TempOut = { 0x28, 0x92, 0x38, 0x1D, 0x07, 0x00, 0x00, 0xA4 }; // Not working when DHT11 robs power
DeviceAddress DWH_TempIn = { 0x28, 0xA4, 0xA8, 0x2A, 0x07, 0x00, 0x00, 0x82 }; // Shows at Serial Print but not on ThinkSpeak: maybe voltage problem
unsigned long myChannelNumber = 130737;
const char * myWriteAPIKey = "F0QA9UVAQWWQ0G1E";
void setup() {
// Start Serial for debugging on the Serial Monitor
Serial.begin(9600);
Ethernet.begin(mac);
ThingSpeak.begin(client);
sensors.begin();
// set the resolution to 10 bit (way more than I need)
sensors.setResolution(HPWH_TempOut, 10);
sensors.setResolution(HPWH_TempIn, 10);
sensors.setResolution(DWH_TempOut, 10);
sensors.setResolution(DWH_TempIn, 10);
// Temp debugging of the DHT11 sensor
Serial.println("DHTxx test!");
dht.begin();
}
void loop() {
// Reading DHT11 temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
int h = dht.readHumidity();
int humidity = h * 1.25; // Correction multiplier
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Read the input on each pin, convert the reading, and set each field to be sent to ThingSpeak.
// On Arduino: 0 - 1023 maps to 0 - 5 volts
float pinVoltage = analogRead(A0) * (VOLTAGE_MAX / VOLTAGE_MAXCOUNTS);
float TMP36 = (pinVoltage - 0.5) * 100 * 9 / 5 + 32;
//Print Temperatures
Serial.print ("Getting temperatures...
");
Serial.print("TMP36... Room Temperature....");
Serial.println(TMP36);
sensors.requestTemperatures();
float HPwhTempOut = sensors.getTempF(HPWH_TempOut);
float HPwhTempIn = sensors.getTempF(HPWH_TempIn);
float DWHTempOut = sensors.getTempF(DWH_TempOut);
float DWHTempIn = sensors.getTempF(DWH_TempIn);
Serial.print("Heat Pump Water Temp out is:(Field 2)");
Serial.print(HPwhTempOut);
Serial.print("F: ");
Serial.print("
");
Serial.print("Heat Pump Water Temp in is: (Field 3)");
Serial.print(HPwhTempIn);
Serial.print("F: ");
Serial.print("
");
Serial.print("Water tank Temp out is: (Field 4)");
Serial.print(DWHTempOut);
Serial.print("F: ");
Serial.print("
");
Serial.print("Water tank Temp in is: (Field 5)");
Serial.print(DWHTempIn);
Serial.print("F: ");
Serial.print("
");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %RH");
Serial.print("DHT11 Temperature: ");
Serial.print(f*.9);
Serial.println(" *F\t");
// The following lines of code convert the DHT11 individual values to strings that ThingSpeak can us
String(h,DEC);
String(f,DEC);
/*//The following lines of code convert DS19B20 to a string value that ThingSpeak can use
String(HPwhTempOut,DEC); // ThingSpeak Field 2
String(HPwhTempIn, DEC); // ThingSpeak Field 3
String(DWHTempOut, DEC); // ThingSpeak Field 4
String(DWHTempIn, DEC); // ThingSpeak Field 5
*/
/*char buffer[12];
String tempStr=dtostrf(HPwhTempOut,6,2,buffer);
String tempStr2=dtostrf(HPwhTempIn,6,2,buffer);
String tempStr3=dtostrf(DWHTempOut,6,2,buffer);
*/
ThingSpeak.setField(1,TMP36);
//pinVoltage = analogRead(A1) * (VOLTAGE_MAX / VOLTAGE_MAXCOUNTS);
ThingSpeak.setField(2,HPwhTempOut);
ThingSpeak.setField(3,HPwhTempIn);
//ThingSpeak.setField(4,DWHTempOut);
//ThingSpeak.setField(5,DWHTempIn);
ThingSpeak.setField(6,f);
ThingSpeak.setField(7,humidity);
// pinVoltage = analogRead(A7) * (VOLTAGE_MAX / VOLTAGE_MAXCOUNTS);
//ThingSpeak.setField(8,pinVoltage);
// Write the fields that you've set all at once.
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
delay(20000); // ThingSpeak will only accept updates every 15 seconds.
}