Software apps and online services

Hand tools and fabrication machines

3D Printer (generic)

Soldering iron (generic)

Story

“It’s For The Birds!” Reinventing the Future of Eco-monitoring with the Arduino 101

Introduction and Motivation:

One way to measure the health of our climate and the ecosystem we live in is by measuring the size and variety of its’ fauna or animal population. Every winter, since 1987, the Cornell Lab of Ornithology conducts a massive citizen science effort called Project FeederWatch:

This is our first year participating and we wanted to combine our interest in making and hacking, with our interest in nature and our participation in Project FeederWatch. So we decided to reinvent our future of bird watching and environmental monitoring with the Arduino 101!

The Arduino 101 is ideal for this project because it combines the simplicity of the Arduino IDE to make our embedded programming easy, onboard capabilities such as Bluetooth LE with a wealth of sensors and breakout boards readily available. By embedding an Arduino 101 in a homemade bird feeder, we developed an experimental platform to measure weather parameters and monitor bird activity at our feeder. Adding in some exciting IoT technologies from Cloudinary and PubNub helped us to reinvent the future of environmental and ecosystem health monitoring!

Project Overview:

Graphical overview of the project.

The heart of our project is an Arduino 101 embedded in a homemade bird feeder. We use 2 Sharp infrared distance sensors to detect birds perched on a wooden dowel running through both sides of the feeder. A force sensitive resistor(FSR) is used to sense the amount of seed present in the feeder. An Adafruit Si7021 temperature and humidity sensor breakout board is attached to the i2c pins and is used to provide our physical weather data.The Arduino 101 is set up to act as a BLE peripheral device and send data from these sensors over BLE to a BLE central device. Power is provided by 4 AA batteries. All of these components are housed in a custom 3D printed enclosure.

We use an Intel Edison on the Arduino Breakout Board both as the BLE central and as an internet gateway. A logitech c270 usb webcam is connected to the usb port on the board and used to take pictures when a BLE notification is received that indicates activity on one of the perches. These images are stored locally on a SD card inserted into the SD card slot on the breakout board.

We take advantage of the Intel Edison’s WiFi capability to use it as an internet gateway. This allows us to use super technologies such as PubNub for real time data streaming and Cloudinary for image storage and manipulation in the cloud.

The bird feeder is made from an empty soda bottle and a wooden dowel and hung it from a post in our yard.

Building the Project:

Arduino 101 the embedded bird feeder.

The foundation of this project is an Arduino 101 embedded in our bird feeder. The bird feeder will be outdoors and need to be able to withstand the physical rigors of being outdoors. It will need a way to transmit data real time and wirelessly. The distance between the transmitting Arduino 101 and the receiving Edison is only few feet and since the Arduino 101 already has BLE onboard, we’ll use BLE!

Most of the circuit can be constructed by following the fritzing diagram , but there were a few challenges we ran into while making and testing this circuit. It is those we will concentrate on here:

The first challenge: Detecting a bird on the feeder, outdoors! For this project we need a sensor that will be able to function outdoors, sealed away against the elements. We don’t want it to disturb or scare away the subject. It should only detect what is on the perch. After evaluating the characteristics of various sensors, we decided to use the Pololu Carrier with Sharp GP2Y0D815Z0F Digital Distance Sensor. These sensors, unlike the regular PIR sensors, have a very short range of detection. We only want to know if a bird is perched a few centimeters away from the sensor. The PIR sensors have a very long and broad range of detection. This is great for sensing any kinds of motion in the driveway of your house, but we don’t want the detect tree branches or other “noise” every time the birdfeeder sways in the breeze. Also a quick bench top evaluation showed that the Sharp IR sensors worked when placed inside a plastic soda bottle. This is important because we need to protect the electronics from the elements and be able to “see through” this part of the enclosure.

The third challenge: In the Related Activities and Learning section of The Project FeederWatch website one of the activities recommended is to weigh the bird seed in your feeder before and after each count and compute how much seed was eaten. After several counts, calculate average consumption rate. Instead of performing manual weights, why not capture seed consumption in an automated manner? Our solution was to use a force sensitive resistor(FSR). This is a resistor with a resistance that varies with the force applied to it. It can be connected to an analog input pin. But would it be sensitive enough to detect changes in seed amounts? Our first attempts to measure seed levels in a small plastic container were not very successful. The sensor responded well to varying finger pressure, but not to the seed levels. So we made two changes to solve the problem. First, the analog signal is delivered to the Arduino 101 analog pin through a 2 resistor voltage divider, one being the FSR the second being a conventional resistor. We lowered the value of this second resistor and the sensor seemed to be more sensitive to touch, but it still was not as responsive to seed changes as we would like. So added in a hardware change to all this. Somewhat by analogy to Pascal’s principle, that if instead of applying the weight of the seeds over the entire surface of the FSR, we created a platform with a small point of contact at it’s center, we would greatly increase the force from the seed on the FSR. Just the opposite of a snowshoe and it worked!

The Force Sensitive Resistor is seen here on the top of the custom enclosure. To the left is the pressure plate.

One other minor challenge is connected the FSR to the Arduino 101 in a secure and dependable manner. This is easily solved by the use of 2-pin 3.5mm terminal blocks. Just make sure the spacing of the terminal block matches that of your board.

This is a side view of the Arduino 101 circuit and enclosure. This shows the Sharp IR sensor and the terminal block connected to the leads of the FSR. The point of pressure, pressure plate is seen on top of the enclosure.

The rest of the Arduino 101 hardware is simple. We connected the Adafruit Si702 breakout board to the I2C bus pins() and used the empty +3.3V for power. Power the the entire package is provided through a 4XAA switchable battery pack housed underneath the main enclosure.

We soldered the IR and FSR sensors to Adafruit Perma-Proto Quarter-sized Breadboard PCBs and attached them to the underside of the Arduino 101 with double sided tape. The entire package is placed inside the soda bottle bird feeder and has survived sub-zero freezing temperatures, mist and light rain and snow( fake blizzard ‘Stella’!).

Arduino 101 Sketch:

The main job of the sketch is to monitor the attached sensors and report the values of the sensors over BLE. All data in BLE is transmitted as a package of bytes. Whether your original data is an int float of array of char, you will have to break it down into its byte representation to transmit over BLE. The easiest way I know of doing this, is to create a union of datatypes. A union allows us to share the same memory location between two different data types. In our case the SI7021 temperature and humidity sensor provides data as a floating point number. The Arduino C language represents a float as 4 bytes, so we create a union between our temperature float and humidity float and an array of 4 bytes.

When we store the floating point value in the union, the byte array is populated as well. In order to transmit the data, we pass the array of bytes to the setValue() function of these characteristics.

For embedded applications, the use of the delay() functions can cause problems. First, while the delay function is called, all processor activity comes to a stop for the period of the delay. This is not ideal when birds can come to perch at any time. A second issue is that the delay() function may cause issues with the BLE notification mechanism. The way to avoid this is to not use delay() in our sketch. There are however, many times a delay in code program will be needed. To overcome this, we will use the method outline by in this set of 3 super tutorials by Bill Earl of Adafruit.

In outline, we create an object representing our embedded device. We decide on an interval or set of intervals to poll our sensors connected to this device. We then create an Update() function.

This function serves to check if the time intervals for our sensors has passed, if so, update the sensors, if not just ignore them. The Update() function is called repeatedly in the loop() section of our sketch.

The most challenging part of working with the Intel Edison is getting it setup. The best tutorial I have found on this is Vincent Wong’s Intel Edison and Intel XDK IoT Edition 101. I can guarantee you that going through this process and trying some of the JavaScript examples is well worth it!

Working with your Edison using the Intel XDK IoT edition will allow you to interact and configure it on the command line. You will also be able to take advantage of the many JavaScript/Node example programs and templates. Learning and using JavaScript/Node to program will open up a large number of easy to use and powerful APIs, such as PubNub, Noble.js and Cloudinary.

Once you have setup the Edison and confirmed an active connection to your WiFi network, you can install the libraries necessary for this project:

npm install noble

npm install pubnub

npm install cloudinary

The USB Webcam

A google search of "intel edison webcam" will yield several fine examples and tutorials. But there is some confusing material out there, which I believe is mainly due to some changes in the modules available in the Yocto OS. Yocto is an embedded version of linux that runs the Intel edison. The Logitech c270 is a uvcvideo compatible webcam. There are numerous tutorials on ensuring that your Edison has the uvcvideo driver/module installed. Without this, you won’t be able to interact with and take pictures with the camera.

