
6
5. Usage
With Arduino
The SIG pin of the module output LOW normally. When a magnet approaches the switch, the
magnetic switch close and the SIG pin output HIGH.
The following sketch demonstrates a simple application of using the Magnetic switch to control the
led. When you put a magnet that has enough magnetic power close to the module, the switch is
closed .Then the SIG pin out put a high voltage. You can use this to control the led.
As the picture on the belowindicates, the Magnetic switch is connected to digital port 9 of the Grove
- Basic Shieldand the LED is connected to digital port 13. When there is Magnetic approaches the
switch, the SIG pin output a High voltage. Then the LED light. The hardware installation is as
follows:
Copy and paste code below to a newArduino sketch.
/*******************************************************************************/
/*macro definitions of magnetic pin and LED pin*/
#define MAGNECTIC_SWITCH 9
#define LED 13//the on board LED of the Arduino or Seeeduino
void setup()
{
pinsInit();