-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArduino Code.ino
More file actions
76 lines (52 loc) · 1.3 KB
/
Arduino Code.ino
File metadata and controls
76 lines (52 loc) · 1.3 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
#include <SoftwareSerial.h>
SoftwareSerial espSerial(2, 3);
int buzzer = 9;
int LED_green = 10;
int LED_red = 11;
int sensor = A5;
int Threshold = 350;
void setup() {
// put your setup code here, to run once:
pinMode(sensor, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(LED_green, OUTPUT);
pinMode(LED_red, OUTPUT);
Serial.begin(9600);
espSerial.begin(115200);
delay(200);
if (espSerial.available()) {
Serial.print("Esp Available!");
}
delay(2000);
espSerial.println("AT+CWMODE=1");
delay(10000);
espSerial.println("AT+CWJAP=\"kapil2001\",\"abc1234!!\"");
delay(20000);
}
void loop() {
// put your main code here, to run repeatedly:
int SensorValue = analogRead(sensor);
espSerial.println("AT+CIPMUX=0");
delay(2000);
espSerial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",80");
delay(2000);
espSerial.println("AT+CIPSEND=51");
delay(2000);
espSerial.println("GET /update?api_key=6FPWPAAUFAK2KVEM&field1="+String(SensorValue));
delay(2000);
espSerial.println("AT+CIPCLOSE");
delay(2000);
if (SensorValue > Threshold)
{
digitalWrite(LED_red, HIGH);
digitalWrite(LED_green, LOW);
tone(buzzer, 2000, 200);
}
else
{
digitalWrite(LED_green, HIGH);
digitalWrite(LED_red, LOW);
noTone(buzzer);
}
delay(2000);
}