Advertisement
Guest User

full code

a guest
Jan 19th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #include <dht.h>
  3.  
  4. /*---- DHT -----*/
  5. dht DHT;
  6. const int DHT11_PIN = 12;
  7.  
  8. /*--------Display----------*/
  9. // initialize the library by associating any needed LCD interface pin
  10. // with the arduino pin number it is connected to
  11. const int rs = 5, en = 6, d4 = 7, d5 = 8, d6 = 9, d7 = 10;
  12. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  13.  
  14. /*----Sound Sensor-----*/
  15. #define SOUNDANALOG_PIN A0
  16. const int SOUNDDIGITAL_PIN = 11;
  17. boolean soundDigitalVal = 0;
  18. int soundAnalogVal = 0;
  19.  
  20. /*-------Dust-------*/
  21. const int DUSTANALOG_PIN = A5;
  22.  
  23. unsigned int samplingTime = 280;
  24. unsigned int deltaTime = 40;
  25. unsigned int sleepTime = 9680;
  26.  
  27. float dustVoMeasured = 0;
  28. float calcVoltage = 0;
  29. float dustDensity = 0;
  30.  
  31. void setup(){
  32. Serial.begin (9600);
  33.  
  34. pinMode(SOUNDANALOG_PIN, INPUT);
  35. pinMode(SOUNDDIGITAL_PIN, INPUT);
  36.  
  37. //Setup of the LCD's number of column and rows
  38. lcd.begin(20, 4);
  39. //Displaying welcome to the LCD
  40. lcd.print("Welcome!");
  41. }
  42.  
  43. void loop (){
  44. lcd.clear();
  45. //delayMicroseconds(samplingTime);
  46.  
  47. /***-------- DHT11 Sensor -----------***/
  48. int chk = DHT.read11(DHT11_PIN);
  49. lcd.setCursor(0,0);
  50. lcd.print("Temp: " + String(DHT.temperature) + ((char)223) + "C");
  51. lcd.setCursor(0,1);
  52. lcd.print("Humidity: " + String(DHT.humidity)+"%");
  53. Serial.println("Temp: " + String(DHT.temperature) + ((char)223) + "C");
  54. Serial.println("Humidity: " + String(DHT.humidity)+"%");
  55. /*-----------------------------------*/
  56.  
  57.  
  58. /***-------- Dust Sensor ---------***/
  59. dustVoMeasured = analogRead(DUSTANALOG_PIN);
  60. calcVoltage = dustVoMeasured*(5.0/1024);
  61. dustDensity = 0.17*calcVoltage-0.1;
  62. if ( dustDensity < 0)
  63. {
  64. dustDensity = 0.00;
  65. }
  66. lcd.setCursor(0,2);
  67. lcd.print("Dust: "+String(dustDensity)+"ng/m3");
  68. Serial.println("Dust: "+String(dustDensity)+"ng/m3");
  69. /*-----------------------------------*/
  70.  
  71.  
  72. /***---------- Sound Sensor ----------***/
  73. soundAnalogVal = analogRead(SOUNDANALOG_PIN);
  74. soundDigitalVal = digitalRead(SOUNDDIGITAL_PIN);
  75.  
  76. double soundAnalogValDB = 20 * log10(soundAnalogVal);
  77. //double soundAnalogValDB = (soundAnalogVal + 83.2073 ) / 11.003;
  78.  
  79. //Serial.println (analogVal);
  80. //When the sensor detects a signal above the threshold value, LED flashes
  81. if (soundDigitalVal==HIGH) {
  82. lcd.setCursor(0,3);//set the cursor at first row
  83. lcd.print("Sound: "+String(soundAnalogValDB)+"db" + " (High)");//Sound Intensity level
  84. Serial.println("Sound: "+String(soundAnalogValDB)+"db" + " (High)");
  85. }
  86. else {
  87. lcd.setCursor(0,3);//set the cursor at first row
  88. lcd.print("Sound: "+String(soundAnalogValDB)+"db" + " (Low)");//Sound Intensity level
  89. Serial.println ("Sound: "+String(soundAnalogValDB)+"db" + " (Low)");
  90. }
  91. /*-----------------------------------*/
  92.  
  93. Serial.println();
  94. delay(1000);
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement