Back to Parent

int LED = D0;
int HALL_SENSOR = D2;

void setup ()
{
  pinMode(HALL_SENSOR, INPUT);
  pinMode(LED, OUTPUT);
}

void loop ()
{
  if(isNearMagnet())
  {
    digitalWrite(LED, HIGH);
  }

}

//Code that detects when a magnet is near the sensor.
boolean isNearMagnet()
{
  int sensorValue = digitalRead(HALL_SENSOR);
  if(sensorValue == LOW)  //detects user is within close proximity
  {
    return true;
  }
  else
  {
    return false;
  }
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0