#include <ArduinoRS485.h>
#include <Arduino.h>
#include <RingBuffer.h>
#include <SoftwareSerial.h>
#include <RS485.h>
// Defining pins
#define DE 2
#define RE 3
void setup() {
// Initialize Serial communication
Serial.begin(9600);
// Set DE and RE as output
pinMode(DE, OUTPUT);
pinMode(RE, OUTPUT);
// Set DE and RE to LOW initially (receive mode)
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
Serial.println("Setup complete, entering loop...");
}
void loop() {
// Ensure DE and RE are set to LOW for receive mode
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
delay(10); // Small delay to stabilize after mode switch
// Check for available data
if (Serial.available() > 0) {
String data = Serial.readString(); // Read the incoming data
// Print the received data to the Serial Monitor
Serial.print("Received Soil Moisture Data: ");
Serial.println(data);
} else {
// Debug statement if no data is available
Serial.println("No data available.");
}
// Optionally, switch to transmit mode
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10); // Small delay before switching back to receive mode
delay(1000); // Wait a second before the next loop iteration
}
I am not getting any reading from the sensor at all even though the TX RX lights are blinking on my Arduino UNO R4 Wifi.
My serial monitor only says "No Data Available"
Please note that unlike the circuit diagram I have connected DE to PIN 2 and RE to PIN 3