Instantly share code, notes, and snippets.

Embed
What would you like to do?
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