Arduino Lunch Box Alarm| Reed Switch
SOURCE CODE:
const int SpeakerPin = 9;//define piezo pin const int reedSwitch = A0;//define reed switch sensor int sensorValue;//define sensor value
void setup() {
pinMode(reedSwitch, INPUT);//set the reed switch as an input Serial.begin(9600);//begin the serial monitor }
void loop() { sensorValue = analogRead(reedSwitch);//read the reed switch
if (sensorValue > 100){//if the magnet is far away turn on the alarm tone(SpeakerPin, 800, 600); delay(200); } Serial.println(sensorValue);//print the sensor value to the serial monitor }