To work with webcam and to make photos on schedule we have to install 2 additional packages:

opkg install fswebcam cronie

*** note we did not install cronie for this project, we just did opkg instal fswebcam. cronie is not needed as we call fswebcam whenever the IR sensors are tripped by a bird on a perch, not on a timed schedule ***

Working with camera

To test your camera, run this command:

fswebcam -r 1280x720 --jpeg 100 -D 3 -S 13 "test.jpg"

-r 1280x720 set resolution of image, it’s better to use maximum available for your camera (optional)

— jpeg 100 set JPEG quality to maximum. It’s useful if you are going to do something with these images later (optional)

-D 3 -S 13 adds 3 second of delay and skips first 13 frames. It’s necessary, because some webcams need time to get best photos (recommended)

test.jpg is the name of output file "

Additional information about using a webcam with the Edison, and other really neat projects, can be found on Dr. Kim's github page. She also posts cool projects to Hackster.io as well!

In addition to confirming that the proper module was present, I also needed to flip the switch between the microusb cables and the USB port towards the direction of the USB port and attached the Arduino shield to a power supply. I used the Compact Switching Power Supply - Selectable Output 3-12VDC (Adafruit product id: 1448).

Move switch towards usb port in order to use the usb camera.

Now place your SD card in the SD card slot. Using the Serial Terminal in the Intel XDK, use the command line to check the card by entering the following commands:

cd /media/sdcard

ls

This should display any files present on the card, or nothing if there are no files present. You should not see any error messages. If you do see errors messages, I recommend rebooting the Edison board without removing the SD card by entering this command:

reboot

Then repeat the commands above after logging back onto your Edison.

Now, to allow our Edison to access Bluetooth, enter the following command:

rfkill unblock bluetooth

To confirm that bluetooth is on and functioning, enter:

bluetoothctl

Then type

scan on

This should shownearby BLE devices as such:

Screen capture showing how to enable BLE on your Edison.

Now exit out of bluetoothctl, and click on the Intel XDK IoT tab then connect to your board. Select a project from the left hand side menu, such as BLESCAN. Gut out the contents of index.js and remove the dependencies from the package.json file.

Replace the contents of index.js with the program from our github repository here. Upload this code to your Edison. Make sure the Arduino 101 is turned on and run the Edison code. Once the Edison has detected your Arduino 101 you should see something like this:

Demonstrating a solid BLE connection with data streaming!

The Code:

The code running on the Edison is written in JavaScript or more properly Node.js. After creating the necessary objects from our imported libraries, we will create variables to represent the BLE service that is running on the Arduino 101.

These UUIDs will be used by noble.js. If you change the UUID's on your Arduino, they must be changed here as well. It is important to make sure you have no dashes for noble.js to work properly.

In order to work with noble.js we will have to scan for peripheral BLE devices and then discover them and then connect. Once connected we will will run through the characteristics available to use, using the UUID define above. The characteristics are all read/notify characteristics.

There are 2 key elements to point out from the code section above. First, there was a change in the how you tell noble.js this is a read/notification characteristic. From Sandeep Mistry's github page:

Data

Emitted when characteristic read has completed, result of characteristic.read(...) or characteristic value has been updated by peripheral via notification or indication - after having been enabled with notify(true[, callback(error)]) .

The change is from 'read' to 'data'. We ran into some problems here inadvertently using an older version of noble and then changing the the newest version. It took many hours to figure out what happened, so we wanted to potentially help you avoid this

The other key here is the function transformRawData(characteristic.uuid,data). This function takes the uuid and data delivered from the read and passes it off to the large and unwieldy function. Each time the BLE notification mechanism is activated by a change in a characteristic this function is called and it handles the data received. This is where all the excitement occurs.

tranformRawData checks to see what characteristic is received.

In the case the Arduino tells us there is activity on the perch, we want to take a picture. In this case, we use the child_process library to make a call to the program fswebcam which resides in out Yocto(linux) system. The child_process library allows us to execute command line functions from within our node.js code. This is a very powerful feature.

