loading

In this instructable I'm going to show you how to work with a Halls sensor using the Linkit One. The halls sensor is a sensor that detects magnetic fields.

Step 1: List of Parts

  • Linkit One
  • Halls Sensor from Seeed Studio
  • Micro USB Cable

Step 2: Halls Sensor

Connect the signal pin from the halls sensor to the linkit one D7 pin, and connect the vcc to the +5v pin and gnd pin to gnd.

Step 3: Micro USB

Next you need to connect a micro USB between the Linkit One and your PC, and install the necessary drivers from the Linkit One official site.

Step 4: Code

Use the arduino IDE to upload the code to the board, you need to modify the IDE to make it support the Linkit One board.

<p>#define HALL_SENSOR 7<br>#define LED	14//the Grove - LED is connected to D4 of Arduino
void setup()
{
 	pinsInit();
}
 
void loop() 
{
	if(isNearMagnet())//if the hall sensor is near the magnet?
	{
		turnOnLED();
	}
	else
	{
		turnOffLED();
	}
}
void pinsInit()
{
	pinMode(HALL_SENSOR, INPUT);
	pinMode(LED,OUTPUT);
}
/*If the hall sensor is near the magnet whose south pole is facing up, */
/*it will return ture, otherwise it will return false.				*/
boolean isNearMagnet()
{
	int sensorValue = digitalRead(HALL_SENSOR);
	if(sensorValue == LOW)//if the sensor value is LOW?
	{
		return true;//yes,return ture
	}
	else
	{
		return false;//no,return false
	}
}
void turnOnLED()
{
	digitalWrite(LED,HIGH);
}
void turnOffLED()
{
	digitalWrite(LED,LOW);
}</p>

Step 5: Run Time

Bring a magnet near the sensor and you should see the on board LED at D13 Light up.

<p>Cool LinkIt One project.</p>

About This Instructable

290views

6favorites

License:

More by sridhar96:Halls Sensor Using the Linkit One Linkit One Getting Started With GPS Linkit One Light Sensor  
Add instructable to: