-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomoticaUNO.ino
112 lines (103 loc) · 2.27 KB
/
domoticaUNO.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <SoftwareSerial.h>
SoftwareSerial BT(2, 3); // RX, TX
int luzBalcon = 5;
int luzGaraje = 8;
int luzSala = 13;
int luzCuarto = 9;
int luzCocina = 11;
int luzFuera = 10;
const int ldrPin = A0;
byte sensorpir = 6;
int actSensor = 5;
char valor ; //Variable para indicar que llega una orden
void setup() {
// put your setup code here, to run once:
pinMode(sensorpir,INPUT);
BT.begin(9600);
pinMode(luzSala, OUTPUT);
pinMode(actSensor, OUTPUT);
pinMode(7, OUTPUT);
pinMode(luzCuarto, OUTPUT);
pinMode(luzCocina, OUTPUT);
pinMode(luzFuera, OUTPUT);
pinMode(ldrPin, INPUT);
Serial.begin(9600);
digitalWrite(actSensor, HIGH);
pinMode(luzGaraje, OUTPUT);
pinMode(luzBalcon, OUTPUT);
}
void loop() {
if (BT.available()) //Si el puerto serie (Bluetooth) está disponible
{
valor = BT.read(); //Lee el dato entrante via Bluetooth
}
if (valor == 'A')
{
digitalWrite(luzFuera, HIGH);
}
if (valor == 'B')
{
digitalWrite(luzFuera, LOW);
}
if (valor == 'C')
{
digitalWrite(luzSala, HIGH);
}
if (valor == 'D')
{
digitalWrite(luzSala, LOW);
}
if (valor == 'E')
{
digitalWrite(luzCocina, HIGH);
}
if (valor == 'F')
{
digitalWrite(luzCocina, LOW);
}
if (valor == 'G')
{
digitalWrite(luzCuarto, HIGH);
}
if (valor == 'H')
{
digitalWrite(luzCuarto, LOW);
}
if (valor == 'K')
{
digitalWrite(luzGaraje, HIGH);
}
if (valor == 'L')
{
digitalWrite(luzGaraje, LOW);
}
if (valor == 'I')
{
digitalWrite(luzBalcon, HIGH);
}
if (valor == 'J')
{
digitalWrite(luzBalcon, LOW);
}
if (valor == 'X' ){
if(digitalRead(sensorpir) == HIGH){
alarma();
delay(1000);
digitalWrite(actSensor,LOW);
}
}
if (valor == 'Z'){
digitalWrite(7,LOW);
digitalWrite(actSensor,HIGH);
}
}
void alarma(){
digitalWrite(7,HIGH);
delay(500);
digitalWrite(7,LOW);
delay(500);
digitalWrite(7,HIGH);
delay(500);
digitalWrite(7,LOW);
delay(500);
}