safwan092

Project_10686_Code

Jan 30th, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <Adafruit_SSD1306.h>
  3. #include <Adafruit_GFX.h>
  4. #include <SoftwareSerial.h>
  5.  
  6. SoftwareSerial softSerial(2, 3); //TX_BT --> D2 / RX_BT --> D3
  7.  
  8.  
  9. #define OLED_WIDTH 128
  10. #define OLED_HEIGHT 64
  11.  
  12. #define OLED_ADDR 0x3C
  13.  
  14. Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT);
  15.  
  16. void setup() {
  17. Serial.begin(9600);
  18. softSerial.begin(9600);
  19. display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  20.  
  21. }
  22.  
  23. void loop() {
  24. float sensorValue = analogRead(A0);
  25. Serial.print("Analog Value =");
  26. Serial.println(sensorValue);
  27. float voltage = (sensorValue / 1023) * 5;
  28. Serial.print("Voltage =");
  29. Serial.print(voltage);
  30. Serial.println(" V");
  31. float wind_speed = mapfloat(voltage, 0, 5, 0, 32.4);
  32. Serial.print("Wind Speed =");
  33. Serial.print(wind_speed);
  34. Serial.println("m/s");
  35. softSerial.println(wind_speed);
  36. display.clearDisplay();
  37.  
  38. display.setTextSize(4);
  39. display.setTextColor(WHITE);
  40. display.setCursor(0, 0);
  41. display.println(wind_speed);
  42.  
  43. display.display();
  44. delay(1000);
  45. }
  46.  
  47. float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
  48. {
  49. return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
  50. }
Add Comment
Please, Sign In to add comment