]> git.piffa.net Git - arduino/blob - books/pdummies/APFD_Chapter12_Home_Sensing_Station_Test/APFD_Chapter12_Home_Sensing_Station_Test.ino
first commit
[arduino] / books / pdummies / APFD_Chapter12_Home_Sensing_Station_Test / APFD_Chapter12_Home_Sensing_Station_Test.ino
1 /* Arduino Projects for Dummies
2  * by Brock Craft 
3  *
4  * Chapter 12: Building a Home Sensing Station
5  * Reads values from Analog Sensors on Pins 2,3 and 4
6  * Posts these values as three datastreams to 
7  * a single Xively feed.
8  *
9  * This code is just for testing an calibrating your
10  * temperature and light sensors
11  *
12  * v0.1 14.05.2013
13 */
14
15 const int lightSensorPin=2;
16 const int tempPin1=3;
17 const int tempPin2=4;
18
19 void setup() {
20   Serial.begin(9600);
21 }
22
23 void loop() {
24   float lightLevel = map(analogRead(lightSensorPin),0,1023,0,100);
25  
26   float temperature1 = ((getVoltage(tempPin1) -.5) * 100L);
27   float temperature2 = ((getVoltage(tempPin2) -.5) * 100L);
28
29   Serial.print("Temp 1 ('C): ");
30   Serial.print(temperature1);
31   Serial.print(", Temp 2 ('C): ");
32   Serial.print(temperature2);
33   Serial.print(", Light (V): ");
34   Serial.println(lightLevel);
35   delay(250);
36 }
37
38 float getVoltage(int pin){
39 return (analogRead(pin) * .004882814);
40 }
41