Skip to content

Instantly share code, notes, and snippets.

@lithiumhead
Created November 11, 2015 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lithiumhead/6d7b93819462319412bb to your computer and use it in GitHub Desktop.
Save lithiumhead/6d7b93819462319412bb to your computer and use it in GitHub Desktop.
Code for Particle Core/Photon to upload readings from SHT11 to Thingspeak.com
#define PARTICLE_PHOTON
#include "ThingSpeak/ThingSpeak.h"
#include "SHT1x/SHT1x.h"
//ThingSpeak.com configurations:
TCPClient client;
unsigned long myChannelNumber = REPLACE_WITH_YOUR_CHANNEL_NUMBER;
const char * myWriteAPIKey = "REPLACE_WITH_YOUR_API_KEY";
// Channel 1 is Temperature (deg C)
// Channel 2 is Humidity (%)
//SHT11 Configuration:
#define dataPin D0
#define clockPin D1
SHT1x sht1x(dataPin, clockPin);
void setup() {
ThingSpeak.begin(client);
}
void loop() {
float temp_c;
float humidity;
temp_c = sht1x.readTemperatureC();
humidity = sht1x.readHumidity();
ThingSpeak.setField(1,temp_c);
ThingSpeak.setField(2,humidity);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
delay(20000); // ThingSpeak will only accept updates every 15 seconds.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment