Description: When a magnet is moved close enough to a Hall Effects Sensor (A3144) the red LED turns ON and the green LED turns OFF. And when the magnet is out of range the red LED turns OFF and the green LED turns back ON.
Arduino Code:
int greenLED = 8; void setup() { pinMode(greenLED, OUTPUT); Serial.begin(9600); } void loop() { int sensorValue = analogRead(A1); Serial.println(sensorValue); if (analogRead(A1) > 100) { digitalWrite(greenLED, HIGH); } else digitalWrite(greenLED, LOW); }