This function is also where PubNub and Cloudinary come into play! PubNub provides a real time data streaming network to your application. What this means is that with an internet connection your application can live stream data anywhere in the world. Any other app or program that has the subscription key to your published streams will have access to a JSON payload representing your data. In our case we send the current seed level, temperature, humidity and perch visit counts. Additionally, we send a link to the 3 most current pictures of the feeder! These are jpegs which have been uploaded to Cloudinary with our program. There is no need to run a server! A simple HTML file with embedded JavaScript serves as a real time interface to our bird feeder courtesy of PubNub!

Laptop and Chromebook running with same HTML page simultaneously receiving real time updates from the bird feeder.. Thanks PubNub!

In the picture above, the I simply e-mailed myself the HTML file containing the code to interface with the bird feeder over PubNub and loaded each from a local directory into a Chrome browser. There is no need for you to code a server to serve up this page on your Edison.

Cloudinary is an image upload, storage and transformation service. Its has a very simple to use api. In developing this project, I could not find an easier, more straightforward api to use. There is nothing comparable out there. Their help desk is fantastic as well. It is definitely something you will want to check out for your projects!

In the code below we use the cloudinary api to upload the 3 latest images from the local SD card. The URL returned from this upload are then saved in an array. These URLS are then sent as part of our JSON payload to PubNub so that they can be accessed by our HTML page to display. Beauty, eh?!

index.html

What is this index.html file all about? The index.html file is our UI. Since we are streaming our data using PubNub and placing our images in a publicly accessible URL with Cloudinary, we can take advantage of the Javascript/HTML/CSS power trio to create a portable UI. Both PubNub and Cloudinary have very easy to use and powerful Javascript APIs. We simply import them into our html file to use them:

After signing up for PubNub, go through a few of the tutorials and learn how to get your pub and sub keys.

We don't need to instantiate a Cloudinary object in this code to display the most recent 3 images on the UI. Our PubNub stream sends the URLs of these images in the JSON payload. We simply subscribe to the channel, 'feederview' on our stream "decode" the payload and update and display the images:

PubNub has a special library to ease graphical data display. It is called eon.js. It is easy to use and there are many good tutorials an excellent webinar on its use. I recommend going through these to understand how we created our data display widgets.

Bird Feeder and Enclosure:

Building the bird feeder is pretty easy. For the construction of the feeder, I started by cutting a perfectly straight line on a 2 liter soda bottle about 11 cm high using a boxcutter. I then cut holes about 3 cm high on the bottom piece where I slid a wooden dowel through that would act as a perch. I then put the electronics package in, to test the size, and it was a snug fit. For the top part, I began by poking small holes just below the bottle cap and inserting a metal wire about 30 cm long and tied a knot on the top. Then I cut four holes on each side, all different heights to fit the different size birds, and to get the smell of the seed out to attract more birds. Finally, I slid the top part into the bottom and secured it with masking tape, making sure that the tape didn’t cover the sensors. Although I chose to use masking tape, clear packaging tape would also work. When everything was secure and set, I filled the seed up using a funnel and put it outside and waited for the birds to come.

Designing the pressure point plate to interact with the FSR in Autodesk Fusion 360.

For the bottle enclosure birdfeeder, I first measured the diameter of the bottle by taking the label, finding the length (the circumference) and dividing it by pi. The bottle turned out to be about 105mm in diameter and I based the whole package around this number. I started by making a case that could hold the arduino and the two breadboards, and a top that had a handle so it would make it easier to pull the package out. I also made a small case on the bottom that could hold the battery pack, and I designed it in such a way that I was able to save half the filament that I might have used other wise. We decided to go even further with the pressure sensor so I created a top that also saved filament while having the same rigidness.

All the components in Autodesk Fusion 360 before 3D Printing.

Finally, I printed the plate that would help the pressure sensor and screwed all of the pieces together. The result was a compact package that functioned very well:

Building the project for testing.

A red light, it sees the hand!

All ready for pre-deployment testing.

And this is what it looks like for deployment!

Testing it Out:

We tested the feeder prior to feed deployment. There are several critical areas of functionality to this project and we tested them systematically prior to our deployment.

