Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <IoTkit.h> // include IoTkit.h to use the Intel IoT Kit
- #include <Ethernet.h> // must be included to use IoTkit
- // create an object of the IoTkit class
- IoTkit iotkit;
- int temp;
- const int pinTemp = A0; // pin of temperature sensor
- int led = 13;
- float temperature;
- int B=3975; // B value of the thermistor
- float resistance;
- void setup() {
- Serial.begin(115200);
- // call begin on the IoTkit object before calling any other methods
- pinMode(led, OUTPUT); // TO DRIVE LED
- iotkit.begin();
- }
- void loop() {
- temp = getADCTemp();
- Serial.print("Temperature is ");
- Serial.print(temp);
- Serial.println(" degrees celcius.");
- iotkit.send("temperature", temp); //will push the number to your IoT cloud.
- delay(5000);//wait 5 seconds between observations
- }
- // reads hardware temp sensor
- int getADCTemp(){
- int val = analogRead(pinTemp); // get analog value
- resistance=(float)(1023-val)*10000/val; // get resistance
- temperature=1/(log(resistance/10000)/B+1/298.15)-273.15; // calc temperature
- // Serial.println(val); //for troubleshooting
- { // blinks led for troubleshooting
- digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(100); // wait for a 0.1 second
- digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
- }
- return temperature;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement