Project tutorial

Eco-Thing #1 "Eco-Smart-Container V1.0" © GPL3+

An IoT device that could help keep the Sandy River Delta clean, as garbage is a very common problem.

  • 7,133 views
  • 4 comments
  • 29 respects

Components and supplies

Necessary tools and machines

Hy gluegun
Hot glue gun (generic)

Apps and online services

About this project

Introduction

The Sandy River Delta is located near Troutdale, OR at the Confluence of the Sandy River, and the Columbia River. The “Delta” recreational site is East of the main stem of the Sandy River, North of the I-84 freeway, and bounded to the North by the Columbia River. Also known as 1000 Acres it is large enough for a good multi-hour outing only 20 minutes from downtown Portland.

The Delta is a mixed use / Multi user accessible area and is part of the Columbia River Gorge National Scenic Area and also has a closed to Protect Wildlife Habitat.

It is a multi-use area open for all types of non-motorized recreational activities including Hunting, Fishing, Horse Riding, Dog Walking, Cycling, and just a great place to be out in Nature.

As a multi use area, it is important that all users respect the area and other users. Despite appearances, the Delta is not a “Dog Park”. Dog walkers should be aware of the other users of the area, and likewise, other users should be aware of the presence of off-leash dogs.

The Idea

I chose this category because I am a nature lover and conservation actions look great to me. I hope I can help.

I am currently working with the Arduino 101 board and its potential to give it connectivity to the objects of daily life by means of bluetooth low energy.

I did an investigation about the place on the website:

http://fsrd.org/

http://envirogorge.com/sandy-river-delta/

http://sandyriver.org/#

In these web pages I found information about the history of the place, its climate, the activities that are carried out and geographic information.

The flora and fauna of the place can be checked in the following document:

http://sandyriver.org/wp/wp-content/uploads/Sandy-River-Species-Guide.pdf

Because the area is visited daily by many people, the problem I observe is that the level of waste and trash control has to be too low, and I want to improve that aspect. Garbage around the world has been a problem that generates many environmental damages. And the goal is to protect the species that live there.

The prototype I want to develop is a trash can with low energy bluetooth connectivity that provides data such as garbage level, meteorological data such as temperature, soil moisture, boat orientation status data to a central hub in My case is a raspberry pi zero w connected with the Blynk platform. We created an application for smart phones where you can observe the state of the sensors and also offers notifications depending on the state of the sensors. The main objective is that when the level of the trash can has a level of trash to the maximum, this sends a notification to all the users of the application and they make the collection and the cleaning of the place. Thus the place will remain in optimal conditions for the flora, the fauna and the visitors.

Above I show the diagram of my prototype, at the end I could only build a trash can because of the lack of components and arduino 101 boards, but making one is enough to show that it works.

Material

1. SparkFun Inventor's Kit for Arduino 101

This material was given to me by the sponsors of the contest, I thank you for the trust and support. This material contains the plate you use and the temperature sensor TMP36 that I use to measure the temperature.

To test the circuits you were using, use the Arduino and Breadboard Holder. The arduino 101.

2. Grove Shield

This shield is perfect for prototyping and connecting components exclusive to the Grove platform.

3. Grove LCD I2C

This screen can be connected through the I2C port of the Arduino 101 and you can change the color of the lighting and it has a very nice design.

4. Raspberry pi zero w

This board has all the advantages of raspberry pi zero but with the addition of bluetooth 4.0 connectivity and wi-fi, use it to receive arduino sensor values by means of bluetooth. Programming in Node Js was a very enjoyable, intuitive and effective experience.

5. DHT22

This digital sensor of humidity and temperature is very used and has good results, this one uses it to measure the temperature and humidity near the central device that is the raspberry pi zero w.

6. Ultrasonic sensor

This sensor I used to measure the level of trash in the trash can, had good results, but probably in an update can be changed by a sensor or infrared sensor in my opinion seem more reliable but in my country it is difficult to achieve components as sensors.

7. Moisture sensor

This sensor used it to measure the level of humidity in the earth, any high reading of humidity means that there could be rain or some flood and that could be a problem for the garbage of that place, sends a warning to the application.

8. Solar battery bank

Any project needs power, my prototype I put this power bank of 12000mAh, which also recharges solar, ideally would have a panel built especially for my prototype. But this device worked great. I used 2 for raspberry pi zero w and arduino 101 in my smart trash can.

9. Arduino 101 6-Axis Acelerometer and Gyroscope

To know if my trash can had fallen, or someone threw it on the floor. Use the accelerometer and gyroscope included in the Arduino 101. It was easy to implement and send the data to the central base.

Results

In the physical aspect of the prototype I will show some images and explain the why of each thing. Below we have the top of the trash can that has the LCD grove that has a nice message for people who use it and leave their waste and also has as information the time and a word, "ON" which means that the system is Connected to the central unit which is the raspberry pi zero wy "OFF" means that it is disconnected.

Below is the finished prototype, on the outside only the LCD is visible on the top and on the back you can see the power bank with its solar panel, so this device is autonomous and sustainable with the environment.

To prove that the arduino data was reaching the raspberry pi zero, I made the latter by programming in node JS, print the value of each sensor per console in Putty and below my results.

To implement the SMS notifications for my project I had to investigate on the internet a lot and everything I gathered in the tutorial in which I leave the link below.

https://www.hackster.io/alexis-santiago-allende/sms-alerts-for-arduino-101-ble-e7184d

Also to connect arduino 101 with the raspberry pi zero w by bluetooth of low energy carry out the following tutorial, in which I leave to information that I found and as I did the process. In this final project was to unite these two previous examples and make slight modifications to obtain the desired operation.

https://www.hackster.io/alexis-santiago-allende/arduino-101-connects-with-raspberry-pi-zero-w-63adc0

Blynk App

Below you can see how the application looks aesthetically, at the top of the application you can see small boxes that are widgets, two of which enable notifications, one of them is the one that activates the events of the Blynk application and the Last is a bin viewer at the moment. In the central part you can see 4 very beautiful displays of temperature and humidity. One pair is from the arduino 101 and the other are from the raspberry pi zero w, with my prototype you can add more visualization widgets and more sensors but only use the ones that had available.

In the lower part you can see the trash level display next to 2 general purpose buttons. That could be used to control any item at a distance as lights from the central unit. The use of this hardware together with Blynk gives many possibilities.

Notifications examples:

There are two types of notifications implemented, notifications specific to the application and those that are through the Twilio SMS service. Here below we have the temperature notification, when the temperature is higher than a threshold, this sends a notification. In the project notification is also given when the trash can is full.

Notifications are also given when the central device is disconnected or there is a connection failure.

Apart from the notifications of the app, under the same cases, or if the previous notifications do not work, we have the notifications by SMS that in my opinion are more effective, below I leave the example of when the trash can is full.

NOTE:

In the schematic diagram I made in fritzing only left it with the components that I could find. It is very difficult to find all the components that I need. Fritzing is very useful but I hope to update your version with more components of different brands.

Conclusions

This project fulfills the objectives with which it was designed, on the one hand it takes care of the environment and it is a question of handling the garbage with more care. And on the other hand these devices that always seem static and do not contribute anything else, can be used as data centers, you can add more sensors, such as atmospheric pressure, gas levels in the garbage (to determine if there is Gases toxic and dangerous for the environment and nature), light sensors and cameras to see nature and wildlife. I would have liked to put all those kind of sensors and special attachments, but that went out of my budget.

The physical design makes this look like a super-normal trash can, and that's great since it does not represent a strong modification to the Delta environment. The whole circuit was assembled on the lid so that leaves the trash can with the most amount of useful space.

The goal of the internet of things is to connect the things that are our daily life, now everything is useful and could give us important information or information to improve our lives.

Code

Main code arduinoArduino
/*Made by Alexis Santiago Allende Last Update 17/07/17*/
#include <CurieBLE.h>
#include "CurieIMU.h"
#include <Wire.h>
#include "rgb_lcd.h"
#include <CurieTime.h>

BLEPeripheral blePeripheral;//BLE Peripheral Device (Arduino Device)
BLEService demo111("19b10000-e8f2-537e4f6c-d104768a1214"); // BLE demo111 Service
// BLE sensor rate Characteristic"
BLEUnsignedIntCharacteristic sensor1("19b10001-e8f2-537e4f6c-d104768a1214", BLERead | BLENotify);
// BLE sensor rate Characteristic"
BLEUnsignedIntCharacteristic sensor2("19b10002-e8f2-537e4f6c-d104768a1214", BLERead | BLENotify);
// BLE sensor rate Characteristic"
BLEUnsignedIntCharacteristic sensor3("19b10003-e8f2-537e4f6c-d104768a1214", BLERead | BLENotify);
// BLE sensor rate Characteristic"
BLEUnsignedIntCharacteristic sensor4("19b10004-e8f2-537e4f6c-d104768a1214", BLERead | BLENotify);
//Ble palabra sensor Characteristic
BLECharacteristic palabra("19b10005-e8f2-537e4f6c-d104768a1214", BLERead | BLENotify,10); 
// BLE demo111 buttons Characteristic - custom 128-bit UUID, read and writable by central
BLEUnsignedCharCharacteristic buttons("19b10006-e8f2-537e4f6c-d104768a1214", BLERead | BLEWrite);
rgb_lcd lcd;
const int colorR = 198;
const int colorG = 78;
const int colorB = 25;
int lastOrientation = - 1; // previous orientation (for comparison)
long previousMillis = 0;  // last time the sensor was checked, in ms
const int green = 13; // pin to use for the green light
const int red = 11;// pin to use for the red light
boolean a = LOW, b = LOW; //Control variables
int temp=0;
long distancia;
long tiempo;
int orientation;
int valor=0,nivel=0,ndistancia;

void setup() {
  Serial.begin(9600);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);
  // Print a message to the LCD.
  setTime(16, 56, 24, 3, 07, 2017);
  lcd.print("Have a nice day!");
  lcd.setCursor(12, 1);
  lcd.print("Off");
  pinMode(green, OUTPUT); // use the LED on pin 13 as an output
  pinMode(red, OUTPUT); 
  pinMode(9, OUTPUT); /*activación del pin 9 como salida: para el pulso ultrasónico*/
  pinMode(8, INPUT);
  CurieIMU.begin();
  CurieIMU.setAccelerometerRange(2);
  // set the local name peripheral advertises
  blePeripheral.setLocalName("Demo111");
  // set the UUID for the service this peripheral advertises
  blePeripheral.setAdvertisedServiceUuid(demo111.uuid());

  // add service and characteristic
  blePeripheral.addAttribute(demo111);
  blePeripheral.addAttribute(buttons);
  blePeripheral.addAttribute(sensor1);
  blePeripheral.addAttribute(sensor2);
  blePeripheral.addAttribute(sensor3);
  blePeripheral.addAttribute(sensor4);
  blePeripheral.addAttribute(palabra);

  // assign event handlers for connected, disconnected to peripheral
  blePeripheral.setEventHandler(BLEConnected, blePeripheralConnectHandler);
  blePeripheral.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);

  // assign event handlers for characteristic
  buttons.setEventHandler(BLEWritten, switchCharacteristicWritten);
  
 // sensors.setEventHandler(BLEWritten, switchCharacteristicWritten);
// set an initial value for the characteristic
  buttons.setValue(0); 
  sensor1.setValue(0);
  sensor2.setValue(0);
  sensor3.setValue(0);
  sensor4.setValue(0);
  // advertise the service
  blePeripheral.begin();
  Serial.println(("Bluetooth device active, waiting for connections..."));
}

