Advertisement
Guest User

iottemplogger

a guest
Feb 2nd, 2015
667
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1.  
  2. #include <IoTkit.h> // include IoTkit.h to use the Intel IoT Kit
  3. #include <Ethernet.h> // must be included to use IoTkit
  4.  
  5.  
  6. // create an object of the IoTkit class
  7. IoTkit iotkit;
  8. int temp;
  9.  
  10.  
  11. const int pinTemp = A0; // pin of temperature sensor
  12. int led = 13;
  13.  
  14. float temperature;
  15. int B=3975; // B value of the thermistor
  16. float resistance;
  17.  
  18.  
  19. void setup() {
  20. Serial.begin(115200);
  21. // call begin on the IoTkit object before calling any other methods
  22. pinMode(led, OUTPUT); // TO DRIVE LED
  23. iotkit.begin();
  24. }
  25.  
  26. void loop() {
  27. temp = getADCTemp();
  28. Serial.print("Temperature is ");
  29. Serial.print(temp);
  30. Serial.println(" degrees celcius.");
  31.  
  32. iotkit.send("temperature", temp); //will push the number to your IoT cloud.
  33. delay(5000);//wait 5 seconds between observations
  34. }
  35.  
  36. // reads hardware temp sensor
  37. int getADCTemp(){
  38. int val = analogRead(pinTemp); // get analog value
  39. resistance=(float)(1023-val)*10000/val; // get resistance
  40. temperature=1/(log(resistance/10000)/B+1/298.15)-273.15; // calc temperature
  41. // Serial.println(val); //for troubleshooting
  42. { // blinks led for troubleshooting
  43. digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
  44. delay(100); // wait for a 0.1 second
  45. digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
  46. }
  47. return temperature;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement