From 51a1935c3f08f12ffe9a3fd30afcfc2315cebe3f Mon Sep 17 00:00:00 2001 From: acevest Date: Thu, 30 Oct 2014 22:55:42 +0800 Subject: [PATCH] add Sensors --- arduino/Sensors/Sensors/Sensors.ino | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 arduino/Sensors/Sensors/Sensors.ino diff --git a/arduino/Sensors/Sensors/Sensors.ino b/arduino/Sensors/Sensors/Sensors.ino new file mode 100644 index 0000000..b1bb7d5 --- /dev/null +++ b/arduino/Sensors/Sensors/Sensors.ino @@ -0,0 +1,46 @@ +const int ledPin = 12; +int cnt = 0; + +void setup() { + Serial.begin(9600); + pinMode(ledPin, OUTPUT); +} + +void loop() { + cnt ++; + + int lv = analogRead(0); // Light + + int tv = analogRead(1); // Temperature + + delay(100); + + float temperature; + float resistance = (float)(1023-tv)*10000/tv; + temperature = 1/(log(resistance/10000)/3975+1/298.15) - 273.15; + if(cnt % 10 == 0) + { + Serial.print("Light Sensor Value: "); + Serial.println(lv); + + Serial.print("Temperature Sensor Value: "); + Serial.println(tv); + + Serial.print(">Light: "); + Serial.println(lv); + + Serial.print(">Temperature: "); + Serial.println(temperature); + } + + if(lv < 400) + { + digitalWrite(ledPin, HIGH); + } + else + { + digitalWrite(ledPin, LOW); + } + +} + -- 2.44.0