edit

Grove - Magnetic Switch

This is a Grove interface compatible Magnetic switch module. It is based on encapsulated dry reed switch CT10. CT10 is single-pole, single throw (SPST) type, having normally open ruthenium contacts. The sensor is a double-ended type and may be actuated with an electromagnet, a permanent magnet or a combination of both. The magnetic switch is a wonderful tool for designers who would like to turn a circuit on and off based on proximity.

Features

  • Grove compatible interface
  • 2.0cm x 2.0cm Grove module
  • Minimum external parts
  • 10W rating
  • Rugged encapsulation

Tip

More details about Grove modules please refer to Grove System

Application Ideas

  • Proximity Sensor
  • Security Alarm Sensor
  • Level Sensor
  • Flow Sensor
  • Pulse Counter

Specifications

Items Min Norm Max Unit
Working Voltage 4.75 5.0 5.25 V
Switched Power 10 W
Switched Voltage AC,RMS value(max) < 140 V
Switched Current DC < 500 mA
Carry Current DC < 0.5 A
Contact Resistance <200
Insulation Resistance >106
Operating Temperature -40 - 125
Operate Range 10 - 40 AT

Tip

More details about Grove modules please refer to Grove System

Platforms Supported

Arduino Raspberry Pi BeagleBone Wio LinkIt ONE

Caution

The platforms mentioned above as supported is/are an indication of the module's hardware or theoritical compatibility. We only provide software library or code examples for Arduino platform in most cases. It is not possible to provide software library / demo code for all possible MCU platforms. Hence, users have to write their own software library.

Getting Started

Note

If this is the first time you work with Arduino, we firmly recommend you to see Getting Started with Arduino before the start.

Play With Arduino

Demonstration

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.

Hardware

  • Step 1. Prepare the below stuffs:
Seeeduino V4.2 Base Shield Grove - Magnetic Switch
enter image description here enter image description here enter image description here
Get One Now Get One Now Get One Now
  • Step 2. Connect Grove - Magnetic Switch to port D2 of Grove-Base Shield.
  • Step 3. Plug Grove - Base Shield into Seeeduino.
  • Step 4. Connect Seeeduino to PC via a USB cable.

Note

If we don't have Grove Base Shield, We also can directly connect Grove-Magnetic-Switch to Seeeduino as below.

Seeeduino Grove-Magnetic_Switch
5V Red
GND Black
NC White
D2 Yellow

Software

  • Step 1. Copy the code into Arduino IDE and upload. If you do not know how to upload the code, please check how to upload code.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*******************************************************************************/

/*macro definitions of magnetic pin and LED pin*/
#define MAGNECTIC_SWITCH 2
#define LED 13//the on board LED of the Arduino or Seeeduino

void setup()
{
    pinsInit();
}

void loop() 
{
    if(isNearMagnet())//if the magnetic switch is near the magnet?
    {
        turnOnLED();
    }
    else
    {
        turnOffLED();
    }
}
void pinsInit()
{
    pinMode(MAGNECTIC_SWITCH, INPUT);
    pinMode(LED,OUTPUT);
}

/*If the magnetic switch is near the magnet, it will return ture, */
/*otherwise it will return false                                */
boolean isNearMagnet()
{
    int sensorValue = digitalRead(MAGNECTIC_SWITCH);
    if(sensorValue == HIGH)//if the sensor value is HIGH?
    {
        return true;//yes,return ture
    }
    else
    {
        return false;//no,return false
    }
}
void turnOnLED()
{
    digitalWrite(LED,HIGH);
}
void turnOffLED()
{
    digitalWrite(LED,LOW);
}
  • Step 2. Then the LED turns on when there is Magnetic approaches the switch. Have a try!

Play With Raspberry Pi

Hardware

  • Step 1. Prepare the below stuffs:
Raspberry pi GrovePi_Plus Grove - Magnetic Switch
enter image description here enter image description here enter image description here
Get One Now Get One Now Get One Now
  • Step 2. Plug the GrovePi_Plus into Raspberry.
  • Step 3. Connect Grove-Magnetic-Switch ranger to D2 port of GrovePi_Plus.
  • Step 4. Connect the Raspberry to PC through USB cable.

Software

  • Step 1. Follow Setting Software to configure the development environment.

  • Step 2. Navigate to the demos' directory:

1
cd yourpath/GrovePi/Software/Python/
  • Step 3. To see the code (this demo has the same usage with tilt switch)
1
nano grovepi_tilt_switch.py   # "Ctrl+x" to exit #
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import time
import grovepi

# Connect the Grove Tilt Switch to digital port D2
# SIG,NC,VCC,GND
tilt_switch = 2

grovepi.pinMode(tilt_switch,"INPUT")

while True:
    try:
        print grovepi.digitalRead(tilt_switch)
        time.sleep(.5)

    except IOError:
        print "Error"
  • Step 4. Run the demo.
1
sudo python grovepi_tilt_switch.py
  • Step 5. Result

Put a magnet upon the sensor, the SIG pin will output HIGH.

Resources

Tech Support

Please submit any technical issue into our forum.