Skip to content

Instantly share code, notes, and snippets.

@schappim
Created December 16, 2017 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save schappim/37bef7f20bb345640c71ca88f4caaab7 to your computer and use it in GitHub Desktop.
Save schappim/37bef7f20bb345640c71ca88f4caaab7 to your computer and use it in GitHub Desktop.
int led = 13;//LED pin
int sensor = 10; //sensor pin
int val; //numeric variable
void setup()
{
pinMode(led, OUTPUT);
pinMode(sensor, INPUT); //set sensor pin as input
}
void loop()
{
val = digitalRead(sensor); //Read the sensor
if(val == HIGH) //when magnetic field is detected, turn led on
{
digitalWrite(led, HIGH);
}
else
{
digitalWrite(led, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment