User:Cjcampo/ENES 100/Useless box

Problem
To engineer a gadget that befuddles and bewilders its user much like this one does.

Conceive
Brainstorming! As a group coming up with ideas for functions and components needed to create this "Useless Box". The Idea is to have a box, which, although it does not appear to have a defined purpose, will require mechanical as well as electrical engineering. The useless box will have an initial operation which is started by the on/off switch, which will open the door on the top of the box. This operation will be followed by a series of cause and effect functions, such as the box turning itself off, the illumination of LED lights, and also having the functions be activated by a motion sensor. In order to achieve the functions that the group has come up with it will require a lot of Arduino code to be written as well as trial and error to achieve the order of this particular "Useless Box's" Functions.

Materials List:
 * Arduino Uno and Shields.
 * LED lights
 * Motion sensor
 * On/Off Switch
 * Electric Motor
 * Actuator arm
 * Small door hinges
 * Cardboard for Prototype
 * Duct tape

Design
 Arm Design 

A three linkage arm can be used in order to move the motor further from the door. The three linkage arm isn't very sturdy, it allows movement perpendicular to the pivoting motion unless the design is created very rigid. A second arm can be used to open the door and can use a double linkage design set at the back of the door.

 Motor 

Code
Servo armservo;
 * 1) include 

int pos = 0; int buttonPin = 2;                               // Button is pin number 2 int ledPin = 4;                                  // Buzzer is pin number 4 int ledPin2 = 3;                                 // The light is pin number 3 int buttonState = 0;                             // The Button state 0 means the button/switch is off int count =0 ;                                   // An int have a value of either 1 or 0 for turning on either the LED or Buzzer void setup { pinMode(ledPin, OUTPUT);                        // For PIN 4 (BUZZER) only 5V can be output pinMode(buttonPin, INPUT);                     // The button is the input so that if it detects a voltage it turms the LED or Buzzer ON  pinMode(ledPin2, OUTPUT);                       // For PIN 3 (LED) only 5V can be output armservo.attach (9); } void loop {

buttonState = digitalRead(buttonPin);          //  ButtonState has a value of either HIGH or LOW depending on if the switch is on (HIGH) or off (LOW) while( buttonState == HIGH && count ==0){       // When the button is on and the count is 0, the buzzer turns on, but the light stays off digitalWrite(ledPin, HIGH);

for(pos = 0; pos < 180; pos += 1)              // goes from 0 degrees to 180 degrees {                                             // in steps of 1 degree armservo.write(pos);                         // tell servo to go to position in variable 'pos' delay(15);                                  // waits 15ms for the servo to reach the position }

for(pos = 180; pos>=1; pos-=1)                // goes from 180 degrees to 0 degrees {    digitalWrite(ledPin, LOW); armservo.write(pos);                         // tell servo to go to position in variable 'pos' delay(15);     // waits 15ms for the servo to reach the position }                     // Turns on Buzzer buttonState = digitalRead(buttonPin);        // Keeps reading the PIN 2 to see if it has changed value from HIGH to LOW if so the if statement changes the value on int count to 1 if (buttonState == LOW){                     // the while loop ends when the switch is turned off and thus changes the int count to 1 so that next time the switch turns on only the LED will light up    count =1; }

}

while (buttonState == HIGH && count ==1){      // When the button is on and the count is 1, the LED turns on, but the buzzer stays off digitalWrite(ledPin2, HIGH); for(pos = 0; pos < 180; pos += 1)                // goes from 0 degrees to 180 degrees {                                             // in steps of 1 degree armservo.write(pos);                         // tell servo to go to position in variable 'pos' delay(15);                                  // waits 15ms for the servo to reach the position }  for(pos = 180; pos>=1; pos-=1)                 // goes from 180 degrees to 0 degrees {      digitalWrite(ledPin2, LOW); armservo.write(pos);                         // tell servo to go to position in variable 'pos' delay(15);                                  // waits 15ms for the servo to reach the position }   digitalWrite(ledPin2, HIGH);                  // Turns LED on    buttonState = digitalRead(buttonPin);         //Keeps reading the PIN 2 to see if it has changed value from HIGH to LOW if so the if statement changes the value on int count to 0 if (buttonState == LOW){                     // the while loop ends when the switch is turned off and thus changes the int count to 0 so that next time the switch turns on only the LED will light up    count =0; } }

digitalWrite(ledPin, LOW);                   // if the switch is off then the both the LED and Buzzer remain off and neither while loop is true digitalWrite(ledPin2, LOW);                  //

}

This code operates with a light switch and buzzer. The basic functions of the code are the light turns on and the motor turns on. Normally an arm would be attached the motor so it can turn the switch off. when the switch is turned back on the buzzer comes on and the motor will turn on and do the same thing as the first loop.

Demo
The three linkage switch arm and double linkage door arm demo

Next Steps

 * Decide on actions that useless box will execute
 * Get familiar with programming options