safwan092

Wind Speed Sensor PR-3000-FSJT-N01 Simple Code

Jul 5th, 2023
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 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.  
  20. #define RXD2 16 // ESP32 Pin [RX2]
  21. #define TXD2 17 // ESP32 Pin [TX2]
  22. byte ByteArray[250];
  23. int ByteData[20];
  24.  
  25. void setup() {
  26. Serial.begin(9600);
  27. Serial2.begin(4800, SERIAL_8N1, RXD2, TXD2);
  28. }
  29.  
  30. void loop() {
  31. readWindSpeesSensor();
  32. }
  33.  
  34. void readWindSpeesSensor() {
  35. delay(200);
  36. byte msgfs[] = { 0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x0B };
  37. int i;
  38. int len = 8;
  39. for (i = 0; i < len; i++) {
  40. Serial2.write(msgfs[i]);
  41. }
  42. len = 0;
  43. int a = 0;
  44. while (Serial2.available()) {
  45. ByteArray[a] = Serial2.read();
  46. a++;
  47. }
  48. int b = 0;
  49. String registros;
  50. for (b = 0; b < a; b++) {
  51. registros = String(ByteArray[b], HEX);
  52. }
  53. ByteData[0] = ByteArray[3] * 256 + ByteArray[4];
  54. float winds;
  55. winds = ByteData[0] * 0.1;
  56.  
  57. Serial.print("Wind Speed = ");
  58. Serial.print(winds);
  59. Serial.println(" m/s");
  60. //delay(50);//200
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment