Advertisement
safwan092

Untitled

Feb 25th, 2024
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1.  
  2. // Wind Speed Sensor PR-3000-FSJT-N01
  3.  
  4. // --------------------- Define Pins ------------------------
  5.  
  6. // [Sensor Pin] ---> [RS485 to TTL Pin]
  7. // Brown ---> 10-30V DC+ (Power Supply)
  8. // Black ---> GND DC- (Power Supply)
  9. // Green ---> A+
  10. // Blue ---> B-
  11. //
  12. // [ESP32 Pin] ---> [RS485 to TTL Pin]
  13. // VIN ---> Vcc
  14. // TX2 ---> TXD
  15. // RX2 ---> RXD
  16. // GND ---> GND
  17.  
  18. //------------------------------------------------------------
  19. int Set_Max_Wind_Speed_To_Turn_OFF = 18;
  20. int Delay_Time_OFF = 30; // Time in Seconds
  21. #define relayPin 19
  22. #define RXD2 16 // ESP32 Pin [RX2]
  23. #define TXD2 17 // ESP32 Pin [TX2]
  24. byte ByteArray[250];
  25. int ByteData[20];
  26. float winds;
  27. int flag = 0;
  28.  
  29. void setup() {
  30. Serial.begin(9600);
  31. Serial2.begin(4800, SERIAL_8N1, RXD2, TXD2);
  32. pinMode(relayPin, OUTPUT);
  33. digitalWrite(relayPin, 1);
  34. }
  35.  
  36. void loop() {
  37. readWindSpeesSensor();
  38. if (flag == 1) {
  39. digitalWrite(relayPin, 0);
  40. delay(Delay_Time_OFF*1000);
  41. }
  42.  
  43. if (winds > Set_Max_Wind_Speed_To_Turn_OFF) {
  44. flag = 1;
  45. }
  46. else {
  47. flag = 0;
  48. digitalWrite(relayPin, 1);
  49. }
  50.  
  51.  
  52. }
  53.  
  54. void readWindSpeesSensor() {
  55. delay(200);
  56. byte msgfs[] = { 0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x0B };
  57. int i;
  58. int len = 8;
  59. for (i = 0; i < len; i++) {
  60. Serial2.write(msgfs[i]);
  61. }
  62. len = 0;
  63. int a = 0;
  64. while (Serial2.available()) {
  65. ByteArray[a] = Serial2.read();
  66. a++;
  67. }
  68. int b = 0;
  69. String registros;
  70. for (b = 0; b < a; b++) {
  71. registros = String(ByteArray[b], HEX);
  72. }
  73. ByteData[0] = ByteArray[3] * 256 + ByteArray[4];
  74.  
  75. winds = ByteData[0] * 0.1;
  76.  
  77. Serial.print("Wind Speed = ");
  78. Serial.print(winds);
  79. Serial.println(" m/s");
  80. //delay(50);//200
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement