Search

Senso

About the project

Senso is a device that detects deforestation using sound analysis detecting machines used to cut down trees and warning the authorities

Project info

Difficulty: Moderate

Platforms: Arduino

Estimated time: 1 day

License: GNU General Public License, version 3 or later (GPL3+)

Story

ABOUT THIS PROJECT

Overview

Deforestation is one of the most significant problems our generation faces across the world. Deforestation is directly linked to climate change as burning down organic material releases a lot of carbon dioxide, a greenhouse gas. Forests are cut down throughout the world to make space for agricultural fields and housing. Intentional fires are put to clear out the forest and illegal logging happens on an international scale.

Logging is a big concern in both developing and developed countries. This happens a lot in Romania. Although logging is regulated in Romania, a lot of the industry is done illegally. Romania accounts for 65% of Europe's virgin forests but they are rapidly going away, cut down. Most of the cutting is done using chainsaws, which emit a lot of noise.

A picture i happened to take

This is where Senso comes in, Senso is a low-powered device that is equipped with a sound analysis module that can isolate different bands of sound. The device is programmed to identify the sound of a logging machinery such as a chainsaw and alert relevant authorities when this happens. The device takes samples every 15 minutes, if an anomalous sound is detected, the device will send an event to the backend where the areas where logging took place are illustrated on a map.

With Senso, illegal logging can be combatted as authorities can be instantly alerted when logging takes place allowing them to take action faster than ever before concentrating their forces on areas where logging is most prominent.

Images

Video

Device Overview

I will be using the Arduino MKR Fox for this project. I have previously used it in a bunch of projects that rely on low-power communication due to its great low-power functionalities. It is very easy to use SigFox on this device as it is built in and Arduino libraries allow you to get up and running in no time.

In this case, I have decided to power the device through a breadboard power supply with 5v as the modules attached would drain too much power if powered by the device.

The MKR Fox

As this is a prototype, the battery life of the product is not long enough for function on the field. I am still working on turning the sensors off when the device is in sleep mode to preserve the battery.

Project Architecture

The product is split into a frontend and a backend. The frontend consists of the device on the field taking samples and the backend consists of the SigFox, Azure and Power Bi ends which process and display the data. Below is a diagram illustrating the process.

Project Architecture

Frontend

The device will wake up at defined intervals of time, it will then sample its audio analysis module 400 times getting the values of critical bands of sound. It will look out for sounds on specific bands on which chainsaws and similar machines operate. Using a mathematical calculation, it will compare the bands with each other isolating the sound of the chainsaw.

If the samples return a positive match to a chainsaw, the device will get its current location and its battery level sending these values to the cloud. The device will then go to sleep for the defined time.

A function that could be added on would be creating a tracker out of the device. The device could detect when the tree has been cut down using accelerometers turning the device into a tracker afterwards. The device could send its location to the backend every 10 minutes allowing the authorities to track the shipment

Backend

The event is received by the SigFox backend, it is forwarded to Azure IoT through a callback function. Azure IoT then assigns the data to a hub, a data streaming service queries the data and inserts it into a Power Bi dataset. Finally Power Bi extracts the data from the dataset creating a report. All the data is then displayed on a report.

Going further, a messaging application could be invoked to send an SMS to the authorities whenever an event is received by the backend. This would allow forestry workers to be able to know exactly where to go when a tree is cut down

Constructing the Project

Enough talk, let's start building the project.

Step 1: Required Materials

This project requires quite a lot of components. The list below summarises the components required for the project. The links to the components are included in the BOM above.

  • Arduino MKR Fox
  • Breadboard
  • GPS Module
  • Antenna, GPS
  • Antenna, GSM
  • Breadboard Power Supply Stick 5V/3.3V
  • 9V battery
  • DFRobot Audio Analyser Module
  • Microphone

The components

Step 2: Connecting the Circuit

This is a little tricky as we will be using the breadboard power supply. This means that we have to power the micro controller with the power. Below are the Fritzing schematics of the circuit. A downloadable version is attached at the end of the project.

The schematics

The images below illustrate the steps taken to wire the project in case you are confused.

Let's start with the device

Step 3: Acknowledging the Code

The code is split into 3 main sections, each of these is described below:

  • Get and process Sound
  • Get GPS and battery
  • Send Data to SigFox

