└── project.c /project.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | SoftwareSerial Serial1(2,3); 6 | 7 | 8 | #include 9 | 10 | LiquidCrystal lcd(14,15,16,17,18,19); 11 | 12 | int led=13; 13 | 14 | int flag=0; 15 | 16 | String str=""; 17 | 18 | 19 | #define motor 11 20 | 21 | #define sensor 7 22 | 23 | 24 | void setup() 25 | 26 | { 27 | 28 | lcd.begin(16,2); 29 | 30 | Serial1.begin(9600); 31 | 32 | Serial.begin(9600); 33 | 34 | pinMode(led, OUTPUT); 35 | 36 | pinMode(motor, OUTPUT); 37 | 38 | pinMode(sensor, INPUT_PULLUP); 39 | 40 | lcd.print(""); 41 | 42 | lcd.setCursor(4,1); 43 | 44 | delay(2000); 45 | 46 | lcd.clear(); 47 | 48 | lcd.print(""); 49 | 50 | lcd.setCursor(0,1); 51 | 52 | lcd.print(""); 53 | 54 | delay(2000); 55 | 56 | gsmInit(); 57 | 58 | lcd.clear(); 59 | 60 | lcd.print("System Ready"); 61 | 62 | } 63 | 64 | 65 | void loop() 66 | 67 | { 68 | 69 | lcd.setCursor(0,0); 70 | 71 | lcd.print("Automatic Mode "); 72 | 73 | if(digitalRead(sensor)==1 && flag==0) 74 | 75 | { 76 | 77 | delay(1000); 78 | 79 | if(digitalRead(sensor)==1) 80 | 81 | { 82 | 83 | digitalWrite(led, HIGH); 84 | 85 | sendSMS("intureder detected. plz check"); 86 | 87 | lcd.begin(16,2); 88 | 89 | lcd.setCursor(0,1); 90 | 91 | lcd.print("Motor ON "); 92 | 93 | digitalWrite(motor, HIGH); 94 | 95 | delay(2000); 96 | 97 | flag=1; 98 | 99 | } 100 | 101 | } 102 | 103 | 104 | else if(digitalRead(sensor)==0 && flag==1) 105 | 106 | { 107 | 108 | delay(1000); 109 | 110 | if(digitalRead(sensor)==0) 111 | 112 | { 113 | 114 | digitalWrite(led, LOW); 115 | 116 | sendSMS("no intureder"); 117 | 118 | digitalWrite(motor, LOW); 119 | 120 | lcd.begin(16,2); 121 | 122 | lcd.print("Motor OFF"); 123 | 124 | lcd.setCursor(0,1); 125 | 126 | lcd.print("Motor OFF"); 127 | 128 | delay(2000); 129 | 130 | flag=0; 131 | 132 | } 133 | 134 | } 135 | 136 | } 137 | 138 | 139 | 140 | void sendSMS(String msg) 141 | 142 | { 143 | 144 | lcd.clear(); 145 | 146 | lcd.print("Sending SMS"); 147 | 148 | Serial1.println("AT+CMGF=1"); 149 | 150 | delay(500); 151 | 152 | Serial1.print("AT+CMGS="); 153 | 154 | Serial1.print('"'); 155 | 156 | Serial1.print("+919025989480"); // number 157 | 158 | Serial1.print('"'); 159 | 160 | Serial1.println(); 161 | 162 | delay(500); 163 | 164 | Serial1.println(msg); 165 | 166 | delay(500); 167 | 168 | Serial1.write(26); 169 | 170 | delay(1000); 171 | 172 | lcd.clear(); 173 | 174 | lcd.print("SMS Sent"); 175 | 176 | delay(1000); 177 | 178 | lcd.begin(16,2); 179 | 180 | } 181 | 182 | 183 | void gsmInit() 184 | 185 | { 186 | 187 | lcd.clear(); 188 | 189 | lcd.print("Finding Module.."); 190 | 191 | boolean at_flag=1; 192 | 193 | while(at_flag) 194 | 195 | { 196 | 197 | Serial1.println("AT"); 198 | 199 | while(Serial1.available()>0) 200 | 201 | { 202 | 203 | if(Serial1.find("OK")) 204 | 205 | at_flag=0; 206 | 207 | } 208 | 209 | delay(1000); 210 | 211 | } 212 | 213 | Serial1.println("ATE0"); 214 | 215 | lcd.clear(); 216 | 217 | lcd.print("Finding Network.."); 218 | 219 | boolean net_flag=1; 220 | 221 | while(net_flag) 222 | 223 | { 224 | 225 | Serial1.println("AT+CPIN?"); 226 | 227 | while(Serial1.available()>0) 228 | 229 | { 230 | 231 | if(Serial1.find("READY")) 232 | 233 | net_flag=0; 234 | 235 | break; 236 | 237 | } 238 | 239 | delay(1000); 240 | 241 | } 242 | 243 | Serial1.println("AT+CNMI=2,2,0,0,0"); 244 | 245 | delay(1000); 246 | 247 | Serial1.println("AT+CMGF=1"); 248 | 249 | delay(1000); 250 | 251 | Serial1.println("AT+CSMP=17,167,0,0"); 252 | 253 | lcd.clear(); 254 | 255 | Serial1.flush(); 256 | 257 | } --------------------------------------------------------------------------------