void loop() {
  // poll peripheral
  blePeripheral.poll();
  digitalWrite(9,LOW); /* Por cuestión de estabilización del sensor*/
  delayMicroseconds(5);
  digitalWrite(9, HIGH); /* envío del pulso ultrasónico*/
  delayMicroseconds(10);
  tiempo=pulseIn(8, HIGH); /* Función para medir la longitud del pulso entrante. Mide el tiempo que transcurrido entre el envío
  del pulso ultrasónico y cuando el sensor recibe el rebote, es decir: desde que el pin 12 empieza a recibir el rebote, HIGH, hasta que
  deja de hacerlo, LOW, la longitud del pulso entrante*/
  distancia= int(0.017*tiempo); /*fórmula para calcular la distancia obteniendo un valor entero*/
  
    char clockTime[8];
  //use sprintf to create a time string of the hour, minte and seconds
  sprintf(clockTime, "%02d:%02d:%02d", hour(), minute(), second());
  //set cursor to column 0, row 0
 lcd.setCursor(2, 1);
 //print the date string over lcd
 lcd.print(clockTime);
 
  long currentMillis = millis();
      // if 1s have passed, check the sensor:
      if (currentMillis - previousMillis >= 1000) {
        previousMillis = currentMillis;
        updateSensor();
      }

  orientation = - 1;   // the board's orientation
  String orientationString; // string for printing description of orientation

  // read accelerometer:
  int x = CurieIMU.readAccelerometer(X_AXIS);
  int y = CurieIMU.readAccelerometer(Y_AXIS);
  int z = CurieIMU.readAccelerometer(Z_AXIS);

  // calculate the absolute values, to determine the largest
  int absX = abs(x);
  int absY = abs(y);
  int absZ = abs(z);

  if ( (absZ > absX) && (absZ > absY)) {
    // base orientation on Z
    if (z > 0) {
      orientationString = "up";
      orientation = 0;  
    } else {
      orientationString = "down";
      orientation = 1;
    }
  } else if ( (absY > absX) && (absY > absZ)) {
    // base orientation on Y
    if (y > 0) {
      orientationString = "digital pins up";
      orientation = 2;
    } else {
      orientationString = "analog pins up";
      orientation = 3;
    }
  } else {
    // base orientation on X
    if (x < 0) {
      orientationString = "connector up";
      orientation = 4;
    } else {
      orientationString = "connector down";
      orientation = 5;
    }
  }

  // if the orientation has changed, print out a description:
  if (orientation != lastOrientation) {
    Serial.println(orientationString);
    lastOrientation = orientation;
  }


}

void blePeripheralConnectHandler(BLECentral& central) {
  // central connected event handler
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Have a nice day!");
  Serial.print("Connected event, central: ");
  Serial.println(central.address());
  lcd.setCursor(12, 1);
  lcd.print("On");
}

void blePeripheralDisconnectHandler(BLECentral& central) {
  // central disconnected event handler
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Have a nice day!");
  Serial.print("Disconnected event, central: ");
  Serial.println(central.address());
  lcd.setCursor(12, 1);
  lcd.print("Off");
}

void switchCharacteristicWritten(BLECentral& central, BLECharacteristic& characteristic) {
  // central wrote new value to characteristic, update LED
  Serial.print("Characteristic event, written: ");
  Serial.print(buttons.value());
  if (buttons.value() == 1 && a == LOW) { // 1 in ASCII
          
          Serial.print("LED on");
          digitalWrite(green, HIGH);         // will turn the LED on
          a = HIGH;
        } else if (buttons.value() == 1 && a == HIGH)  {  //when 1 was read again (second time)          

          Serial.println("LED off");
          digitalWrite(green, LOW);          // will turn the LED off
          a = LOW;
        }
        else if (buttons.value() == 2 && b == LOW) { // 1 in ASCII
          
          Serial.print("LED on");
          digitalWrite(red, HIGH);         // will turn the LED on
          b = HIGH;
        } else if (buttons.value() == 2 && b == HIGH)  {  //when 1 was read again (second time)          

          Serial.println("LED off");
          digitalWrite(red, LOW);          // will turn the LED off
          b = LOW;
        }
        
}




