element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Solar Power Devices
  • Challenges & Projects
  • Project14
  • Solar Power Devices
  • More
  • Cancel
Solar Power Devices
Blog Solar SPEC - updated temperature sensor code
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Solar Power Devices to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ralphjy
  • Date Created: 14 Sep 2018 5:25 AM Date Created
  • Views 692 views
  • Likes 4 likes
  • Comments 1 comment
  • solar panel
  • solarpwrdevicesch
  • iot design
Related
Recommended

Solar SPEC - updated temperature sensor code

ralphjy
ralphjy
14 Sep 2018

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.

image

 

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);

}

  • Sign in to reply
  • genebren
    genebren over 6 years ago

    Thermal mass is a problem with a lot of the temperature sensors (more so when the mass of plastic around the sensor is so great).  You can improve the response by circulating air across the sensor, but in reality, the temperature changes in a more natural setting will be far more gradual so that this should not be seen as a problem,

     

    Good luck on your next steps!

    Gene

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube