Project Dustbinator

Estimated reading time: Less than 3 minutes

Arduino

For the ‘Soft Prototyping’ module, as part of an introduction to physical computing, I worked on a very small Arduino based project called “Dustbinator”. The project is a very small scale project which was carried out as an exploration of how Arduino works and how can we leverage it’s capabilities using a wide range of sensors.

The Dustbinator project uses an Arduino and an IR sensor to indicate trash level in a dustbin.

The Arduino Codes are provided below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//Code starts
int IRpin = A0; // analog pin for reading the IR sensor
int green1 = 7;
int green2 = 8;
int yellow1 = 9;
int yellow2 = 10;
int yellow3 = 11;
int red1 = 12;
int red2 = 13;

int level1 = 40;
int level2 = 50;
int level3 = 60;
int level4 = 70;
int level5 = 80;
int level6 = 90;
int level7 = 100;

void setup() {
    // start the serial port
    Serial.begin(9600);

    // initialize the digital pin as an output.
    pinMode(green1, OUTPUT);
    pinMode(green2, OUTPUT);
    pinMode(yellow1, OUTPUT);
    pinMode(yellow2, OUTPUT);
    pinMode(yellow3, OUTPUT);
    pinMode(red1, OUTPUT);
    pinMode(red2, OUTPUT);
}

void loop() {
    //IR sensor to distance conversion code from http://goo.gl/7242z
    float volts = analogRead(IRpin)*0.0048828125; // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3
    float distance = 65*pow(volts, -1.10); // worked out from graph 65 = theretical distance / (1/Volts)S - luckylarry.co.uk
    Serial.println(distance); // print the distance

    if (distance < level1){
        //Case 1

        // All LEDs glow: Trash bin is full
        digitalWrite(red2, HIGH);
        digitalWrite(red1, HIGH);
        digitalWrite(yellow3, HIGH);
        digitalWrite(yellow2, HIGH);
        digitalWrite(yellow1, HIGH);
        digitalWrite(green2, HIGH);
        digitalWrite(green1, HIGH);
    } else if (distance < level2 && distance > level1) {
        //Case 2

        // Green & Yellow LEDs glow: trash bin is half full
        digitalWrite(red1, HIGH);
        digitalWrite(yellow3, HIGH);
        digitalWrite(yellow2, HIGH);
        digitalWrite(yellow1, HIGH);
        digitalWrite(green2, HIGH);
        digitalWrite(green1, HIGH);

        //Red LEDs goes off if trash is removed
        digitalWrite(red2, LOW);

    } else if (distance < level3 && distance > level2) {
        //Case 3

        // Green & Yellow LEDs glow: trash bin is half full
        digitalWrite(yellow3, HIGH);
        digitalWrite(yellow2, HIGH);
        digitalWrite(yellow1, HIGH);
        digitalWrite(green2, HIGH);
        digitalWrite(green1, HIGH);

        //Red LEDs goes off if trash is removed
        digitalWrite(red2, LOW);
        digitalWrite(red1, LOW);

    } else if (distance < level4 && distance > level3) {
        //Case 4

        //Only green LED glows: trash is almost empty
        // Green & Yellow LEDs glow: trash bin is half full
        digitalWrite(yellow2, HIGH);
        digitalWrite(yellow1, HIGH);
        digitalWrite(green2, HIGH);
        digitalWrite(green1, HIGH);

        //Red LEDs goes off if trash is removed
        digitalWrite(red2, LOW);
        digitalWrite(red1, LOW);
        digitalWrite(yellow3, LOW);

    } else if (distance < level5 && distance > level4 ) {
        //Case 5

        // Green & Yellow LEDs glow: trash bin is half full
        digitalWrite(yellow1, HIGH);
        digitalWrite(green2, HIGH);
        digitalWrite(green1, HIGH);

        //Red LEDs goes off if trash is removed
        digitalWrite(red2, LOW);
        digitalWrite(red1, LOW);
        digitalWrite(yellow3, LOW);
        digitalWrite(yellow2, LOW);

    } else if (distance < level6 && distance > level5) {
        //Case 6

        // Green & Yellow LEDs glow: trash bin is half full
        digitalWrite(green2, HIGH);
        digitalWrite(green1, HIGH);

        //Red LEDs goes off if trash is removed
        digitalWrite(red2, LOW);
        digitalWrite(red1, LOW);
        digitalWrite(yellow3, LOW);
        digitalWrite(yellow2, LOW);
        digitalWrite(yellow1, LOW);

    } else if (distance < level7 && distance > level6) {
        //Case 7

        // Green & Yellow LEDs glow: trash bin is half full
        digitalWrite(green1, HIGH);

        //Red LEDs goes off if trash is removed
        digitalWrite(red2, LOW);
        digitalWrite(red1, LOW);
        digitalWrite(yellow3, LOW);
        digitalWrite(yellow2, LOW);
        digitalWrite(yellow1, LOW);
        digitalWrite(green2, LOW);

    } else {
        //Case 7

        //Red LEDs goes off if trash is removed
        digitalWrite(red2, LOW);
        digitalWrite(red1, LOW);
        digitalWrite(yellow3, LOW);
        digitalWrite(yellow2, LOW);
        digitalWrite(yellow1, LOW);
        digitalWrite(green2, LOW);
        digitalWrite(green1, LOW);
}

delay(500); // arbitary wait time.

}

Also read...

Loading Facebook Comments ...

Leave a Reply

Your email address will not be published. Required fields are marked *