First we confirmed BLE connectivity in 2 parts. First, we confirmed the proper functioning of the Arduino 101 to send notifications over BLE using the nRF Master Control App. I have found this to be a reliable and indispensable tool for debugging my BLE projects. Next we confirmed that we could receive signals from outside the house well beyond the range we intended to place the feeder. Once the Edison was ready we reconfirmed this. Using this approach allowed us to focus one thing at a time. While this is not an ultra complex project, it has enough pieces to cause confusion if you don't take it step-by-step. One thing we found out was that when the batteries ran low, the first function to be be lost was BLE.

We also did some calibration of or our FSR and found some interesting results. With our point of contact platform we found a linear range, within an overall non-linear response to adding seed:

Calibrating the FSR. Let the citizen science begin!

For now, we just used these values to adjust our min/max and color ranges on the Eon.js feeder gauge, but we will explore this in the future so we can accurately estimate feeding.

Average of 3 FSR readings recieived over BLE vs. Cups of Feed placed in Sensor.

Deployment Gallery:

The best part of this project has to be reviewing the pictures! You can do this either online in your Cloudinary dashboard or by looking a the files stored on the SD card. Once the birds discover your bird feeder you can easily generate 2,000 jpegs in the space of a few hours! This is no exaggeration!

Testing the Perch IR Sensor! It works!

House finches sharing some perch space.

A cardinal enjoying a meal during Stella! Yes the Arduino 101 works in a snow storm!

Coming in for a landing.

Action shot!

Dine & Dash!

Wings spread and female cardinal in foreground.

Beautiful Wings!

One last one of everyone's favorite, the cardinal.

Note on alignment with project FeederWatch.

Seeed What the Future Will Bring!

We have already begun to redesign and test our circuit using the SeeedStudio kit. We did not enter the contest in time to qualify for the free hardware, but we get a Grove Starter Kit on our own. Very importantly the power supply of the Base Shield allows us to use both Sharp IR sensors WITHOUT the supporting capacitors! Both sensors function very well with them. An additional benefit as you can see from the picture below is the greatly simplified the layout. This is for a bird feeder and not a birds nest! We probably should have started our prototyping with the SeeedStudio Grove kit!

On the left is the new bird feeder circuit created using the Gove kit, on the right is our original project. No more capacitors and bird's nest wiring with the Grove Kit!

The standard infrared sensor from Seeed was not the same as the Sharp IR sensors we used, so we made modified our sensors slightly to be compatible with the base shield. Simply by soldering in solid core wire to the GND, Vin and SIG lines of the IR sensor we were to connect:

This shows our simple modifications to make the Sharp IR proximity sensor compatible with the Seeed Studio Base Shield connectors.

Alignment with Project FeederWatch & Conclusion

Our original inspiration for this project was joining Project FeederWatch for the first time. So how does our IoT feeder alignment with the goals and measurement method of Project FeederWatch?

When you sign up for Project FeederWatch, this is the awesome kit you get!

Project FeederWatch has a specific and validated methodology for their bird count. Over the period of 2 consecutive days, you report the maximum number of birds of a certain type seen at one point in time. So our perch counts don't really match up with this. However, measuring environmental parameters and automating our seed consumption definitely does. Also taking stills of the birds visiting our feeder helps us learn identifications. Also, if a "rare" bird were to visit we would have the photo documentation required to document this visit.

The potential of live streaming the data over PubNub's network is huge. Data and images could be shared among bird watchers and classrooms around the world, live and realtime! One area we would like to explore is the clarifai block in PubNub. Could we send stream the image stored at cloudinary to clarifai to add image detection of birds and bird types in our images? Could we use the PubNub cloudinary block to help correct for poor image quality due to variable weather conditions? What other Seeed/Grove sensors could we add?

As geek makers, this project also was a lot of fun. We really enjoyed watching the birds live at the feeder and then going back to see what kind of pictures we captured was like a mini treasure hunt! Seeing the feed data decrease throughout the day, as we literally collected thousands of jpegs was just super fun. And using arduinos, edisons and improving it with the Grove and using the web technologies of PubNub and Cloudinary to all work together was just a great challenge for us. . .oh yeah and did we mention the 3D printing?

We hope you will be inspired to sign up for FeederWatch and agree with us that in the end . . . Its for the Birds!