Hi, I wish to read the level of the water tanks on my property remotely, I was able to do on site via my router using a using an HC-SR04. However, water damage to the sensor prompted me to replace the sensor with an A02YYUW . I have used the sketch you supplied on your web page and it works ok.
The problem is I cannot get the sensor to work on an IP address! It will work on the serial monitor ok, but I cannot get it to print to my PC. I am a novice at this coding business however, despite my age I am determined to get it going. Are you able to suggest any ideas or at least point me in the right direction. I have included the code I wrote initially (with some help from online research) for the HC-SR04
Many Thanks
[//Measurement of distance to water level in Shed Tanks
#include <SPI.h>
#include<Ethernet.h>
#include<b64.h>
#include<SoftwareSerial.h>
//MAC Address
byte mac [] = {0xDE,0xAD,0xBE,0xEF,0xFE,0xED};
IPAddress ip(192, 168, 0, 209 );
EthernetServer server(80);
//Define connections to the sensor
int pinRX = 6;
int pinTX = 5;
//Array to store incoming serial data
unsigned char data_buffer [4] = {0};
// Integer to store distance
int distance = 0;
// Variable to hold checksum
unsigned char CS;
// Object to represent software serial port
SoftwareSerial mySerial(pinRX, pinTX);
void setup() {
// Set up serial monitor
Serial.begin(9600);
Ethernet.begin (mac);
server.begin ();
server.println ("Distance to water level");
Serial.print ("Server started on: ");
Serial.println (Ethernet.localIP () );
//Set up software serial port
mySerial.begin(9600);
}
void loop() {
// Run if data available
if (mySerial.available() > 0) {
delay(4);
// Check for packet header character 0xff
if (mySerial.read() == 0xff) {
//Insert header into array
data_buffer[0] = 0xff;
// Read remaining 3 characters of data and insert into array
for (int i = 1; i < 4; i++) {
data_buffer[i] = mySerial.read();
//Compute checksum
CS = data_buffer[0] + data_buffer[1] + data_buffer[2];
//If checksum is valid compose distance from data
if (data_buffer[3] == CS) {
distance = (data_buffer[1] << 8) + data_buffer[2];
//Print to serial monitor
Serial.print("distance: ");
Serial.print(distance);
Serial.println(" mm");
// Listen for incoming clients
EthernetClient client = server.available ();
if (client)
while (client. connected () );
delay (1000);
}
}
}
}
}