By dfrobot
#44715
Dear all
I have bought an A02YYUW that I want to use for regular measurements on an ESP8266. The measured distance is to be measured every 30 minutes and transmitted to ThingSpeak. I got the sensor running on the ESP8266 via SoftwareSerial (thanks to the sample code in the wiki). I am currently using the following code:
Code: Select all
#include <SoftwareSerial.h>

SoftwareSerial mySerial(4,5); // RX, TX
unsigned char data[4]={};
float distance;

void setup()
{
 Serial.begin(57600);
 mySerial.begin(9600); 
}

void loop()
{
    do{
     for(int i=0;i<4;i++)
     {
       data[i]=mySerial.read();
     }
  }while(mySerial.read()==0xff);

  mySerial.flush();

  if(data[0]==0xff)
    {
      int sum;
      sum=(data[0]+data[1]+data[2])&0x00FF;
      if(sum==data[3])
      {
        distance=(data[1]<<8)+data[2];
        if(distance>30)
          {
           Serial.print("distance=");
           Serial.print(distance/10);
           Serial.println("cm");
          }else 
             {
               Serial.println("Below the lower limit");
             }
      }else Serial.println("ERROR");
     }
     delay(100);
}
Now I wanted to increase the delay for the measurement from 100ms, but already at 200ms the sensor does not work anymore. In the documentation I read the following:
"When "RX" floats or input High level, the module outputs processed value, the data is more steady, response time: 100-300ms; when input Low level, the module outputs real-time value, response time: 100ms."
According to this, I am probably in the "input Low Level" and therefore have real-time values. But how do I adapt the script so that one-time measurements can be made every 30 or 60 minutes?
Thank you very much for your help.
#44744
When I say wake-up, I mean to wake up the master with the clock module, because only the master can enter the sleep mode. You can go to the wiki of the clock module to find the specific usage method.