In and Out

Assignment: Input / Output Coincidence Lab Assignment

Collaborators:

Assignment: Input / Output Coincidence Lab Assignment
Collaborators:

Assignment: Input / Output Coincidence Lab Assignment
Collaborators:

I had a hard time choosing which of my ideas to pick for this assignment.

One idea I had was to create a flexible lid-like sensor for a recycling bin which would be able to differentiate between items put in the bin based on weight. It would then reward the correct recycler with no lights or sound, but punish a person who recycled the wrong thing with flashing lights or annoying sounds.

Another idea I had was to make an alarm clock that wakes you with a gradual light at a certain time, makes noise if you don't turn it off, and allows you to turn it off by hitting it.

 

Finally I decided to do something a tad simpler, partially because I couldn't find the sheet music I wanted to have the speaker output the songs I desired, and because I wanted to play with the speaker and photocell rather than the force sensor I used in the last assignment, but also because there was an actual real need that had to be met. My lab mates were complaining that folks do not take out the recying or trash, even when it gets full and I thought....ah ha! That is a fairly easy problem to fix.

This code is simple but effective. I set the photocell to the ambient light in the room and when it became covered (ie. by the last person putting in a peice of garbage/recyling) it makes a noise and won't stop till you stomp down the trash or empty the bucket!

 

Materials Used:

Duct tape

Wires

Arduino board

Breadboard

Garbage pail

peizo speaker

resistors

1 photocell

 

 

 

Arduino code:

 

 

/* Take out the recycling!

* Modified by Hazel Onsrud

* I finally decided that the most useful lab tool would be to create a light sensor that would trigger a

* noise when the last person drops in something

* into the recyling bin (or waste bin). Obviously the sensor would have to be placed a critical level.

*

* This was adapted from two programs

* The first by

* Tod E. Kurt <tod@todbot.com , 2006

* http://todbot.com/

*

* & the second by

* (cleft) 2005 D. Cuartielles for K3 - named Melody

*

* The Melody program notes the following:

* The calculation of the tones is made following the mathematical

* operation:

*

*       timeHigh = period / 2 = 1 / (2 * toneFrequency)

*

* where the different tones are described as in the table:

*

* note frequency period timeHigh

* c 261 Hz 3830 1915

* d 294 Hz 3400 1700

* e 329 Hz 3038 1519

* f 349 Hz 2864 1432

* g 392 Hz 2550 1275

* a 440 Hz 2272 1136

* b 493 Hz 2028 1014

* C 523 Hz 1912 956

*

* http://www.arduino.cc/en/Tutorial/Melody

*/

 

int potPin = 0;    // select the input pin for the input sensor

int speakerPin = 7;

 

int val = 0;

 

void setup() {

pinMode(speakerPin, OUTPUT);

Serial.begin(9600);

Serial.println("ready");

}

 

 

void playTone(int tone, int duration) {

for (long i = 0; i < duration * 1000L; i += tone * 2) {

digitalWrite(speakerPin, HIGH);

delayMicroseconds(tone);

digitalWrite(speakerPin, LOW);

delayMicroseconds(tone);

}

}

 

void loop() {

digitalWrite(speakerPin, LOW);

 

val = analogRead(potPin);    // read value from the sensor

val = val*2;                 // process the value a little

//val = val/2;                 // process the value a little

 

if (val >= 0 && val < 50){

playTone(1700, 4000);

}

/* I was going to elborate on this to have it play a song etc...but my labmates vetoed further

 

experimentation.

*Ie. the annoying nature of that speaker really works!

*/

}