-
Notifications
You must be signed in to change notification settings - Fork 0
/
FINAL.ino.ino
151 lines (120 loc) · 3.63 KB
/
FINAL.ino.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
String textMessage;
String Presstemp="";
String lampState = "OFF";
const int relay = 13;
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085); // Displays some basic information on this sensor from the un
void setup()
{
pinMode(relay, OUTPUT);
digitalWrite(relay, HIGH);
pinMode(12, OUTPUT);
digitalWrite(12, LOW);
delay(1000);
digitalWrite(12, HIGH);
Serial.begin(19200);
SIM900.begin(19200);
if(!bmp.begin())
{ /* There was a problem detecting the BMP085 ... check your connections */
Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
}
displaySensorDetails();
delay(2000);
Serial.print("SIM900 ready...");
SIM900.print("AT\r");
delay(200);
SIM900.print("AT+CMGF=1\r");
delay(200);
SIM900.print("AT+CNMI=2,2,0,0,0\r");// Set module to send SMS data to serial out upon receipt
delay(200);
}
void loop(){
if(SIM900.available()>0)
{
textMessage = SIM900.readString();
Serial.print(textMessage);
delay(10);
}
if(textMessage.indexOf("ON")>=0)
{
// Turn on relay and save current state
digitalWrite(relay, LOW);
delay(1000);
digitalWrite(relay, HIGH);
lampState = "on";
Serial.println("Car Lock set to ON");
textMessage = "";
}
if(textMessage.indexOf("OFF")>=0)
{
// Turn off relay and save current state
digitalWrite(12, LOW);
delay(1000);
digitalWrite(12, HIGH);
lampState = "off";
Serial.println("Car Lock set to OFF");
textMessage = "";
}
if(textMessage.indexOf("STATE")>=0)
{
sensors_event_t event;
bmp.getEvent(&event);
if (event.pressure)
{
float tyrepress = event.pressure; // Serial.println(" hPa");
float temperature;
bmp.getTemperature(&temperature);
Presstemp = "Tyre Pressure is ";
Presstemp += String(tyrepress);
Presstemp += " hPa , ";
Presstemp += "Tyre Temperature is ";
Presstemp += String(temperature);
Presstemp += " Degree Celcius";
}
else
{
Serial.println("Sensor error");
}
int a= analogRead(A1);
a=map(a,0,1023,0,100);
String fuel=String(a);
String message = "CAR is " + lampState+", Fuel level is "+ fuel+" %"+ Presstemp;
sendSMS(message);
Serial.println("Lamp state resquest");
textMessage = "";
Presstemp="";
fuel="";
}
}
void sendSMS(String message)
{
SIM900.print("AT+CMGF=1\r");
delay(500);
SIM900.println("AT + CMGS = \"+917986534673\""); // REPLACE THE X's WITH THE RECIPIENT'S MOBILE NUMBER
delay(500);
SIM900.println(message);
delay(500);
SIM900.println((char)26);
delay(100);
SIM900.println();
delay(5000);
}
void displaySensorDetails(void)
{
sensor_t sensor;
bmp.getSensor(&sensor);
Serial.println("------------------------------------");
Serial.print ("Sensor: "); Serial.println(sensor.name);
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" hPa");
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" hPa");
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" hPa");
Serial.println("------------------------------------");
Serial.println("");
delay(500);
}