Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
| ||||||
|
Introduction
Ultrasonic sensor
Transmiter Arduino UNO
Read moreThis garbage tank uses ultrasonic sensor to get data-how full it is. The this data is transmited using IR light to second Arduino. Then data is got to Processing using Serial comunication and Processing visualy shows how full is the tank.
FrameUltraonic sensor is mounted on top that it sees the filling of trash can with folowing conections
- VCC - 5V
- GND - GND
- TRIG - D7
- ECHO - D8
Distance (cm) is transmited like hex code using IR diode with 220Ω resistor.
ReciverSecond Arduino Mega gets IR signal and writes number using Serial to Processing.
#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);
}
#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);
}
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);
}
Comments