]> Zhao Yanbai Git Server - acecode.git/commitdiff
add Sensors
authoracevest <zhaoyanbai@126.com>
Thu, 30 Oct 2014 14:55:42 +0000 (22:55 +0800)
committeracevest <zhaoyanbai@126.com>
Thu, 30 Oct 2014 14:55:42 +0000 (22:55 +0800)
arduino/Sensors/Sensors/Sensors.ino [new file with mode: 0644]

diff --git a/arduino/Sensors/Sensors/Sensors.ino b/arduino/Sensors/Sensors/Sensors.ino
new file mode 100644 (file)
index 0000000..b1bb7d5
--- /dev/null
@@ -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);
+  }
+  
+}
+