Lab6- Toilet paper dispenser

Submitted by jooddang on Tue, 03/12/2013 - 20:13

Description

After finishing your business in a toilet, you will need toilet paper. :) If you are as lazy as you don't want to pull toilet paper, you will definitely need it. When you approach with your hand to toilet paper, this toilet paper dispenser will roll automatically so that all you need to do is just cutting the paper. After rolling the paper, it will make sound of success and turn on LED lamps.

 

 

 

Components used

 

1- Arduino Uno
1- DC Motor
1- Diode
1- Transistor
1- 3V Power
1- Photocell sensor
3- LED lamps
1- 1kΩ Resistor
1- 10kΩ Resistor
toilet paper, wood sticks, etc.

 

 

 

Code

 

 
int lightPin = 0;   // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val = 0;      // variable to store the value coming from the sensor
int prevVal = 0;
int BOUNDARY = 400;
 
int aPin = 11;
int bPin = 12;
int cPin = 13;
int speakerOut = 7;               
byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};  
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
byte ringA[] =   "ceggggppggppgppCCCCCpppppp";
int count = 0;
int count2 = 0;
int count3 = 0;
 
void setup() {
  Serial.begin(9600);
 pinMode(aPin, OUTPUT); 
 pinMode(bPin, OUTPUT); 
 pinMode(cPin, OUTPUT); 
 pinMode(speakerOut, OUTPUT);
}
void loop() {
  val = analogRead(lightPin);    // read the value from the sensor, between 0 - 1024
  Serial.println(val);
  if (val < BOUNDARY) {
    analogWrite(motorPin, 100); // analogWrite can be between 0-255
  }
  else {
    analogWrite(motorPin, 0);
  }
  
  if (prevVal < BOUNDARY && val > BOUNDARY) {
    playA();
  }
  prevVal = val;
}
 
 
 
void playA() {
 
  digitalWrite(cPin, HIGH);
  digitalWrite(bPin, HIGH);
  digitalWrite(aPin, HIGH);
  Serial.println("play A");
  
  for (count = 0; count < sizeof(ringA); count++) {
 
//    statePin = !statePin;
    
    for (count2=0;count2<8;count2++) {
      if (names[count2] == ringA[count]) {
        for( int i=0; i<50; i++ ) {   // play it for 50 cycles
          digitalWrite(speakerOut,HIGH);
          delayMicroseconds(tones[count2]);
          digitalWrite(speakerOut, LOW);
          delayMicroseconds(tones[count2]);
        }
      } 
      if (ringA[count] == 'p') {
        // make a pause of a certain size
        digitalWrite(speakerOut, 0);
        delayMicroseconds(500);
      }
    }
  }
  digitalWrite(aPin, LOW);
  digitalWrite(bPin, LOW);
  digitalWrite(cPin, LOW);
}

 

 

20130312_204837.jpg
0
Your rating: None
Drupal theme by Kiwi Themes.