Get and process Sound

  1. bool processData()
  2. {
  3. Serial.println("Processing Data");
  4. Serial.println("________________________________________");
  5. Serial.println("Getting Samples");
  6. Serial.println(" OK - Setting Up");
  7. bool anomaly[nrSamples]; // 6 samples will be taken of 100 reads
  8. Serial.println(" OK - Taking Samples");
  9. for(int y = 0; y < nrSamples; y++)
  10. {
  11. long valueMean[7] = {0, 0, 0, 0, 0, 0, 0}; // final data mean
  12. long avg[7] = {0, 0, 0, 0, 0, 0, 0}; // add data together to get mean
  13. for(int i = 0; i < 100; i++) // take 100 samples
  14. {
  15. int rawFreq[7]; // array for data
  16. long refinedFreq[7]; // array of refined data
  17. for(int a = 0; a < 7; a++)
  18. {
  19. rawFreq[a] = 0;
  20. refinedFreq[a] = 0;
  21. }
  22. Audio.ReadFreq(rawFreq); // get the frequencies
  23. // process the analogic data
  24. for(int a = 0; a < 7; a++)
  25. {
  26. refinedFreq[a] = max((rawFreq[a]-100),0);
  27. }
  28. // add the refined data to the variables
  29. for(int a = 0; a < 7; a++)
  30. {
  31. avg[a] += refinedFreq[a];
  32. }
  33. delay(20);
  34. }
  35. // get the mean of all the values
  36. for(int i = 0; i < 7; i++)
  37. {
  38. valueMean[i] = (avg[i] / 100);
  39. }
  40. long comparison = ((valueMean[0] + valueMean[1] + valueMean[2] + valueMean[3]) / 1.9);
  41. if(valueMean[5] > comparison)
  42. {
  43. anomaly[y] = true;
  44. }
  45. else
  46. {
  47. anomaly[y] = false;
  48. }
  49. }
  50. Serial.println(" OK - Checking Samples");
  51. // check if at least 2 of the samples signalled anomalies
  52. int anomalyNr = 0;
  53. for(int i = 0; i < nrSamples; i++)
  54. {
  55. if(anomaly[i] == true)
  56. {
  57. anomalyNr++;
  58. }
  59. }
  60. Serial.print(" OK - Samples detected with anomanies: "); Serial.println(anomalyNr);
  61. if(anomalyNr > 1)
  62. {
  63. Serial.println(" Success - Sending Warning Message");
  64. Serial.println("________________________________________");
  65. Serial.println("");
  66. return true;
  67. }
  68. else
  69. {
  70. Serial.println(" Success - All Values are Normal");
  71. Serial.println("________________________________________");
  72. Serial.println("");
  73. return false;
  74. }
  75. }

This section of code is executed when the device wakes up. The device will first take the samples of data from the sound sensor and will then process the data by comparing the value of the target frequency to the other frequencies. This is done in the following line of code.

  1. long comparison = ((valueMean[0] + valueMean[1] + valueMean[2] + valueMean[3]) / 1.9);
  2. if(valueMean[5] > comparison)

The mean of all bands except for the target one are added and divided by 1.9. If the value of the target band is bigger than the comparison, the sample is positive.

Get GPS and Battery

  1. bool getGPS()
  2. {
  3. while(Serial1.available() > 0)
  4. {
  5. if(gps.encode(Serial1.read()))
  6. {
  7. if(gps.location.isValid() && gps.time.isValid() && gps.date.isValid() && (gps.location.lat() != 0) && (gps.location.lng() != 0))
  8. {
  9. return true;
  10. }
  11. else
  12. {
  13. return false;
  14. }
  15. }
  16. }
  17. if(millis() > 10000 && gps.charsProcessed() < 10)
  18. {
  19. Serial.println("Error - GPS Module Responded with Error");
  20. Serial.println(" Terminating Code");
  21. Serial.println("________________________________________");
  22. while(1) {};
  23. }
  24. }
  25. // only gets voltage id powered through terminals
  26. void getBatteryVoltage()
  27. {
  28. analogReadResolution(10);
  29. analogReference(AR_INTERNAL1V0);
  30. int sensorValue = analogRead(ADC_BATTERY);
  31. float batteryVoltage = sensorValue * (3.25 / 1023.0);
  32. dataUnion.data.battery = batteryVoltage;
  33. }
  34. void extractGPS()
  35. {
  36. dataUnion.data.geoLat = gps.location.lat();
  37. dataUnion.data.geoLng = gps.location.lng();
  38. }

These functions extract the GPS co-ordinates from the module and verify that they are correct. They then get the battery voltage of the attached battery (if a battery is directly attached to the device).

Note that if the device is powered through VIN the battery voltage will be equal to 0 - the device must be powered through the terminals to display the voltage. To do this, connect the power pins on the breadboard to the terminals on the device.

Send Data to SigFox

  1. bool sendToSigFox()
  2. {
  3. Serial.println(" OK - Getting Values to Compile");
  4. Serial.println(" OK - Sending Data");
  5. Serial.print(" --> OUTPUT ");
  6. for(int i = 0; i < 12; i++)
  7. {
  8. Serial.print(dataUnion.bytes[i], HEX);
  9. }
  10. Serial.println("");
  11. delay(100);
  12. SigFox.beginPacket();
  13. SigFox.write(dataUnion.bytes, HEX);
  14. Serial.println(" Success - Data is Sent");
  15. Serial.println("");
  16. }
  17. void encodeData(float sigLat, float sigLng, float sigBattery)
  18. {
  19. Serial.println(" OK - Encoding Data");
  20. Serial.print(" --> INPUT ");
  21. Serial.print(sigLat, 6); Serial.print(", ");
  22. Serial.print(sigLng, 6); Serial.print(", ");
  23. Serial.println(sigBattery);
  24. Serial.print(" --> OUTPUT ");
  25. for(int i = 0; i < 12; i++)
  26. {
  27. Serial.print(dataUnion.bytes[i], HEX);
  28. }
  29. Serial.println("");
  30. }

