-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcdsensor.ino
More file actions
54 lines (47 loc) · 1.3 KB
/
lcdsensor.ino
File metadata and controls
54 lines (47 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* lcdsensor
* Temp and light sensor
*
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// TMP36
int temperaturePin = 0;
//PhotoResistor Pin
int lightPin = 1; //the analog pin the photoresistor is
//connected to
//the photoresistor is not calibrated to any units so
//this is simply a raw sensor value (relative light)
//LED Pin
int ledPin = 9; //the pin the LED is connected to
//we are controlling brightness so
//we use one of the PWM (pulse width
// modulation pins)
void setup()
{
lcd.begin(16, 2);
}
/*
* loop() - this function will start after setup
* finishes and then repeat
*/
void loop()
{
float lightVoltage = getVoltage(lightPin);
float temperatureVoltage = getVoltage(temperaturePin);
float temperature = (temperatureVoltage - 0.5) * 100.0;
float lightKOhms = 10.0 / (5.0/lightVoltage - 1.0);
float lightLux = 255.84 * pow(lightKOhms, -10/9);
lcd.clear();
lcd.print("Temp=");
lcd.print(temperature);
lcd.setCursor(0,1);
lcd.print("LightLux=");
lcd.print(lightLux);
delay(1000);
}
float getVoltage(int pin) {
return (analogRead(pin) * 0.004882814);
}