// //
// ITOI: The Interactive TOIlet for kids //
// //
// Tarek Mokhtar and Ivan Siles //
// //
// Project #1 - Architectural Robotics (Arch879/ECE893) //
// //
// Spring 2009 //
// Clemson University, Clemson, SC //
// //
//////////////////////////////////////////////////////////////////////////
// Declare all the IN/OUT pin variables
int Action1 = 2; // Action sensors (Digital Inputs 2-4)
int Action2 = 3;
int Action3 = 4;
int Presence = 6; // Presence sensor (Digital Input 6)
int Music = 7; // Music box (Digital Output 7)
int Red = 11; // Red LEDs (Digital Output 11)
int Yellow = 12; // Yellow LEDs (Digital Output 12)
int Green = 13; // Green LEDs (Digital Output 13)
int Paper = 9; // Paper-Dispensing Arm Servo
int Shake = 10; // Hand-Shaking Arm Servo
// Declare own variables
int Pres = 0;
int Action = 0;
int presence = 0;
int A1 = 0;
int A2 = 0;
int A3 = 0;
int Time_Paper = 0;
int Time_Shake = 0;
//**********************************************************************//
// //
// VOID SETUP: Configure board pins //
// //
//**********************************************************************//
void setup() {
pinMode(Presence,INPUT); // Presence Sensor: INPUT
pinMode(Action1,INPUT); // Action sensors: INPUT
pinMode(Action2,INPUT);
pinMode(Action3,INPUT);
pinMode(Music,OUTPUT); // Music box: OUTPUT
pinMode(Red,OUTPUT); // Action Signals (LEDs): OUTPUT
pinMode(Yellow,OUTPUT);
pinMode(Green,OUTPUT);
pinMode(Paper,OUTPUT); // Servomotors (Motor Shield)
pinMode(Shake,OUTPUT);
} // Close void setup
//**********************************************************************//
// //
// VOID LOOP: Main program //
// //
//**********************************************************************//
void loop() {
digitalWrite(Red,LOW); // Make sure all LEDs are OFF
digitalWrite(Yellow,LOW);
digitalWrite(Green,LOW);
while (presence == 0) { // If no kid, keep updating sensor
Pres = digitalRead(Presence); // Read from presence sensor
if (Pres==LOW){
presence=1;
}
else {
presence=0;
}
} // Close while
digitalWrite(Red,HIGH); // If kid detected, Red light ON
while (Action == 0) { // If no action from kid, update sensors
A1 = digitalRead(Action1);
A2 = digitalRead(Action2);
A3 = digitalRead(Action3);
if (A1==HIGH || A2==HIGH || A3==HIGH) {
Action = 1; // If action detected
} // Close if
else {
Action = 0;
} // Close else
} // Close while
digitalWrite(Red,LOW); // Red light OFF
digitalWrite(Yellow,HIGH); // Yellow light ON
digitalWrite(Music,LOW);
delay(100);
digitalWrite(Music,HIGH); // Music ON
delay(100);
digitalWrite(Music,LOW); // Only pulse is required
// Activate Hand-Shaking Arm (HSA)
for (Time_Shake = 0; Time_Shake <= 15; Time_Shake++) { // 90 degrees approx.
digitalWrite(Shake,HIGH);
delayMicroseconds(1400); // 1.4ms CLOCKWISE
digitalWrite(Shake,LOW);
delay(20); // 20ms
}
delay(12000); // Wait 12 seconds (song)
// Activate Paper-Dispensing Arm (PDA)
for (Time_Paper = 0; Time_Paper <= 17; Time_Paper++) { // 90 degrees approx.
digitalWrite(Paper,HIGH);
delayMicroseconds(1600); // 1.6ms COUNTER-CLOCKWISE
digitalWrite(Paper,LOW);
delay(20); // 20ms
}
delay(5000); // Wait 5 seconds
digitalWrite(Yellow,LOW); // Yellow light OFF
digitalWrite(Green,HIGH); // Red light ON
// Deactivate both arms
for (Time_Paper = 0; Time_Paper <= 7; Time_Paper++) {
digitalWrite(Paper,HIGH);
delayMicroseconds(1400); // 1.4ms CLOCKWISE
digitalWrite(Paper,LOW);
delay(20); // 20ms
}
for (Time_Shake = 0; Time_Shake <= 7; Time_Shake++) {
digitalWrite(Shake,HIGH);
delayMicroseconds(1600); // 1.6ms COUNTER-CLOCKWISE
digitalWrite(Shake,LOW);
delay(20); // 20ms
}
while (1) { // Infinite loop
} // Close while
} // Close void loop
Electric Diagrams:
1 - Action sensors:
R1-R3 100-Ohm resistors
D1-D3 IR LEDs
R4-R6 10-kOhm resistors
Q1-Q3 Photo transistors
2 - Action lights:
R7-R12 150-Ohm resistors
D4-D5 Red LEDs
D6-D7 Yellow LEDs
D8-D9 Green LEDs
3 - Music-activating circuit:
R13 10-kOhm resistor
Q4 2N2222 General Purpose Transistor
A-B Terminals to the music box
4 - Presence sensor:
R14 10-Ohm resistor
C1 22 nF electrolytic capacitor
No comments:
Post a Comment