Advertisement
Guest User

Code

a guest
Feb 29th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. /*
  2. RXD,4
  3. TXD,5
  4. A,1
  5. B,0
  6. Q,13
  7. 3.3,3.3
  8. D1,A5
  9. D2,A4
  10. GND,GND
  11. 5V,5V
  12.  
  13. */
  14. #include <Wire.h>
  15. #include <LiquidCrystal_I2C.h>
  16. #include <BLINKER_PMSX003ST.h>
  17. char recd_dat; // variable for receiving data from bluetooth serial port
  18. int on_brd_led = 8; // On-board LED pin detail
  19. int Al=1;
  20. LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
  21. #if defined(ESP32)
  22. LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
  23. HardwareSerial pmsSerial(2);// UART1/Serial1 pins 16,17
  24. #else
  25. #include <SoftwareSerial.h>
  26. SoftwareSerial pmsSerial(2,3);
  27. #endif
  28.  
  29. BLINKER_PMSX003ST pms;
  30.  
  31. void setup() {
  32. pinMode(8, OUTPUT);
  33. pinMode(13, INPUT);
  34. lcd.init(); //initialize the lcd
  35. lcd.backlight(); //open the backlight
  36. Serial.begin(115200);
  37. Serial.println("\nStart");
  38. pinMode(on_brd_led, OUTPUT);
  39. digitalWrite(on_brd_led, LOW);
  40. pmsSerial.begin(9600);
  41. pms.begin(pmsSerial);
  42. // pms.wakeUp();
  43. pms.setMode(PASSIVE);
  44. lcd.init(); //initialize the lcd
  45. lcd.backlight(); //open the backlight
  46. }
  47.  
  48. void loop() {
  49. pms.request();
  50.  
  51.  
  52.  
  53. if(Al == 1)
  54. {
  55. Serial.print("OK");
  56. }
  57. else
  58. {
  59. Serial.print("?");
  60. }
  61. if(13 == HIGH)
  62. {
  63. if(Al ==1 )
  64. {
  65. int Al = 2;
  66. delay (1000);
  67. }
  68. if(Al = 2)
  69. {
  70. int Al = 1;
  71. delay (1000);
  72. }
  73. }
  74. ç
  75.  
  76. lcd.clear();
  77. Serial.print("PM1.0(CF1)\t");
  78. Serial.print(pms.getPmCf1(1.0));
  79. Serial.println("ug/m3");
  80. Serial.print("PM2.5(CF1)\t");
  81. Serial.print(pms.getPmCf1(2.5));
  82. Serial.println("ug/m3");
  83. Serial.print("PM10(CF1)\t");
  84. Serial.print(pms.getPmCf1(10));
  85. Serial.println("ug/m3");
  86. Serial.print("PM1.0(ATO)\t");
  87. Serial.print(pms.getPmAto(1.0));
  88. Serial.println("ug/m3");
  89. Serial.print("PM2.5(ATO)\t");
  90. Serial.print(pms.getPmAto(2.5));
  91. Serial.println("ug/m3");
  92. Serial.print("PM10(ATO)\t");
  93. Serial.print(pms.getPmAto(10));
  94. Serial.println("ug/m3");
  95. Serial.print(" PCS0.3\t");
  96. Serial.print(pms.getPcs(0.3));
  97. Serial.println("pcs/0.1L");
  98. Serial.print(" PCS0.5\t");
  99. Serial.print(pms.getPcs(0.5));
  100. Serial.println("pcs/0.1L");
  101. Serial.print(" PCS1.0\t");
  102. Serial.print(pms.getPcs(1));
  103. Serial.println("pcs/0.1L");
  104. Serial.print(" PCS2.5\t");
  105. Serial.print(pms.getPcs(2.5));
  106. Serial.println("pcs/0.1L");
  107. Serial.print(" PCS5.0\t");
  108. Serial.print(pms.getPcs(5));
  109. Serial.println("pcs/0.1L");
  110. Serial.print(" PCS10\t");
  111. Serial.print(pms.getPcs(10));
  112. Serial.println("pcs/0.1L");
  113. Serial.print("Formalde\t");
  114. Serial.print(pms.getForm());
  115. Serial.println("ug/m3");
  116. Serial.print("Temperat\t");
  117. Serial.print(pms.getTemp());
  118. Serial.println("'C");
  119. Serial.print("Humidity\t");
  120. Serial.print(pms.getHumi());
  121. Serial.println("%");
  122. Serial.println();
  123. lcd.clear();
  124. lcd.setCursor(0,0);
  125. lcd.print("PM2.5 ");
  126. lcd.print(pms.getPmAto(2.5));
  127. lcd.print("ug/m3");
  128. lcd.setCursor(25,2); // set the cursor to column 15, line 1
  129. lcd.print(pms.getTemp());
  130. lcd.print("C ");
  131. lcd.print(pms.getHumi());
  132. lcd.print("%");
  133. delay(1000);
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement