Instructions

IDUINO for maker’s life
www.openplatform.cc 83
3.example
In this example, If no magnetic field is present, the signal line of the sensor is HIGH (3.5
V). If a magnetic field is presented to the sensor, the signal line goes LOW, at the same time
the LED on the sensor lights up.
The connection as below:
Example Code:
******Code begin******
int Led = 13 ; // define LED Interface
int SENSOR = 10 ; // define the Hall magnetic sensor interface
int val ; // define numeric variables val
void setup ()
{
pinMode (Led, OUTPUT) ; // define LED as output interface
pinMode (SENSOR, INPUT) ; // define the Hall magnetic sensor line as
input
}
void loop ()
{
val = digitalRead (SENSOR) ; // read sensor line
if (val == LOW) // when the Hall sensor detects a magnetic field, Arduino
LED lights up