From: acevest Date: Thu, 30 Oct 2014 14:55:42 +0000 (+0800) Subject: add Sensors X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=51a1935c3f08f12ffe9a3fd30afcfc2315cebe3f;p=acecode.git add Sensors --- 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); + } + +} +