-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVIBRATIONAL_SENSOR_NODEMCU_THINGSPEAK_final.ino
83 lines (55 loc) · 1.44 KB
/
VIBRATIONAL_SENSOR_NODEMCU_THINGSPEAK_final.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <ESP8266WiFi.h>;
#include <WiFiClient.h>;
#include <ThingSpeak.h>;
const char* ssid = "ABCDEF"; //Your Network SSID
const char* password = "**********"; //Your Network Password
//int val;
int VIBRATION_SENSOR = 5;
int led_RED = 4;
int led_GREEN = 16;
int val;
WiFiClient client;
unsigned long myChannelNumber = ******; //Your Channel Number (Without Brackets)
const char * myWriteAPIKey = "****************"; //Your Write API Key
void setup()
{
Serial.begin(9600);
pinMode(VIBRATION_SENSOR, INPUT);
pinMode(led_RED, OUTPUT);
pinMode(led_GREEN, OUTPUT);
digitalWrite(led_RED,LOW);
digitalWrite(led_GREEN,LOW);
delay(10);
// Connect to WiFi network
WiFi.begin(ssid, password);
ThingSpeak.begin(client);
}
long TP_init()
{
delay(10);
long measurement=pulseIn (VIBRATION_SENSOR, HIGH); //wait for the pin to get HIGH and returns measurement
return measurement;
}
void loop()
{
long measurement =TP_init();
delay(10);
if(measurement >= 1000)
{
digitalWrite(led_RED,HIGH);
digitalWrite(led_GREEN,LOW);
delay(100);
Serial.print("measurment = ");
Serial.println(measurement);
ThingSpeak.writeField(myChannelNumber, 1,measurement, myWriteAPIKey);
delay(10);
}
else
digitalWrite(led_GREEN,HIGH);
digitalWrite(led_RED,LOW);
delay(100);
Serial.print("measurment = ");
Serial.println(measurement);
ThingSpeak.writeField(myChannelNumber, 1,measurement, myWriteAPIKey);
delay(10);
}