Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.40 KB | None | 0 0
  1. #define BLYNK_PRINT Console
  2. #include <Console.h>
  3. #include <Bridge.h>
  4. #include <BlynkSimpleYun.h>
  5. #include <SPI.h>
  6. #include <Servo.h>
  7.  
  8. // You should get Auth Token in the Blynk App.
  9. // Go to the Project Settings (nut icon).
  10. char auth[] = "31d2f39a78f949d095c3e9318db33e7d";
  11.  
  12. SimpleTimer timer;
  13. //************************I2C 1602 LCD Display
  14. //************************Servo/Keypad
  15. Servo myservo;
  16. BLYNK_WRITE(V3)
  17. {
  18. myservo.write(param.asInt());
  19. }
  20.  
  21. #define Password_Length 8
  22. //int signalPin = 12;
  23. char Data[Password_Length];
  24. char Master[Password_Length] = "123A456";
  25. byte data_count = 0, master_count = 0;
  26. bool Pass_is_good;
  27. char customKey;
  28. const byte ROWS = 4; //four rows
  29. const byte COLS = 4; //four columns
  30. //define the cymbols on the buttons of the keypads
  31. char hexaKeys[ROWS][COLS] = {
  32. {'1','2','3','A'},
  33. {'4','5','6','B'},
  34. {'7','8','9','C'},
  35. {'*','0','#','D'}
  36. };
  37. byte rowPins[ROWS] = {47, 45, 43, 41}; //connect to the row pinouts of the keypad
  38. byte colPins[COLS] = {39, 37, 35, 33}; //connect to the column pinouts of the keypad
  39.  
  40. //initialize an instance of class NewKeypad
  41.  
  42. //************************RFID
  43. bool state=true;
  44.  
  45. //***********************DHT11
  46. #define DHTPIN 5 // What digital pin we're connected to
  47. // Uncomment whatever type you're using!
  48. #define DHTTYPE DHT11 // DHT 11
  49. //#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
  50. //#define DHTTYPE DHT21 // DHT 21, AM2301
  51. //BlynkTimer timer;
  52. // This function sends Arduino's up time every second to Virtual Pin (5).
  53. // In the app, Widget's reading frequency should be set to PUSH. This means
  54. // that you define how often to send data to Blynk App.
  55.  
  56. //******************************Light sensor/Utrasonic sensor/ LED
  57. #define echoPin 29
  58. #define trigPin 27
  59. int lightsensorPin = A0; // select the input pin for the photoresistor
  60. int light_val = 0; // variable to store the value coming from the sensor
  61. int LED = 26; // select the pin26 for the LED
  62.  
  63. //****************************Widget LED
  64. WidgetLED led1(V0); //register to virtual pin 0
  65. WidgetLED led2(V1); //register to virtual pin 1
  66. WidgetLED led3(V2); //register to virtual pin 2
  67. WidgetLED led4(V4); //register to virtual pin 4
  68.  
  69. //************************************************************************smoke sensor mq2
  70. //connect to A1
  71. int smoke_mq2 = A1;
  72. int smoke = 0;
  73.  
  74. //************************************************************************FLAME sensor
  75. //connect to A2
  76. int FlamePin = A2; // This is for input pin
  77. int Flame = 0; // HIGH when FLAME Exposed
  78.  
  79. //************************************************************************BUZZER
  80. int Buzzer = 31;//the pin of the active buzzer
  81.  
  82. //************************************************************************RGB1
  83. const int redPin1 = 8; // R1 connected to digital pin 8
  84. const int greenPin1 = 9; // G1 to digital pin 9
  85. const int bluePin1 = 10; // B1 connected to digital pin 10
  86. //************************************************************************RGB2
  87. const int redPin2 = 11; // R2 connected to digital pin 11
  88. const int greenPin2 = 12; // G2 to digital pin 12
  89. const int bluePin2 = 13; // B2 connected to digital pin 13
  90.  
  91. //************************************************************************2 CHANNEL RELAYS
  92. //the relays connect to
  93. //int IN1 = 4;
  94. //int IN2 = 3;
  95.  
  96. //************************************************************************Water sensor
  97. //the signal pin connect to D7
  98. int waterSensor = 7;
  99. int waterValue = 0;
  100.  
  101. //************************************************************************PIR_HC_SR501
  102. //Connect to D24
  103. int pir_hc_sr501 = 24;
  104. //int LED1 = 26; // choose the pin for the LED
  105. //int relayInput = 3; // choose the pin for the relay
  106. int pirState = LOW; // we start, assuming no motion detected
  107. int pirval = 0; // variable for reading the pin status
  108.  
  109. //rgb
  110. void setColor(int red, int green, int blue)
  111. {
  112. analogWrite(redPin1, red);
  113. analogWrite(greenPin1, green);
  114. analogWrite(bluePin1, blue);
  115. }
  116.  
  117.  
  118.  
  119.  
  120. void ShowCardType( unsigned char* type)
  121. {
  122. Console.print("Card type: ");
  123. if(type[0]==0x04&&type[1]==0x00)
  124. Console.println("MFOne-S50");
  125. else if(type[0]==0x02&&type[1]==0x00)
  126. Console.println("MFOne-S70");
  127. else if(type[0]==0x44&&type[1]==0x00)
  128. Console.println("MF-UltraLight");
  129. else if(type[0]==0x08&&type[1]==0x00)
  130. Console.println("MF-Pro");
  131. else if(type[0]==0x44&&type[1]==0x03)
  132. Console.println("MF Desire");
  133. else
  134. Console.println("Unknown");
  135. }
  136.  
  137. void ShowUser( unsigned char* id)
  138. {
  139. //32 DA 94 10
  140. //Overhere, you need to use your own card message!!!
  141. if( id[0]==0x32 && id[1]==0xDA && id[2]==0x94 && id[3]==0x10 ) {
  142. Console.println("Hello Mary!");
  143. setColor(0, 255, 0); // set rgb1 green
  144. myservo.write(90);//goes to 90 degrees
  145. // state=RelayStatus(state);
  146. delay(3000);
  147. setColor(0, 0, 0);
  148. myservo.write(0);//back to 0 degrees
  149. }
  150. //75 C0 D0 6
  151. //Overhere, you need to use your own card message!!!
  152. else if(id[0]==0x75 && id[1]==0xC0 && id[2]==0xD0 && id[3]==0x65) {
  153. Console.println("Hello MicroHao!");
  154. myservo.write(90);//goes to 90 degrees
  155. setColor(0, 255, 0); // set rgb1 green
  156. Console.println("Open th door");
  157. delay(3000);
  158. myservo.write(0);//back to 0 degrees
  159. setColor(0, 0, 0);
  160. Console.println("Close the door");
  161. //state=RelayStatus(state);
  162. }
  163. else{
  164. Console.println("Hello unkown guy!");
  165. setColor(255, 0, 0); // set rgb1 red
  166. delay(500);
  167. setColor(0, 0, 0);
  168. delay(500);
  169. setColor(255, 0, 0); // set rgb1 red
  170. delay(500);
  171. setColor(0, 0, 0);
  172. }
  173. }
  174.  
  175. //dht
  176.  
  177. void DHTSENSOR ()
  178. {
  179. Console.println("DHT START!");
  180.  
  181. if (isnan(h) || isnan(t)) {
  182. Console.println("Failed to read from DHT sensor!");
  183. // lcd.setCursor(0, 0);
  184. // lcd.print("Failed to read from DHT sensor! : ");
  185. // lcd.clear();
  186. delay(500);
  187. return;
  188. }
  189. // You can send any value at any time.
  190. // Please don't send more that 10 values per second.
  191. Blynk.virtualWrite(V5, h);
  192. Blynk.virtualWrite(V6, t);
  193. delay(500);
  194. }
  195.  
  196. //Light / Ultrasonic
  197.  
  198. void LIGHTSENSOR () {
  199. Console.println("LIGHT SENSOR AND HC-SR04 START!");
  200. float duration, distance;
  201. digitalWrite(trigPin, LOW);
  202. delayMicroseconds(2);
  203.  
  204. digitalWrite(trigPin, HIGH);
  205. delayMicroseconds(10);
  206. digitalWrite(trigPin, LOW);
  207.  
  208. duration = pulseIn(echoPin, HIGH);
  209. distance = (duration / 2) * 0.0344;
  210.  
  211. light_val = analogRead(lightsensorPin); // read the value from the sensor
  212. Console.print("light_val = ");
  213. Console.println(light_val); //The serial will print the light value
  214. Console.print("Distance = ");
  215. Console.print(distance);
  216. Console.println(" cm");
  217. if(light_val>=400 && distance <= 10 ) // the point at which the state of LEDs change
  218. {
  219. digitalWrite(LED, HIGH);
  220. delay(1000);
  221. }
  222. else
  223. {
  224. digitalWrite(LED, LOW); //set LED off
  225. }
  226. }
  227.  
  228. //********************************************* PIR HC-SR501
  229. void PIRSENSOR () {
  230. Console.println("PIR SENSOR START!");
  231. pirval = digitalRead(pir_hc_sr501); // read input value
  232. if (pirval == HIGH) { // check if the input is HIGH
  233. //digitalWrite(LED, HIGH); // turn LED ON
  234. led2.on(); // set LED on
  235. if (pirState == LOW) {
  236. // we have just turned on
  237. Console.println("Motion detected!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  238. // We only want to print on the output change, not state
  239. pirState = HIGH;
  240. }
  241. } else {
  242. led2.off(); //set LED off
  243. if (pirState == HIGH){
  244. // we have just turned of
  245. Console.println("Motion ended!");
  246. // We only want to print on the output change, not state
  247. pirState = LOW;
  248. }
  249. }
  250. }
  251.  
  252. //********************************************* Flame Sensor
  253. void FLAMESENSOR () {
  254. Console.println("FLAME SENSOR START!");
  255. Flame = analogRead(FlamePin);
  256. Console.print("flame_val = ");
  257. Console.println(Flame); //The serial will print the fire value
  258. if(Flame<=650) // the point at which the state of LEDs change
  259. {
  260. setColor(255, 0, 0); // turn the RGB LED red
  261. delay(500);
  262. setColor(0, 0, 0);
  263. delay(500);
  264. setColor(255, 0, 0); // turn the RGB LED red
  265. delay(500);
  266. setColor(0, 0, 0);
  267. delay(500);
  268. digitalWrite(Buzzer, HIGH);
  269. led3.on();
  270.  
  271. }
  272. else
  273. {
  274. Console.println("No Fire!");
  275. digitalWrite(Buzzer, LOW);
  276. led3.off();
  277. }
  278. //delay(2000);
  279. }
  280. //********************************************* MQ2 Smoke sensor
  281. void SMOKESENSOR () {
  282. Console.println("SMOKE SENSOR START!");
  283. smoke = analogRead(smoke_mq2);
  284. Console.print("smoke_val = ");
  285. Console.println(smoke); //The serial will print the smoke value
  286. if(smoke>=240) // the point at which the state of LEDs change
  287. {
  288. setColor(255, 0, 0); // turn the RGB LED red
  289. delay(2000);
  290. setColor(0, 0, 0);
  291. delay(2000);
  292. setColor(255, 0, 0); // turn the RGB LED red
  293. delay(2000);
  294. setColor(0, 0, 0);
  295. digitalWrite(Buzzer, HIGH);
  296. led1.on();
  297. }
  298. else
  299. {
  300. Console.println("No smoke!");
  301. digitalWrite(Buzzer, LOW);
  302. led1.off();
  303. }
  304. // delay(500);
  305. }
  306.  
  307. //**********************void setup
  308. void setup()
  309. {
  310. Blynk.begin(auth);
  311. Bridge.begin();
  312. Console.begin();
  313. SPI.begin();
  314. myservo.attach(2);
  315. myservo.write(0);//back to 0 degrees
  316. lcd.init(); // initialize the lcd
  317. // Print a message to the LCD.
  318. lcd.backlight();
  319. lcd.clear();
  320. // pinMode(led, OUTPUT);
  321. //pinMode(relay,OUTPUT);
  322. // digitalWrite(relay,HIGH);
  323. // Setup a function to be called every second
  324. pinMode(trigPin, OUTPUT);
  325. pinMode(echoPin, INPUT);
  326. pinMode(LED, OUTPUT); // declare LED as output
  327. pinMode(pir_hc_sr501, INPUT); // declare sensor as input
  328. pinMode(Buzzer, OUTPUT); // declare Buzzer as output
  329. pinMode(redPin1, OUTPUT);
  330. pinMode(greenPin1, OUTPUT);
  331. pinMode(bluePin1, OUTPUT);
  332.  
  333. timer.setInterval(1000, KEYPADSENSOR);
  334. timer.setInterval(1000, RFIDSENSOR);
  335. timer.setInterval(10000, DHTSENSOR);
  336. timer.setInterval(10000, FLAMESENSOR);
  337. timer.setInterval(10000, SMOKESENSOR);
  338. timer.setInterval(1000, LIGHTSENSOR);
  339. timer.setInterval(1000, PIRSENSOR);
  340. while (!Console);{}
  341.  
  342. }
  343.  
  344. //**********************void loop
  345. void loop()
  346. {
  347. // this is where the "polling" occurs
  348. timer.run();
  349. Blynk.run();
  350. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement