Created
December 16, 2017 11:56
-
-
Save schappim/37bef7f20bb345640c71ca88f4caaab7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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