void updateSensor() {
  temp=analogRead(A0);//dht.readTemperature();//read temperature 
  valor=analogRead(A1);
  nivel = map(valor, 0, 1023, 100, 0);
  ndistancia = map(distancia, 38, 2, 0, 100);
  float sensorLevel = temp*(3.3/1023);
  int temp1=(sensorLevel-0.5)*100;
  sensor1.setValue(temp1);//send temperature value
  sensor2.setValue(distancia);//send distance value
  sensor3.setValue(orientation);//send orientation value
  sensor4.setValue(nivel);//send percentage of hummidity value
  Serial.println(temp1);
  Serial.println(distancia);
  Serial.println(orientation);
  Serial.println(nivel);
 
}
Main code Node JSJavaScript
//Blynk
var Blynk = require('blynk-library');

var AUTH = 'adea86da8f774157b6a4997a6ed18a08';

var blynk = new Blynk.Blynk(AUTH);

var v1 = new blynk.VirtualPin(1);
var v9 = new blynk.VirtualPin(9);
var v8 = new blynk.VirtualPin(8);
var v7 = new blynk.VirtualPin(7);
var v6 = new blynk.VirtualPin(6);
var v5 = new blynk.VirtualPin(5);
var v4 = new blynk.VirtualPin(4);
var v3 = new blynk.VirtualPin(3);

//Bluetooth low energy
var noble = require('noble');

// Search only for the Service UUID of the device (remove dashes)
var serviceUuids = ['19b10000e8f2537e4f6cd104768a1214'];

// Search only for the led charateristic
var characteristicUuids = ['19b10001e8f2537e4f6cd104768a1214','19b10002e8f2537e4f6cd104768a1214','19b10003e8f2537e4f6cd104768a1214','19b10004e8f2537e4f6cd104768a1214','19b10005e8f2537e4f6cd104768a1214','19b10006e8f2537e4f6cd104768a1214'];

var sensor1=0;
var sensor2=0;
var sensor3=0;
var sensor4=0;
var temperatura=0;
var humedad=0;
var boton=0;
var contador1=0,contador2=0,contador3=0,contador4=0;

//Twilio
const twilio = require('twilio')
var accountSid = 'AC4c3a664e0475a08a4e0fdbd016555a70'; 
var authToken = '22ee6e5fe596967997a2d1a57d6d73eb'; 
 
const phone = new twilio(accountSid, authToken);
 
const sendMessage = () => {
  phone.messages.create({
    to: "+526462378678",
    from: "+12818266123 ",
    body: 'WARNING!!!!!! take care, please review your Blynk app now!!!!!', 
  }) 
}
//Reading DHT22
var sensor = require('node-dht-sensor');


//Final
v1.on('write', function(param) {
  boton=param[0];
  
});

v9.on('read', function() {
  v9.write(new Date().getSeconds());
});

v8.on('read', function() {
  v8.write(sensor1);
});

v7.on('read', function() {
  v7.write(humedad);
});

v6.on('read', function() {
  v6.write(temperatura);
});

v5.on('read', function() {
  v5.write(sensor2);
});

v4.on('read', function() {
  v4.write(sensor3);
});

v4.on('read', function() {
  v4.write(sensor4);
});

// start scanning when bluetooth is powered on
noble.on('stateChange', function(state) {
  if (state === 'poweredOn') {
    noble.startScanning(serviceUuids);
  } else {
    noble.stopScanning();
  }
});

//Reading sensor
setInterval(function() {
sensor.read(22, 21, function(err, temperature, humidity) {
    if (!err) {
         temperatura=temperature.toFixed(1);
         humedad= humidity.toFixed(1);
        
    }
    });
        }, 1000);


