Skip to main content

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

ItemsMinNormMaxUnit
Working Voltage3.35.05.25V
Switched Power10W
Switched Voltage AC,RMS value(max)< 140V
Switched Current DC< 500mA
Carry Current DC< 0.5A
Contact Resistance<200
Insulation Resistance>106
Operating Temperature-40-125
Operate Range10-40AT
tip

More details about Grove modules please refer to Grove System

Platforms Supported

ArduinoRaspberry Pi
caution

The platforms mentioned above as supported is/are an indication of the module's software 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.2Base ShieldGrove - Magnetic Switch
enter image description hereenter image description hereenter image description here
Get One NowGet One NowGet 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.

SeeeduinoGrove-Magnetic_Switch
5V/3.3VRed
GNDBlack
NCWhite
D2Yellow

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.
/*******************************************************************************/

/*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 Codecraft

Hardware

Step 1. Connect a Grove - Magnetic Switch to port D2 of a Base Shield.

Step 2. Plug the Base Shield to your Seeeduino/Arduino.

Step 3. Link Seeeduino/Arduino to your PC via an USB cable.

Software

Step 1. Open Codecraft, add Arduino support, and drag a main procedure to working area.

note

If this is your first time using Codecraft, see also Guide for Codecraft using Arduino.

Step 2. Drag blocks as picture below or open the cdc file which can be downloaded at the end of this page.

cc

Upload the program to your Arduino/Seeeduino.

success

When the code finishes uploaded, move the magnet close to the magnetic switch and you will see the LED on the Arduino 13 pin turns on.

Play With Raspberry Pi

Hardware

  • Step 1. Prepare the below stuffs:
Raspberry piGrovePi_PlusGrove - Magnetic Switch
enter image description hereenter image description hereenter image description here
Get One NowGet One NowGet 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

caution

If you are using Raspberry Pi with Raspberrypi OS >= Bullseye, you have to use this command line only with Python3.

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

  • Step 2. Navigate to the demos' directory:

cd yourpath/GrovePi/Software/Python/
  • Step 3. To see the code (this demo has the same usage with tilt switch)
nano grovepi_tilt_switch.py   # "Ctrl+x" to exit #
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.
sudo python grovepi_tilt_switch.py
  • Step 5. Result

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

Grove-Magnetic Switch v0.9

Grove-Magnetic Switch v1.3

Resources

Tech Support & Product Discussion

Thank you for choosing our products! We are here to provide you with different support to ensure that your experience with our products is as smooth as possible. We offer several communication channels to cater to different preferences and needs.

Loading Comments...