-
Notifications
You must be signed in to change notification settings - Fork 1
/
smartbed.ino
67 lines (41 loc) · 1.09 KB
/
smartbed.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
int sensorReading1=0;
int sensorReading2=0;
int knock1 = A0;
int knock2 = A1;
int threshold1 = 12;
int threshold2 = 50;
int motorPin = 3;
const int buzzerPin = 8;
void setup() {
Serial.begin(9600);
pinMode(11,OUTPUT);
pinMode(10, OUTPUT);
//Setup pin modes
pinMode(buzzerPin, OUTPUT);
}
void loop() {
sensorReading1=analogRead(knock1);
sensorReading2=analogRead(knock2);
Serial.println(sensorReading1);
Serial.println(sensorReading2);
if((sensorReading1>=threshold1)||(sensorReading2>=threshold2))
{ delay(20000);
if((sensorReading1>=threshold1)||(sensorReading2>=threshold2))
{digitalWrite(11,HIGH);
digitalWrite(10, HIGH);
tone(buzzerPin, 1000); // Send 1KHz sound signal...
delay(5000);
// ...for 5 sec
noTone(buzzerPin);// Stop sound...
}
else
{
digitalWrite(11,LOW);
digitalWrite(10, LOW);
}}
else
{
digitalWrite(11,LOW);
digitalWrite(10, LOW);
}
}