Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iampaulidrobo/32a9bc03d9a2c429ff47158251dd9012 to your computer and use it in GitHub Desktop.
Save iampaulidrobo/32a9bc03d9a2c429ff47158251dd9012 to your computer and use it in GitHub Desktop.
Adafruit MQTT,DATA visuals,Temperature
//Code by PIYUSH TAILOR
#include "config.h"
float tempC;
int reading;
int tempPin = 0;
/************************ Example Starts Here *******************************/
// pin connected to DH22 data line
#define DATA_PIN 13
// create DHT22 instance
// set up the 'temperature' and 'humidity' feeds
AdafruitIO_Feed *temperature = io.feed("temperature");
void setup() {
// start the serial connection
Serial.begin(115200);
// wait for serial monitor to open
while(! Serial);
// initialize dht22
// connect to io.adafruit.com
Serial.print("Connecting to Adafruit IO");
io.connect();
// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
// we are connected
Serial.println();
Serial.println(io.statusText());
}
void loop() {
reading = analogRead(tempPin);
tempC = reading / 9.31;
Serial.println(tempC);
delay(1000);
// io.run(); is required for all sketches.
// it should always be present at the top of your loop
// function. it keeps the client connected to
// io.adafruit.com, and processes any incoming data.
io.run();
// save fahrenheit (or celsius) to Adafruit IO
temperature->save(tempC);
// wait 5 seconds (5000 milliseconds == 5 seconds)
delay(5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment