/* Author: Danny van den Brande, Arduinosensors.nl. BlueCore Tech. In this example we use the hall magnetic sensor as a magnetic field detector. A simple but useful code. */ int GreenLed = 2; int BlueLed = 3; int MagneticHallSensor = 4; int Buzzer = 5; int val; void setup () { pinMode (GreenLed, OUTPUT); pinMode (BlueLed, OUTPUT); pinMode (MagneticHallSensor, INPUT); pinMode (Buzzer, OUTPUT); } void loop () { val = digitalRead (MagneticHallSensor) ; if (val == LOW) //Set to HIGH if you want the device to work the other way around. { digitalWrite (BlueLed, HIGH); digitalWrite (Buzzer, HIGH); delay(1000); digitalWrite (BlueLed, LOW); digitalWrite (Buzzer, LOW); delay(100); } else { digitalWrite (BlueLed, LOW); digitalWrite (GreenLed, HIGH); delay(1000); digitalWrite (GreenLed, LOW); digitalWrite (Buzzer, LOW); delay(100); } }