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
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 | 3.3 | 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 | mΩ | ||
Insulation Resistance | >106 | MΩ | ||
Operating Temperature | -40 | - | 125 | ℃ |
Operate Range | 10 | - | 40 | AT |
More details about Grove modules please refer to Grove System
Platforms Supported
Arduino | Raspberry Pi | |||
---|---|---|---|---|
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
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 |
---|---|---|
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.
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/3.3V | 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.
/*******************************************************************************/
/*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.
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.
Upload the program to your Arduino/Seeeduino.
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 pi | GrovePi_Plus | Grove - Magnetic Switch |
---|---|---|
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
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
[Datasheet] CT10 Datasheet
[Codecraft] CDC File
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.