AUTOFOKUS
Published © GPL3+

Smart Trash Can with Processing, 2 Arduinos and IR

This trash can use ultrasonic sensor to get data how filled it is. Then this data is transmited using IR diode and then to Processing.

AdvancedFull instructions provided814
Smart Trash Can with Processing, 2 Arduinos and IR

Things used in this project

Story

Read more

Schematics

Schematics

Code

Trash can

C/C++
Code for arduino uno on trash can
#include <IRremote.h>
IRsend irsend;

int trig = 7;
int ech = 8;
long duration, distance;
void setup() {
  Serial.begin(9600);
  pinMode(trig, OUTPUT);
  pinMode(ech, INPUT);
}

void loop() {
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  duration = pulseIn(ech, HIGH);
  distance = (duration / 2) / 29.1;
  Serial.println(distance);
  switch (distance) {
    case 1:
      irsend.sendSony(0x1, 12);
      break;
    case 2:
      irsend.sendSony(0x2, 12);
      break;
    case 3:
      irsend.sendSony(0x3, 12);
      break;
    case 4:
      irsend.sendSony(0x4, 12);
      break;
    case 5:
      irsend.sendSony(0x5, 12);
      break;
    case 6:
      irsend.sendSony(0x6, 12);
      break;
    case 7:
      irsend.sendSony(0x7, 12);
      break;
    case 8:
      irsend.sendSony(0x8, 12);
      break;
    case 9:
      irsend.sendSony(0x9, 12);
      break;
    case 10:
      irsend.sendSony(0x10, 12);
      break;
    case 11:
      irsend.sendSony(0x11, 12);
      break;
    case 12:
      irsend.sendSony(0x12, 12);
      break;
    case 13:
      irsend.sendSony(0x13, 12);
      break;
    case 14:
      irsend.sendSony(0x14, 12);
      break;
    case 15:
      irsend.sendSony(0x15, 12);
      break;
    case 16:
      irsend.sendSony(0x16, 12);
      break;
    case 17:
      irsend.sendSony(0x17, 12);
      break;
    case 18:
      irsend.sendSony(0x18, 12);
      break;
    case 19:
      irsend.sendSony(0x19, 12);
      break;
    case 20:
      irsend.sendSony(0x20, 12);
      break;
    case 21:
      irsend.sendSony(0x21, 12);
      break;
  }
  delay(100);
}

Code for reciver Arduino that writes serial data for processing.

C/C++
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn();
  pinMode(48,OUTPUT);
}

void loop() {
  if (irrecv.decode(&results)) {
    switch (results.value) {
      case 0x1:
        Serial.write(1);
        break;
      case 0x2:
        Serial.write(2);
        break;
      case 0x3:
        Serial.write(3);
        break;
      case 0x4:
        Serial.write(4);
        break;
      case 0x5:
        Serial.write(5);
        break;
      case 0x6:
        Serial.write(6);
        break;
      case 0x7:
        Serial.write(7);
        break;
      case 0x8:
        Serial.write(8);
        break;
      case 0x9:
        Serial.write(9);
        break;
      case 0x10:
        Serial.write(10);
        break;
      case 0x11:
        Serial.write(11);
        break;
      case 0x12:
        Serial.write(12);
        break;
      case 0x13:
        Serial.write(13);
        break;
      case 0x14:
        Serial.write(14);
        break;
      case 0x15:
        Serial.write(15);
        break;
      case 0x16:
        Serial.write(16);
        break;
      case 0x17:
        Serial.write(17);
        break;
      case 0x18:
        Serial.write(18);
        break;
      case 0x19:
        Serial.write(19);
        break;
      case 0x20:
        Serial.write(20);
        break;
      case 0x21:
        Serial.write(21);
        break;
    }
    if (results.value<5) {
      digitalWrite(48,1);
      delay(100);
      digitalWrite(48,0);
      delay(200);
    }
    irrecv.resume();
  }
  delay(100);
}

Processing sketch for visual representation for trash can

Processing
import processing.serial.*;

Serial myPort;
int val;

PImage img; 
void setup() 
{
  size(590,800);
  myPort = new Serial(this, "COM5", 9600);//change your port
  img = loadImage("image.jpg");
}

void draw()
{
  background(255);
  image(img, 1, 0);
  if ( myPort.available() > 0) {
    val = myPort.read(); 
    val = 21-val;
    println(val);
  }
 textSize(20);
 fill(0);
 text("Trash can Nr1.",190,394);
 fill(100);
 rect(230,430,100,180);
 fill(255,255,0);
 if (val < 10) {
  fill(0,255,0); 
 }
 if (val > 15) {
  fill(255,0,0); 
 }
 rect(230,map(val,0,21,610,430),100,10);
}

Credits

AUTOFOKUS

AUTOFOKUS

0 projects • 1 follower

Comments