Interfacing Waterproof Ultrasonic Sensor JSN-SR04TAJ-SR04M with Arduino

Поделиться
HTML-код
  • Опубликовано: 13 дек 2024

Комментарии • 1

  • @raystonrizwan7800
    @raystonrizwan7800 6 месяцев назад

    please i need some help with the dwin hmi project 🙏 😢...i already have a project water level indicator and controller displays parameters on 0.96' oled using esp32..i want to display the same parameters on dwin hmi i can make UI and everything else now how can i display this data on dwin...will this code work
    #include
    // Define the RX and TX pins for the Serial2 connection
    #define RXD2 16
    #define TXD2 17
    // Initialize Serial2 for DWIN display
    HardwareSerial mySerial(2);
    void setup() {
    // Initialize the default Serial monitor for debugging
    Serial.begin(115200);
    // Initialize Serial2 for DWIN display communication
    mySerial.begin(115200, SERIAL_8N1, RXD2, TXD2);
    }
    void loop() {
    // Simulate reading the water level; replace with actual sensor code
    int waterLevel = getWaterLevel();
    // Send the water level to the DWIN display
    sendWaterLevelToDWIN(waterLevel);
    // Delay for 1 second before sending the next value
    delay(1000);
    }
    // Function to simulate reading the water level sensor
    int getWaterLevel() {
    // Replace with actual code to read the sensor value
    return analogRead(34); // Example analog pin for water level sensor
    }
    // Function to send water level data to the DWIN display
    void sendWaterLevelToDWIN(int level) {
    // Format the command according to DWIN's protocol
    byte command[] = {0x5A, 0xA5, 0x05, 0x82, 0x00, 0x10, (byte)(level >> 8), (byte)(level & 0xFF)};
    // Send the command to the DWIN display
    mySerial.write(command, sizeof(command));
    }