Go Down

Topic: Tipping bucket rain gauge sensor with TTGO-T-Beam (Read 144 times) previous topic - next topic



I am the new one with TTGO-T-Beam board using Arduino IDE. Can someone provide a good sketch to connect TTGO-T-Beam board (one of ESP32 board but some difference) with a tipping bucket rain gauge sensor(has two switch contacts)?

Thank you.



Aug 21, 2019, 04:36 pm Last Edit: Aug 21, 2019, 04:37 pm by septillion
No, but we can help you make code :)

Just tell us what your tried. What did you expect? What happened? Where are you stuck?
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake


Hello, I have an example code for connection between ESP32 and tipping bucket rain gauge. But when it uploads to TTGO-T-Beam which is a integrated device contains ESP32 MCU and other chips. It fails.
And this is the code:


//Original code by jurs od Arduino.cc forum for use with "tipping bucket rain gauge.
//jurs code modified 6/3/2019 @ 14:58 EDT by William Lucid, Github.com/tech500.

#define FIVEMINUTES (30*1000L) // 30 Seconds, for 5 minutes will need changed to 300000 milliseconds

#define REEDPIN 14

int count;
int hourCount;

volatile int pulseCount_ISR = 0;


void IRAM_ATTR reedSwitch_ISR()
    static unsigned long lastReedSwitchTime;
    // debounce for a quarter second = max. 4 counts per second
    if (labs(millis()-lastReedSwitchTime)>250)

void setup() {

  attachInterrupt(digitalPinToInterrupt(REEDPIN),reedSwitch_ISR, FALLING);  // <----- changed to this line

unsigned long lastSecond,last5Minutes;
float lastPulseCount;
int currentPulseCount;
float rain5min;
float rainHour;
float rainDay;

void loop()
  float rainFall;
  // each second read and reset pulseCount_ISR
  if (millis()-lastSecond>=1000)
      currentPulseCount+=pulseCount_ISR; // add to current counter  <--changed to this line
      pulseCount_ISR=0; // reset ISR counter
      rainFall = currentPulseCount * .047;
      Serial.print("Rainfall:  " + (String)rainFall);Serial.print('\t');Serial.print("Dumps during 5 Minutes:  " + (String)currentPulseCount);

    // each 5 minutes save data to another counter
    if (millis()-last5Minutes>=FIVEMINUTES)
      float daysRain;
      rain5min = rainFall;
      rainHour = rainHour + rainFall;  //accumulaing 5 minute rainfall for 1 hour then reset -->rainHour Rainfall
      rainDay = rainDay + rainFall;  //Only 1 hour
      daysRain = daysRain + rainDay  ;  //accumulaing every hour rainfall for 1 day then reset -->day total
      //Serial.println("5 Minute Rainfall:  " + (String)rain5min);
      Serial.println("Hourly rainfall rate:  " + (String)rainHour);
      Serial.println("60 Minute Accumulating:  " + (String)rainHour);
      Serial.println("Day Rainfall:  " + (String)rainDay);
      last5Minutes+=FIVEMINUTES; // remember the time
      lastPulseCount+=currentPulseCount; // add to last period Counter
      currentPulseCount=0;; // reset counter for current period
      Serial.println("count:  " + (String)count);
           if(count == 3) //End of 1 hour  (for testing 90 Seconds); otherwise, count = 20 for real 1 hour.)
               rainFall = 0;
               rainHour = 0;
           if (count == 6)  //End of 1 day  (for testing 180 Seconds); otherwise, count = 24 for real 1 hour.)
              rainFall = 0;
              rainHour = 0;
              rainDay = 0;
              daysRain = 0;
              count = 0;         


Whether TTGO borad has the same controller system with ESP32 but cannot upload the same program? After I have changed pin set.


It fails.
A little more detail would help a lot.  What does "fails" mean?  Fails to compile with some errors?  Post the complete and entire error message(s).  There is a copy errors button in the IDE (lower right).  Copy the errors and paste into a post (in code tags).  Or does "fails" mean compiles but fails to upload?  Or does "fails" mean that the code compiles and uploads but fails to do what you want?

Read the how to use this forum-please read sticky to see how to, properly, post code and some advice on how to ask a good question.  Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.


Sorry. As 'It fails', I mean when uploaded the same programy on TTGO board instead of ESP32 board, no errors in this uploading process.  the counter of rainfall rate is always '0'. Which means the board did not receive any command to control the rain gauge sensor. So I want to know whether and how can I change the program and make it suit for connection between TTGO board and rain gauge sensor.

Go Up