Our mailbox uses a series of complex wires to create a very productive design. We wire a tilt sensor to pin 2, an LED to pin 7, and a buzzer to pin 3. The tilt sensor will take in the angle, and when the proper angle is detected, the LED will turn on and the beeper will go off. If the consumer has opened the mailbox and not an intruder, they will click the Arduino reset and the code will reset.
We wrote our code in the Arduino IDE.
const int sigPin = 2; // the number of the tilt switch pin
const int ledPin = 7; // the number of the LED pin
bool mail = false; // variables will change:
bool isaac = false; // variables will change:
boolean sigState = 0; // variable for reading the tilt switch status
void setup()
{
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output:
pinMode(sigPin, INPUT); // tilt sensor as input
pinMode(3, OUTPUT); // setup beeper
digitalWrite(ledPin, LOW); // LED pin off
digitalWrite(3, LOW); // beeper off
Serial.begin(9600); // turn on serial monitor
Serial.println ("NO MAIL"); // serial writes...
}
void loop()
{
sigState = digitalRead(sigPin);
if ((sigState == HIGH) & (mail == false))
{
Serial.println("MAIL AVAILABLE!"); // serial writes...
digitalWrite(ledPin, HIGH); // led on
mail = true; // variable change
isaac = true; // variable change
Serial.end(); // serial monitor off
}
if ((sigState == HIGH) & (mail == true)& (isaac == true))
{
digitalWrite(3, HIGH);
delay(1000);
digitalWrite(3, LOW);
isaac = false;
}
}