-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.ino
64 lines (49 loc) · 1.53 KB
/
code.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
57
58
59
60
61
62
63
64
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
float value;
int tmp = A1;
const int ledPin = 13; //the number of the LED pin
const int ldrPin = A0; //the number of the LDR pin
int v_GasSen = 0; //Gas sensor pins
void setup()
{
pinMode(tmp,INPUT);
Serial.begin(9600);
pinMode(ledPin, OUTPUT); //initialize the LED pin as an output
pinMode(ldrPin, INPUT); //initialize the LDR pin as an input
pinMode(A2, INPUT);
pinMode(7, OUTPUT);
}
void loop()
{
//Checking temperature
value = analogRead(tmp)* 0.00482814;
value =(value - 0.5) * 100.0; // Converting temperature to celcius
lcd.setCursor(0, 1); // Setting cursor for LCD
lcd.print("Tmp:");
lcd.print(value); //Displaying value read and converted
delay(1000);
lcd.clear();
//LED Implementation
int ldrStatus = analogRead(ldrPin); //read the status of the LDR value
//check if the LDR status is <= 300
//if it is, the LED is HIGH
if (ldrStatus <=300)
{
digitalWrite(ledPin, HIGH); //turn LED on
Serial.println("LDR is DARK, LED is ON");
}
else
{
digitalWrite(ledPin, LOW); //turn LED off
Serial.println("---------------");
}
//Gas sensor Implementation
v_GasSen = analogRead(A2);
if (v_GasSen >= 250)
{
tone(7, 523, 1000); // play tone 60 (C5 = 523 Hz)
}
delay(10); // Delay a little bit to improve simulation performance
}