Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. // Demo code for Grove - Temperature Sensor V1.1/1.2
  2. // Loovee @ 2015-8-26
  3. #include <Wire.h>
  4. #include <SeeedOLED.h>
  5. #include <math.h>
  6.  
  7. const int B=4275; // B value of the thermistor
  8. const int R0 = 100000; // R0 = 100k
  9. const int pinTempSensor = A0; // Grove - Temperature Sensor connect to A5
  10.  
  11. void setup()
  12. {
  13. Wire.begin();
  14. SeeedOled.init(); //initialze SEEED OLED display
  15.  
  16. SeeedOled.clearDisplay(); //clear the screen and set start position to top left corner
  17. SeeedOled.setNormalDisplay(); //Set display to normal mode (i.e non-inverse mode)
  18. SeeedOled.setPageMode(); //Set addressing mode to Page Mode
  19. SeeedOled.setTextXY(0,0); //Set the cursor to Xth Page, Yth Column
  20. SeeedOled.putString("Temp:");
  21. Serial.begin(9600);
  22. }
  23.  
  24. void loop()
  25. {
  26. int a = analogRead(pinTempSensor );
  27.  
  28. float R = 1023.0/((float)a)-1.0;
  29. R = 100000.0*R;
  30.  
  31. float temperature=1.0/(log(R/100000.0)/B+1/298.15)-273.15;//convert to temperature via datasheet ;
  32. SeeedOled.setTextXY(1,0); //Set the cursor to Xth Page, Yth Column
  33. SeeedOled.putNumber(temperature);
  34. Serial.print("temperature = ");
  35. Serial.println(temperature);
  36.  
  37. delay(100);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement