Skip to main content

Grove - Electromagnet

An electromagnet is a type of magnet in which the magnetic field is produced by electric current. An electric current flowing in a wire creates a magnetic field around the wire, due to Ampere's law(see drawing below). To concentrate the magnetic field, in an electromagnet the wire is wound into a coil with many turns of wire lying side by side. The magnetic field of all the turns of wire passes through the center of the coil, creating a strong magnetic field there. Grove - Electromagnet can suck 1KG weight and hold on. It is easy to use, to learn electromagnet principle.


  • Grove shape
  • 1KG peak suction
  • Low standby current


Working VoltageDC 5V
Working Current400mA
Standby Current200uA
Load Weight1KG

More details about Grove modules please refer to Grove System

Platforms Supported

ArduinoRaspberry 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


  • Step 1. Prepare the below stuffs:
Seeeduino V4.2Base ShieldGrove-Electromagnet
enter image description hereenter image description hereenter image description here
Get One NowGet One NowGet One Now
  • Step 2. Connect Grove-Electromagnet 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-Electromagnet to Seeeduino as below.

SeeeduinoGrove-Ultrasonic Ranger
Not ConenctedWhite


  • Step 1. Please copy below code to Arduio IDE and upload to arduino. If you do not know how to upload the code, please check how to upload code.
Turns on an Electromagnet on for one second, then off for one second, repeatedly.
This example code is in the public domain.

int Electromagnet = 2;
int LED = 13;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(Electromagnet, OUTPUT);
pinMode(LED, OUTPUT);

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(Electromagnet, HIGH); // turn the Electromagnet on (HIGH is the voltage level)
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(Electromagnet, LOW); // turn the Electromagnet off by making the voltage LOW
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
  • Step 2. Grove-Electromagnet worked.

Play with Codecraft


Step 1. Connect Grove - Electromagnet 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.


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, you can try to bring the ironwork close to the electromagnet. The LED on the Arduino 13 pin will be lighted up when the electromagnet is working.

Play With Raspberry Pi


  • Step 1. Prepare the below stuffs:
Raspberry piGrovePi_PlusGrove-Electromagnet
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-Electromagnet to D4 port of GrovePi_Plus.

  • Step 4. Connect the Raspberry to PC through USB cable.



In this wiki we use the path ~/GrovePi/ instead of /home/pi/Desktop/GrovePi, you need to make sure Step 2 and Step 3 use the same path.


We firmly suggest you to update the firmware, or for some sensors you may get errors.

  • Step 3. Git clone the Github repository.
cd ~
git clone

  • Step 4. Navigate to the demos' directory:
cd yourpath/GrovePi/Software/Python/

Here is the code.

    import time
import grovepi

# The electromagnet can hold a 1KG weight

# Connect the Grove Electromagnet to digital port D4
electromagnet = 4


while True:
# Switch on electromagnet
print "on"

# Switch off electromagnet
print "off"

except KeyboardInterrupt:
except IOError:
print "Error"

5.Run the demo.

    sudo python

Schematic Online Viewer


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