Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <Adafruit_SSD1306.h>
- #include <Adafruit_GFX.h>
- #include <SoftwareSerial.h>
- SoftwareSerial softSerial(2, 3); //TX_BT --> D2 / RX_BT --> D3
- #define OLED_WIDTH 128
- #define OLED_HEIGHT 64
- #define OLED_ADDR 0x3C
- Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT);
- void setup() {
- Serial.begin(9600);
- softSerial.begin(9600);
- display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
- }
- void loop() {
- float sensorValue = analogRead(A0);
- Serial.print("Analog Value =");
- Serial.println(sensorValue);
- float voltage = (sensorValue / 1023) * 5;
- Serial.print("Voltage =");
- Serial.print(voltage);
- Serial.println(" V");
- float wind_speed = mapfloat(voltage, 0, 5, 0, 32.4);
- Serial.print("Wind Speed =");
- Serial.print(wind_speed);
- Serial.println("m/s");
- softSerial.println(wind_speed);
- display.clearDisplay();
- display.setTextSize(4);
- display.setTextColor(WHITE);
- display.setCursor(0, 0);
- display.println(wind_speed);
- display.display();
- delay(1000);
- }
- float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
- {
- return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
- }
Add Comment
Please, Sign In to add comment