Advertisement
kimpoy010

smoke

Jan 17th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <UIPEthernet.h>
  2.  
  3. int buzzer = 8;
  4. int smokeA0 = A5;
  5. int smokeA1 = A4;
  6. int smokeA2 = A3;
  7.  
  8. int sensorThres1 = 650;
  9. int sensorThres2 = 500;
  10. int sensorThres3 = 500;
  11.  
  12.  
  13. byte mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};
  14. EthernetClient client;
  15. char server[] = "192.168.2.100";
  16. int interval = 5000;
  17. char uid[] = "1";
  18. String readString = String(100);
  19.  
  20. void setup() {
  21.  
  22. pinMode(buzzer, OUTPUT);
  23. pinMode(smokeA0, INPUT);
  24. pinMode(smokeA1, INPUT);
  25. pinMode(smokeA2, INPUT);
  26.  
  27.  
  28. Serial.begin(9600);
  29. Ethernet.begin(mac);
  30.  
  31. Serial.print("IP Address : ");
  32. Serial.println(Ethernet.localIP());
  33. }
  34.  
  35. void loop() {
  36. int analogSensor1 = analogRead(smokeA0);
  37. int analogSensor2 = analogRead(smokeA1);
  38. int analogSensor3 = analogRead(smokeA2);
  39.  
  40.  
  41. if (analogSensor1 > sensorThres1 || analogSensor2 > sensorThres2 || analogSensor3 > sensorThres3)
  42. {
  43. if(client.connect(server, 80)){
  44. Serial.println("-> Connected");
  45. // Make a HTTP request:
  46. client.print( "GET /apartment/insert.php?");
  47. client.print("uid=");
  48. client.print(uid);
  49. client.println( " HTTP/1.1");
  50. client.print( "Host: " );
  51. client.println(server);
  52. client.println( "Connection: close" );
  53. client.println();
  54. client.println();
  55.  
  56. while (client.connected()) {
  57. if (client.available()) {
  58. char c = client.read();
  59. if (readString.length() < 100) {
  60. readString.append(c);
  61. Serial.println(readString);
  62. }
  63. }
  64. }
  65.  
  66.  
  67. client.stop();
  68. delay(1000);
  69. tone(buzzer, 1000);
  70. delay(10000);
  71. noTone(buzzer);
  72. delay(1000);
  73. }else{
  74. Serial.println("--> connection failed/n");
  75. }
  76. }
  77. else
  78. {
  79. noTone(buzzer);
  80. }
  81. delay(1000);
  82. }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement