-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGas_Temperature_Sensors.ino
56 lines (45 loc) · 1.16 KB
/
Gas_Temperature_Sensors.ino
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
55
56
/* temperature sensor variables*/
float celcius;
float fahrenheit;
float voltage;
int temperatureSensorPin = A0;
/* gas sensor variables */
const int gas = 0;
int gasSensorPin = A1;
/* variable that both sensors use */
float sensorValue;
void setup()
{
pinMode(temperatureSensorPin, INPUT);
Serial.begin(9600);
}
void loop()
{
/* code for the gas sensor */
sensorValue = analogRead(gasSensorPin);
if(sensorValue >= 450)
{
Serial.print(sensorValue);
Serial.println(" | SMOKE DETECTED!");
}
else
{
Serial.print("Sensor Value: ");
Serial.println(sensorValue);
}
/* code for the temperature sensor */
sensorValue = analogRead(temperatureSensorPin);
/* calculating the voltage collected from the sensor */
voltage = sensorValue * 5;
voltage /= 1024;
/* calculate the temperature from the voltage */
celcius = (voltage - 0.5) * 100;
fahrenheit = (9.0 / 5) * celcius + 32;
/* printing the temperatures */
Serial.print("Celcius: ");
Serial.println(celcius);
Serial.print("Fahrenheit: ");
Serial.println(fahrenheit);
Serial.println();
delay(2000); // pauses for 2 seconds so we're not bombarded with data
}