Advertisement
Guest User

Untitled

a guest
May 9th, 2017
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. //include LCD library
  2. #include <LiquidCrystal.h>
  3.  
  4. //LCD pins
  5. LiquidCrystal lcd(7,6,5,4,3,2);
  6.  
  7. //light sensor input pin
  8. const int lightPin = 0;
  9.  
  10. //heat sensor input pin
  11. const int heatPin = 1;
  12.  
  13. //record light level
  14. int lightLevel;
  15.  
  16. //used to get heat level\
  17. float voltage, degreesC;
  18.  
  19. void setup()
  20. {
  21. Serial.begin(9600);
  22.  
  23. // LCD initial setups
  24. lcd.begin(16, 2);
  25. lcd.clear();
  26. }
  27.  
  28. void loop()
  29. {
  30. // Begin
  31. float voltage, degreesC;
  32.  
  33. // take Light reading as variable
  34. lightLevel = analogRead(lightPin);
  35.  
  36. // take Heat level as voltage and convert to Celcius
  37. voltage = getVoltage(heatPin);
  38. degreesC = (voltage - 0.5) * 100.0;
  39.  
  40. // display Heat + Light variables on LCD
  41. //serial display
  42. Serial.println(lightLevel);
  43. Serial.println(degreesC, 2);
  44.  
  45.  
  46. //lcd display
  47. lcd.setCursor(1,0);
  48. lcd.print("Temp: ");
  49. lcd.setCursor(7,0);
  50. lcd.print(degreesC,2);
  51.  
  52. lcd.setCursor(1,1);
  53. lcd.print("Light: ");
  54. lcd.setCursor(8,1);
  55. lcd.print(lightLevel);
  56. // append values to txt file on computer via usb connection
  57.  
  58.  
  59. // wait specified time before taking next value
  60. delay(10000);
  61. }
  62. float getVoltage(int pin)
  63. {
  64. return (analogRead(pin) * 0.004882814);
  65.  
  66. // This equation converts the 0 to 1023 value that analogRead()
  67. // returns, into a 0.0 to 5.0 value that is the true voltage
  68. // being read at that pin.
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement