Menu
Cart 0

Bat-mail: Email alerts with the Bat Detector

Posted by Matthew Little on

This post covers a bit of an experiment I tried using both our bat listener kit and the cheeseboard (an ESP8266 development board). I wanted to make a unit that would send me an email whenever a bat was detected in my garden.

This would be based upon the ESP8266 and monitor the output from the bat listener kit we sell. This was just a bit of fun, but might have some useful applications for remote monitoring...

I basically just needed to connect the micro-controller output from the bat listener to a GPIO pin on the ESP8266. I needed to ensure it uses a 3.3V zener on this output (rather than the supplied 5.1V zener) or else there will be too high voltage here.

Parts required:

I used D1 (GPIO5) on the ESP8266 board to take the output from the bat listener and count the pulses. (Note: D0, which I tried originally, does not work with interrupt service routines and caused issues).

I needed to provide a 9V DC supply for the bat listener board. I was using 5V for the ESP8266, so I bought a low cost DC-DC step up converter, based on the MT3608. This takes 5V and boosts to 9V, which is set by a small potentiometer. Set this to 9V first before attaching it to the bat listener board! I use a bit of nail varnish to hold the potentiometer in the right place and stop it getting knocked and adjusting the voltage.

The code is relatively simple (and quite hacky!). It uses WiFi manager to connect to WiFi, or create an access point to add WiFi credentials.

Once connected then it has a ISR (Interrupt Service Routine) which runs whenever there is a pulse from the bat listener. This just increments a counter. Every second this counter is checked and if it is over the trigger level value then it will send an email with the value of the counter.

The counter value might give an indication of the species of bat, but that needs a lot more work!

Counting Pulses

I needed to count the incoming pulses from the bat listener. These are stepped down in frequency by a factor of 7 (?) times (due to the circuit in the bat listener). This means a reading of 1kHz would actually be 7kHz.

I decided to implement this by using an ISR) which increments each time a pulse is detected. Every sample period this is checked and then reset. This value is used to figure out if a bat has been detected or not.

I found a couple of tutorials for implementing interrupts on the ESP8266:

Using the these tutorials, attaching an interrupt was relatively simple, requiring just:

attachInterrupt(digitalPinToInterrupt(BAT_TRIGGER), detectPulse, RISING);

And then also added a ISR which runs on trigger, which was:

ICACHE_RAM_ATTR void detectPulse() {
bat_pulses++;
}

This worked well and gave a count of pulses from the detector within the previous time sample.

Detection Algorithm

This needed a bit of error detection and clever analysis to ensure that there were not false triggers, but also that the bats were correctly detected and that not too many emails were sent (I didn't one for every detection if the bat is flying around in circles nearby for an hour!).

So there were two tests to check whether to send an email or not:

First the frequency within a sample period needed to be high enough to highlight a bat had been detected.

Second was that there would be no additional bat detections within a detection window. Once that time is up then the unit will send an email, along with the number of detections within the window and how long the bats were detected for.

Sending an Email on ESP8266

I found the EMailSender library from xreef. This can be installed via the Arduino Library manager.

This needs a few things:

  • You need to set up an email account (I used gmail) and change it to be less secure, as you will be accessing it via an older SMTP protocol. You will need the email address and password for this account.
  • You also need the email you will be sending to.

I entered in these values into the example code and it worked straight away! Good little library!

NTP Time

I wanted to add a time stamp to the email so that I knew when the bats were detected. An example for this was found in the Time examples, which included: TimeNTP_ESP8266WiFi.ino which I used as the example here.

Code Repository

I've put the example code here for anyone who might want to experiment with it a bit:

https://github.com/curiouselectric/BatDetectorEmailer

Prototype Testing

I put the equipment in a waterproof enclosure. The ultrasonic detector stuck out of the base of the unit to stop rain going into the unit. I hope to use a small piece of plastic to reflect the ultrasonic pulses up into the detector.

Future Work

Ideally this unit would be solar powered and use some sleep modes, but that's for a future design...


Share this post



← Older Post


Leave a comment

Please note, comments must be approved before they are published.