// Search for BLE peripherals
noble.on('discover', function(peripheral) {
  peripheral.connect(function(error) {
    console.log('connected to peripheral: ' + peripheral.uuid);
    // Only discover the service we specified above
    peripheral.discoverServices(serviceUuids, function(error, services) {
      var service = services[0];
      console.log('discovered service');

      service.discoverCharacteristics(characteristicUuids, function(error, characteristics) {
        console.log('discovered characteristics');
        // Assign Characteristic
        var sensor1Characteristic = characteristics[1];
        var sensor2Characteristic = characteristics[2];
        var sensor3Characteristic = characteristics[3];
        var sensor4Characteristic = characteristics[4];
       //var botonCharacteristic = characteristics[4];
        
        setInterval(function() {
           
            sensor1Characteristic.read(function(error, data) {
            // data is a buffer
            console.log('Temperature is: ' + data.readUInt8(0));
            sensor1=data.readUInt8(0);
            if (data.readUInt8(0)>=32 && contador1===0) {
                    sendMessage();
                    contador1=1;
                  }
            else if(data.readUInt8(0)<=30 && contador1==1){
                      contador1=0;
                  
                   }
            
            });

             sensor2Characteristic.read(function(error, data) {
            // data is a buffer
            console.log('Trash percent is: ' + data.readUInt8(0));
            sensor2=data.readUInt8(0);
            if (data.readUInt8(0)<=4 && contador2===0) {
                    sendMessage();
                    contador2=1;
                  }
            else if(data.readUInt8(0)>=30 && contador2==1){
                      contador2=0;
                  
                   }
            });


             sensor3Characteristic.read(function(error, data) {
            // data is a buffer
            console.log('Orientation: ' + data.readUInt8(0));
            sensor3=data.readUInt8(0);
            if (data.readUInt8(0)!=2 && contador3===0) {
                    sendMessage();
                    contador3=1;
                  }
            else if(data.readUInt8(0)==2 && contador3==1){
                      contador3=0;
                  
                   }
            });

            sensor4Characteristic.read(function(error, data) {
            // data is a buffer
            console.log('Humidity: ' + data.readUInt8(0));
            sensor4=data.readUInt8(0);
            if (data.readUInt8(0)>=90 && contador4===0) {
                    sendMessage();
                    contador4=1;
                  }
            else if(data.readUInt8(0)<=30 && contador4==1){
                      contador4=0;
                  
                   }
            });
            
        }, 1000);

             //  var bufferToSend = new Buffer(1);
               // bufferToSend.writeUInt8(boton);
               // console.log(bufferToSend);
               // botonCharacteristic.write(bufferToSend, false);
           // setInterval(function() {
           //bufferToSend.writeUInt8(1); // you can pass this any integer, we just do this to alternate 0/1
         //  botonCharacteristic.write(bufferToSend, false);
       // }, 1000);
      }); 
    });
  });
});

Schematics

Example
Asa 6ypbaygxrw

Comments

Similar projects you might like

Smart Garbage Monitoring System Using Arduino 101

Project tutorial by Technovation

  • 35,581 views
  • 13 comments
  • 52 respects

Arduino 101 Connects with Raspberry Pi Zero W

Project tutorial by Alexis Santiago Allende

  • 9,930 views
  • 0 comments
  • 18 respects

SMS alerts for arduino 101 BLE

Project tutorial by Alexis Santiago Allende

  • 2,629 views
  • 0 comments
  • 10 respects

Octopod: Smart IoT Home/Industry Automation Project

Project tutorial by Saksham Bhutani

  • 11,746 views
  • 9 comments
  • 39 respects

Rocky Rover: Robotic Vision System PixyCam & Arduino 101

Project tutorial by Ron Dagdag

  • 18,802 views
  • 7 comments
  • 125 respects
Add projectSign up / Login