These functions will encode the data in byte format and will then send it to the SigFox backend.

Setting up the Variables

There are two variables that have to be edited.

proDebug set to true if debugging. The device will need a serial connection and the serial monitor open to run the code if set to true. Set to false otherwise.

nrSamples will define the number of samples to take. Each sample consists of 100 readings.

Step 5: A bit on the modules

I am using a cheap GPS module I found on Amazon for €10. It is easy to use though it takes a bit of a while to lock onto satellites. A good antenna will be needed.

The focus on this section is on the audio analyser module from DF Robot. It basically collects the sound level of the 7 most prominent bands: 63Hz, 160Hz, 400Hz, 1kHz, 2.5kHz, 6.25kHz and 16kHz. After rigorous testing I was able to identify that a chainsaw was typically in the 2.5kHz 6.25kHz range. When testing with the sensor, the 6.25kHz band would spike up when playing the sound of a chainsaw.

I was then able to come up with a calculation that would prevent other machinery such as cars and natural sounds from being recognised as a chainsaw. Although not perfect, it does a great job at rejecting similar sounds.

Sound testing - the spikes show chainsaw activity

Step 6: Preparing Azure

This project will use Microsoft Azure as a backend. I am aware that most people will prefer AWS but honestly, I am a fan of Azure. There are a few prerequisites.

  • Have an Azure Account
  • Have an Azure subscription
  • Basic knowledge of the application

This step will go through setting up the account and the IoT hub that will store our data received from the device.

Step 7: Preparing SigFox

Next we need to prepare the SigFox callback, for this there are a couple of prerequisites:

  • A SigFox backend account
  • The device registered in the backend

The values that should be inserted into the fields are displayed below. Place the following in the cutom-data-config field

  1. geoLat::float:32:little-endian geoLng::float:32:little-endian battery::float:32:little-endian

Here we are basically telling the backend what data we are sending, defining that we are sending 3 floats, latitude, longitude and battery level.

Next we want to fill the JSON body of the message with the following data.

  1. {
  2. "device" : "{device}",
  3. "data" : "{data}",
  4. "latitude" : {customData#geoLat},
  5. "longitude" : {customData#geoLng},
  6. "battery" : {customData#battery},
  7. "time" : {time},
  8. "duplicate" : {duplicate},
  9. "snr" : {snr},
  10. "station" : "{station}",
  11. "avgSignal" : {avgSnr},
  12. "lat" : {lat},
  13. "lng" : {lng},
  14. "rssi" : {rssi},
  15. "seqNumber" : {seqNumber}
  16. }

This defines the values that we want to send on to Azure.

Step 8: Stream Analytics Setup

The next step is to set up the job that will query data from the IoT hub and push it into a Power Bi dataset. Prerequisites.

  • Complete all steps above
  1. SELECT
  2. latitude as latitude,
  3. longitude as longitude,
  4. battery as battery,
  5. System.Timestamp AS Timestamp
  6. INTO
  7. [OutputToPowerBI]
  8. FROM
  9. [InputFromIOTHub]

Step 9: Upload Code

Now we have to upload the code to test the connection, ensure that the stream analytics job is running and then upload the code to the device. Simulate a chainsaw sound on your phone and make the device send an event to the cloud. You should see the graphs on your dashboard shifting after you sent the data. This indicates that the data is received and you can move on.

If the event is not plotted on any of the graphs, you should start debugging with the SigFox backend and then work your way towards Azure.

Step 10: Setting Up Power Bi

We will now set up Power Bi, note that a business account is needed to assign a Power Bi subscription in Microsoft, hopefully you have access to one. Otherwise, there are plenty of alternatives that you can use. Prerequisites:

  • A Power Bi Account
  • All the steps done before

Step 11: Enclosure

So now that we have finished setting up the application we need to create an enclosure for the project. I have decided to tie the device to a tree and make it camouflaged to catch the loggers by surprise. Make sure to have the microphone outside the enclosure so it can pick up the sounds.

I had something like this

Background

I went to Romania this summer and climbed some hills. Everyone seemed mad about illegal logging and I though that there is something that I can do about it. So I looked at the problem and thought of a new approach to it. I decided to identify logging by the sound of the machinery cutting down trees, an array of devices implanted in the forest that would look out for chainsaws and alert the authorities when trees are being cut down was my solution.

I hope that countries will be able to stop illegal deforestation through the use of IoT solutions, I think that Senso is a start to finding cheap solutions to combat climate change one step at a time.

CODE

CUSTOM PARTS AND ENCLOSURES

Enclosure Schematics

SCHEMATICS

File

Schematics and circuit diagrams

Schematic

CAD, enclosures and custom parts

Credits

Photo of Arduino

Arduino

Arduino is the world’s leading open-source hardware and software ecosystem. The Company offers a range of software tools, hardware platforms and documentation enabling almost anybody to be creative with technology.

   

Leave your feedback...