My take on the Useless Machine that turns itself off. Used Arduino Uno, servo, magnet, bicycle Hall Effects switch and a box. Posted a few days ago on instructables.com
Hotglued stick to servo arm and magnet to stick.
Hotglued servo to inside of plastic container.
Hotglued magnetic switch beneath the playingboard square.
Plug one end of magnetic switch to digital port 2 and also to a 1 k resistor then to ground.
Plug other end of magnetic switch to 5 vcc.
Plug servo signal to digital port 9.
Plug servo positive to 5vcc.
Plug servo ground to gnd.
Code:
#include Servo servo1;
const int buttonPin = 2;
// the number of the pushbutton pin const int ledPin = 13;
// the number of the LED pin // variables will change: int buttonState = 0;
// variable for reading the pushbutton status
void setup() { Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
servo1.attach(9);
servo1.write(55); }
void loop(){ // read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
Serial.print(" button= ");
Serial.println(buttonState);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
delay(3000); servo1.write(85);
delay(100); servo1.write(47); delay(2000); }
else { // turn LED off: digitalWrite(ledPin, LOW); }
}
https://www.youtube.com/watch?v=L_hDAKNzrVw