I've updated the 8266 program to change the temperature sensor from the DHT22 to the 18B20.  It was a straightforward change using the OneWire and DallasTemperature libraries.  Initially nothing was working, but then I realized that I had forgotten to add the pullup resistor on the Data line (not required on the DHT22).  Added a 4.7K resistor to 3.3V and everything started working.

 

Here is my test plot from ThingSpeak.  I held the temperature probe between my fingers and then released it.  It seems the thermal mass of the probe housing gives it a bit of a time constant in the response.

18B20 test

 

I also updated the program to correct the offset in the irradiance equation.  I won't update the sample time until I finish testing.  The program is pretty simple because I have not included the temperature compensation or any power management.  That's the next phase of the project.

 

Here is the Arduino IDE code:

 

/**

* Solar SPEC - Temperature and Solar Cell Voltage Logger

* Author: Ralph Yamamoto

* Date: September 13, 2018

*

* Log temperature and voltage data to a channel on

* thingspeak.com once every 20 seconds.

*

* Connections:

*    Thing   |  18B20

*   ---------|---------

*      3V3   | Red (VDD)

*        4     | Yellow (DATA)

*      GND  | Black (GND)

*     

*   A/D is measuring a scaled voltage from a solar cell with a 160mA load @ 2V.

*

* Development environment specifics:

*  Arduino IDE v1.8.4

*  Distributed as-is; no warranty is given. 

*/

 

#include <ESP8266WiFi.h>

#include <OneWire.h>

#include <DallasTemperature.h>

#include "ThingSpeak.h"

#define ONE_WIRE_BUS 4 // Data wire is plugged into pin 4 on the 8266 Thing

 

OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices

DallasTemperature sensors(&oneWire); // Pass oneWire reference to Dallas Temperature.

 

// WiFi and Channel parameters

const char WIFI_SSID[] = "XXXXXXX";

const char WIFI_PSK[] = "XXXXXXX";

unsigned long CHANNEL_ID = XXXXXXX;

const char * WRITE_API_KEY = "XXXXXXX";

 

// Pin definitions

const int LED_PIN = 5;

const int ANALOG_PIN = A0; // The only analog pin on the Thing

 

// Global variables

WiFiClient client;

 

void setup() {

 

  // Set up LED for debugging

  pinMode(LED_PIN, OUTPUT);

 

  // Connect to WiFi

  connectWiFi();

 

  // Initialize connection to ThingSpeak

  ThingSpeak.begin(client);

 

}

 

void loop() {

 

  // Flash LED to show that we're sampling

  digitalWrite(LED_PIN, LOW);

 

//Read the temperature from DS18B20

  sensors.requestTemperatures();

  float h = (sensors.getTempCByIndex(0));

  float temp_f = (DallasTemperature::toFahrenheit(h));

 

//Read the irradiance from the A/D

  float ADCount = analogRead(ANALOG_PIN);

  float cellVoltage = ADCount/1023;

  float irradiance = 2.46*ADCount -220;

 

  if (irradiance < 0)

  {

    irradiance = 0;

  }

 

  // Write the values to our ThingSpeak channel

  ThingSpeak.setField(1, temp_f);

  ThingSpeak.setField(2, irradiance);

  ThingSpeak.writeFields(CHANNEL_ID, WRITE_API_KEY);

 

  // Turn LED off when we've posted the data

  digitalWrite(LED_PIN, HIGH);

 

  // ThingSpeak will only accept updates every 15 seconds

  delay(20000);

}

 

// Attempt to connect to WiFi

void connectWiFi() {

 

  byte led_status = 0;

 

  // Set WiFi mode to station (client)

  WiFi.mode(WIFI_STA);

 

  // Initiate connection with SSID and PSK

  WiFi.begin(WIFI_SSID, WIFI_PSK);

 

  // Blink LED while we wait for WiFi connection

  while ( WiFi.status() != WL_CONNECTED ) {

    digitalWrite(LED_PIN, led_status);

    led_status ^= 0x01;

    delay(100);

  }

 

  // Turn LED off when we are connected

  digitalWrite(LED_PIN, HIGH);

}