CoilCell is a compact magnetic actuator that can make magnets move and even jump! In this guide, we will explore how to make a small 5mm diameter ball magnet bounce using the CoilCell, using short pulses to generate motion.
CoilCell generates a magnetic field when an electric current passes through its coil. By applying a short pulse, we create a rapid magnetic repulsion that propels the magnet upwards. Depending on the power of the CoilCell module, the effect varies:
When using the 2.5W 200-Turns CoilCell, always wear eye protection. The repulsion force may cause small magnets to shoot upwards unpredictably.
To generate a pulse, we use the CoilCell library. The following example demonstrates how to make a 5mm ball magnet bounce using an on-time pulse of 20ms, followed by a delay to allow the magnet to be attracted back:
#include <CoilCell.h>
/* Learn more at microbots.io */
/* In this example, we initialize a CoilCell and make a 5mm diameter ball magnet bounce */
#define IN1_pin1 5
#define IN1_pin2 6
CoilCell myCoilCell(IN1_pin1, IN1_pin2);
void setup() {
myCoilCell.Init(); /* Initialize the CoilCell */
}
void loop() {
myCoilCell.Bounce(0, 20); /* Bounce the magnet up for 20ms */
delay(600); /* Attract the magnet back down for 600ms */
}
Understanding the Function:
direction
: The pulse direction (0 for normal bounce behavior).duration
: Time in milliseconds for the activation pulse.By tweaking the duration
and delay
, you can fine-tune the bouncing effect. A longer pulse will push the magnet higher, while a shorter delay may not allow it to return fully before the next bounce.
This showed us how to make a small ball magnet bounce using CoilCell! Check out the CoilCell GitHub Repository for more code examples and technical documentation!
CoilCell can be used as a weak electromagnet, instead of interacting with magnets. By upgrading to the Iron Back-Plate option, you can enhance the 2.5W CoilCell's peak strength to 17 mT, turning it into a weak electromagnet suitable for attracting small metallic objects like paper clips.
⚠ Caution: When using the 2.5W 200-Turns CoilCell, it may heat up to 110°C (especially the iron back-plate). Keep hands away from hot areas to prevent injury and always turn off the coil when not in use.
CoilCell operates by passing current through its coil, generating a magnetic field. Instead of controlling polarity to interact with magnets, we can maximize field strength to attract small metallic objects.
Since CoilCell has an integrated H-bridge, it can directly control the coil’s magnetic strength without requiring an external driver. By pulling one of the input pins HIGH, CoilCell will operate at maximum magnetic power. If magnetic field adjustments are needed, the CoilCell library can be used to adjust the power using Pulse Width Modulation (PWM) to finely tune the intensity.
The following example demonstrates how to adjust the strength of the electromagnet:
#include <coilcell.h>
#define COIL_PIN1 2
#define COIL_PIN2 3
CoilCell myCoilCell(COIL_PIN1, COIL_PIN2);
void setup() {
myCoilCell.Init();
}
void loop() {
myCoilCell.Drive(true, 100); // Maximum power
delay(3000);
myCoilCell.Drive(true, 75); // 75% power
delay(3000);
myCoilCell.Drive(true, 50); // 50% power
delay(3000);
myCoilCell.Drive(true, 25); // 25% power
delay(3000);
}
⚠ Note: The Drive()
function uses a high-speed PWM timer, making it compatible only with CodeCell and ESP32-based devices.
Init()
→ Initializes CoilCell and sets up the control pins.Drive(bool direction, uint8_t power_percent)
true
(activates electromagnet) / false
(not used in this case)This showed us how to power and control a CoilCell and use it as a weak electromagnet, capable of attracting paper clips and other lightweight metal objects. Check out the CoilCell GitHub Repository for more code examples and technical documentation!
In this guide, we’ll focus on controlling the CoilCell's polarity and magnetic field strength, making it ideal for applications like flip-dot mechanical pixel and other magnetic pixels.
CoilCell operates by passing current through its coil, generating a magnetic field whose polarity depends on the current direction. Since CoilCell has an integrated H-bridge, it can directly control the coil’s polarity and strength without requiring an external driver, like DriveCell.
Instead of simply turning the coil on or off, we’ll use Pulse Width Modulation (PWM) to finely adjust the magnetic strength and flip polarity as needed.
Several factors affect polarity control and field strength:
Remember CoilCell is available in two configurations:
If you're using the CoilCell library, the following example demonstrates how to flip polarity and adjust strength:
#include <CoilCell.h>
#define COIL_PIN1 2
#define COIL_PIN2 3
CoilCell myCoilCell(COIL_PIN1, COIL_PIN2);
void setup() {
myCoilCell.Init();
}
void loop() {
myCoilCell.Drive(true, 100); // Strong north pole field
delay(3000);
myCoilCell.Drive(false, 100); // Strong south pole field
delay(3000);
myCoilCell.Drive(true, 50); // Weaker north pole field
delay(3000);
myCoilCell.Drive(false, 50); // Weaker south pole field
delay(3000);
}
⚠ Note: The Drive
()
function uses a high-speed PWM timer, making it compatible only with CodeCell and ESP32-based devices.
Init()
→ Initializes CoilCell and sets up the control pins.Drive(bool direction, uint8_t power_percent)
true
(north pole) / false
(south pole)By alternating polarity, CoilCell can be used to flip magnetic elements, such a flipdot pixel combined with a magnet. To smooth this out, we can use Pulse Width Modulation (PWM) on both outputs. This method gradually changes the magnetic field intensity, reducing mechanical stress on the CoilCell.
This function is automatically handled within our CoilCell library:
#include <coilcell.h>
#define COIL_PIN1 2
#define COIL_PIN2 3
CoilCell myCoilCell(COIL_PIN1, COIL_PIN2);
uint16_t vibration_counter = 0;
void setup() {
myCoilCell.Init();
myCoilCell.Tone();
}
void loop() {
myCoilCell.Vibrate(1, 75, 1000); // Flip at 75% power every 1sec
}
Init()
→ Initializes CoilCell and sets up the input pins.Vibrate(smooth, power, speed_ms)
→ Oscillates the CoilCell in either a square wave or a smoother PWM wave.
smooth
→ 1 (PWM wave) / 0 (square wave)power
→ Magnetic-field strength (0 to 100%)speed_ms
→ Vibration speed in milliseconds⚠ Note: The Vibrate
()
function uses a high-speed PWM timer, making it compatible only with CodeCell and ESP32-based devices.
With these techniques, you can start controlling CoilCell's magnetic polarity. Check out the CoilCell GitHub Repository for more code examples and technical documentation!
This guide explains how the CoilCell can generate vibrations, how frequency and polarity affect its movement, and how to create its drive signals.
To make CoilCell vibrate, an electric current is applied to its coil, generating a magnetic field. By reversing the polarity at a set frequency, we create a repetitive push-pull motion that causes vibrations.
The vibration frequency can be controlled within the range of 1 Hz to 25 Hz, which means CoilCell can oscillate between 1 to 25 times per second depending on the input signal. It can go to higher frequencies, but usually the magnet won't have enough time to react.
If you attach it to something, you can adjust it to match its new resonant frequency and make the whole thing shake.
A square wave signal is required to make the CoilCell vibrate. Unlike CoilPad, CoilCell has an integrated H-Bridge driver, so no external driver like DriveCell is needed. The input signals of the square wave can be generated using simple digitalWrite()
commands in Arduino:
#define VIB_PIN1 2
#define VIB_PIN2 3
void setup() {
pinMode(VIB_PIN1, OUTPUT);
pinMode(VIB_PIN2, OUTPUT);
}
void loop() {
digitalWrite(VIB_PIN1, HIGH);
digitalWrite(VIB_PIN2, LOW);
delay(100); // Adjust delay for desired vibration speed
digitalWrite(VIB_PIN1, LOW);
digitalWrite(VIB_PIN2, HIGH);
delay(100); // Adjust delay for desired vibration speed
}
This simple code creates a square wave oscillation, making the CoilCell vibrate continuously. You can adjust the delay time to change the vibration frequency.
The code example above generates a basic square wave, which drives the coil in an abrupt on-off manner. At low frequencies, this might not be desirable. To smooth this out, we can use Pulse Width Modulation (PWM) on both outputs. This method gradually changes the magnetic field intensity, reducing mechanical stress on the CoilCell.
This function is automatically handled within our CoilCell library:
#include <coilcell.h>
#define COIL_PIN1 2
#define COIL_PIN2 3
CoilCell myCoilCell(COIL_PIN1, COIL_PIN2);
uint16_t vibration_counter = 0;
void setup() {
myCoilCell.Init();
myCoilCell.Tone();
}
void loop() {
delay(1);
vibration_counter++;
if (vibration_counter < 2000U) {
myCoilCell.Vibrate(0, 100, 100); // Square Wave mode
}
else if (vibration_counter < 8000U) {
myCoilCell.Vibrate(1, 100, 1000); // Smooth PWM Wave mode
} else {
vibration_counter = 0U;
}
}
Init()
→ Initializes CoilCell and sets up the input pins.Vibrate(smooth, power, speed_ms)
→ Oscillates the CoilCell in either a square wave or a smoother PWM wave.
smooth
→ 1 (PWM wave) / 0 (square wave)power
→ Magnetic-field strength (0 to 100%)speed_ms
→ Vibration speed in milliseconds⚠ Note: The Run()
function uses a high-speed PWM timer, making it compatible only with CodeCell and ESP32-based devices.
With these techniques, you can start using CoilCell to vibrate. Check out the CoilCell GitHub Repository for more code examples and technical documentation!
CoilCell isn’t just a compact coil actuator – it can also generate buzzing tones, much like a piezo buzzer. By sending a high-frequency signal, CoilCell can produce audible tones and vibrations, making it useful for alert systems, interactive responses, and creative sound-based installations.
Unlike CoilPad, CoilCell has an integrated H-Bridge driver, making it even easier to integrate into microcontroller projects without requiring an external driver like DriveCell.
CoilCell uses a built-in H-Bridge to rapidly switch the direction of current through a thin copper coil, which can interacts with an N52 neodymium magnet to create motion. By switching the current at an audible frequency (~100Hz–10kHz), CoilCell can emit tones similar to a speaker or piezo buzzer.
By varying the frequency, you can:
Since CoilCell already includes an H-Bridge, wiring it is straightforward:
Basic Connection for Buzzing CoilCell
CoilCell can generate tones using PWM signals. Below is an example using the CoilCell library to generate buzzing tones.
This example makes CoilCell buzz like a speaker, playing a sequence of tones:
#include <CoilCell.h>
#define IN1_pin1 2
#define IN1_pin2 3
CoilCell myCoilCell(IN1_pin1, IN1_pin2);
void setup() {
myCoilCell.Init(); /* Initialize FlatFlap with DriveCell */
myCoilCell.Tone(); /* Play a fixed tone*/
delay(500);
}
void loop() {
myCoilCell.Buzz(100); /* Buzz at 100 microseconds */
}
Understanding the Functions:
Buzz(duration)
→ Generates a buzzing effect at 100 microseconds, controlling the vibration speed.Tone()
→ Plays an audible tone, varying its frequency automatically.Tip: By adjusting the frequency and duty cycle, you can create different musical notes, alarms, or feedback sounds.
Below is another code example that plays the Super Mario song using CoilCell:
/* Arduino Mario Bros Tunes With Piezo Buzzer and PWM
by : ARDUTECH
Connect the positive side of the Buzzer to pin 3,
then the negative side to a 1k ohm resistor. Connect
the other side of the 1 k ohm resistor to
ground(GND) pin on the Arduino.
*/
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
#define melodyPin 5
//Mario main theme melody
int melody[] = {
NOTE_E7, NOTE_E7, 0, NOTE_E7,
0, NOTE_C7, NOTE_E7, 0,
NOTE_G7, 0, 0, 0,
NOTE_G6, 0, 0, 0,
NOTE_C7, 0, 0, NOTE_G6,
0, 0, NOTE_E6, 0,
0, NOTE_A6, 0, NOTE_B6,
0, NOTE_AS6, NOTE_A6, 0,
NOTE_G6, NOTE_E7, NOTE_G7,
NOTE_A7, 0, NOTE_F7, NOTE_G7,
0, NOTE_E7, 0, NOTE_C7,
NOTE_D7, NOTE_B6, 0, 0,
NOTE_C7, 0, 0, NOTE_G6,
0, 0, NOTE_E6, 0,
0, NOTE_A6, 0, NOTE_B6,
0, NOTE_AS6, NOTE_A6, 0,
NOTE_G6, NOTE_E7, NOTE_G7,
NOTE_A7, 0, NOTE_F7, NOTE_G7,
0, NOTE_E7, 0, NOTE_C7,
NOTE_D7, NOTE_B6, 0, 0
};
//Mario main them tempo
int tempo[] = {
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
9, 9, 9,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
9, 9, 9,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
};
//Underworld melody
int underworld_melody[] = {
NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
NOTE_AS3, NOTE_AS4, 0,
0,
NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
NOTE_AS3, NOTE_AS4, 0,
0,
NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
NOTE_DS3, NOTE_DS4, 0,
0,
NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
NOTE_DS3, NOTE_DS4, 0,
0, NOTE_DS4, NOTE_CS4, NOTE_D4,
NOTE_CS4, NOTE_DS4,
NOTE_DS4, NOTE_GS3,
NOTE_G3, NOTE_CS4,
NOTE_C4, NOTE_FS4, NOTE_F4, NOTE_E3, NOTE_AS4, NOTE_A4,
NOTE_GS4, NOTE_DS4, NOTE_B3,
NOTE_AS3, NOTE_A3, NOTE_GS3,
0, 0, 0
};
//Underwolrd tempo
int underworld_tempo[] = {
12, 12, 12, 12,
12, 12, 6,
3,
12, 12, 12, 12,
12, 12, 6,
3,
12, 12, 12, 12,
12, 12, 6,
3,
12, 12, 12, 12,
12, 12, 6,
6, 18, 18, 18,
6, 6,
6, 6,
6, 6,
18, 18, 18, 18, 18, 18,
10, 10, 10,
10, 10, 10,
3, 3, 3
};
void setup(void)
{
pinMode(5, OUTPUT);//buzzer
pinMode(6, OUTPUT);
digitalWrite(6, LOW);
}
void loop()
{
//sing the tunes
sing(1);
sing(1);
sing(2);
}
int song = 0;
void sing(int s) {
// iterate over the notes of the melody:
song = s;
if (song == 2) {
Serial.println(" 'Underworld Theme'");
int size = sizeof(underworld_melody) / sizeof(int);
for (int thisNote = 0; thisNote < size; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / underworld_tempo[thisNote];
buzz(melodyPin, underworld_melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
buzz(melodyPin, 0, noteDuration);
}
} else {
Serial.println(" 'Mario Theme'");
int size = sizeof(melody) / sizeof(int);
for (int thisNote = 0; thisNote < size; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / tempo[thisNote];
buzz(melodyPin, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
buzz(melodyPin, 0, noteDuration);
}
}
}
void buzz(int targetPin, long frequency, long length) {
long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
//// 1 second's worth of microseconds, divided by the frequency, then split in half since
//// there are two phases to each cycle
long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
//// multiply frequency, which is really cycles per second, by the number of seconds to
//// get the total number of cycles to produce
for (long i = 0; i < numCycles; i++) { // for the calculated length of time...
digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram
delayMicroseconds(delayValue); // wait for the calculated delay value
digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram
delayMicroseconds(delayValue); // wait again or the calculated delay value
}
}
As we've seen, CoilCell can also produce buzzing tones - Check out the CoilCell GitHub Repository for more code examples and technical documentation!
CoilCell is a thin planar PCB coil built on a multi-layered PCB with an integrated driver that simplifies magnetic control. In this post, we’ll explore its circuitry and how it functions.
CoilCell is a PCB-based planar coil that generate a magnetic field that can interact with magnets. It is available in two configurations:
With its DRV8837 H-Bridge driver, CoilCell allows control of current flow, determining both magnetic polarity and strength via the 2 input signals.
Unlike the CoilPad (which requires an external driver) this CoilCell module has an integrated DRV8837 H-Bridge driver. It enables bidirectional current flow, allowing the coil to generate a north or south magnetic field:
IN1 = VCC/PWM
, IN2 = GND
IN1 = GND
, IN2 = VCC/PWM
IN1 = GND
, IN2 = GND
For added clarity, an onboard LED provides visual feedback, indicating the polarity of the output.
These safety features help prevent damage from overheating or incorrect wiring, ensuring reliable operation.
To start using CoilCell, follow these steps:
Solder the power and input pins to your microcontroller.
The VCC must be connected to a maximum supply voltage of 5V.
If using multiple CoilCells, the side pads allow for easy daisy-chaining to share power and control signals across multiple units.
To simplify programming we had a CoilCell library with easy to use functions.
Use our CodeCell module which is designed to be pin-to-pin compatible with CoilCell. With CodeCell, you can add wireless control and interactive sensing, unlocking new possibilities for your projects.
With the CoilCell module you have everything you need to start experimenting and build your own fun magnetic actuators! Check out the CoilCell Schematics here to explore its circuit design and start integrating it into your next project!
CoilCell is a compact planar coil designed for various DIY projects. Whether you're just starting or are an experienced maker, CoilCell offers easy integration to simplify your creations. In this tutorial we will explain:
What is CoilCell?
CoilCell is a thin, planar coil built on a multi-layered PCB, with an integrated driver that simplifies controlling magnetic polarity and strength. It is available in two configurations:
Magnetic Applications
Safety Tips
While using the 2.5W 200-Turns CoilCell, it can potentially heating up to 110°C, especially when combined with the iron back-plate. Follow these precautions:
How Does CoilCell Work?
CoilCell utilizes an on-board DRV8837 H-bridge chip to control current flow through the coil, allowing it to switch magnetic polarity:
The DRV8837 chip provides overcurrent protection, undervoltage lockout, and thermal shutdown features, ensuring safe operation.
Getting Started with CoilCell
Wiring one of the input-pins to VCC will instantly turn on the CoilCell. But to make it smarter we also developed a Arduino Software Library to make it easier for you to get started.
You will need to write some basic code to tell CoilCell what to do. Don’t worry, it’s quite simple! Start by downloading the "CoilCell" library from the Arduino's Library Manager. Once this is installed, we are ready to control your device. There are multiple examples that can help you get started but next we will breakdown and understand all the functions:
Before we start make sure you connect the CoilCell to your microcontroller -- We recommend using a CodeCell which is pin to pin compatible, the same size, supports all the library functions, and can add wireless control + interactive sensing.
1. Initialize CoilCell
#include <CoilCell.h>
CoilCell myCoilCell(IN1, IN2); // Replace IN1 and IN2 with your specific pins
void setup() {
myCoilCell.Init(); // Initializes the CoilCell
}
This code configures the CoilCell, setting it up for magnetic control based on your selected pins and microcontroller.
2. Bounce(bool direction, uint8_t ms_duration)The Bounce()
function makes a magnet bounce up and down. The first parameter, sets the polarity of the CoilCell and the delay_ms
, sets the duration for which the magnet is repelled./
myCoilCell.Bounce(true, 20); //Bounce the magnet up for 20ms
3. Buzz(uint16_t us_buzz)
Create a buzzing sound by rapidly alternating the coil’s polarity. Adjust 'us_buzz' to control the frequency of the buzz.
myCoilCell.Buzz(80); // Generates a buzzing effect at 80 microseconds intervals
4. Tone()
This function plays a default tone by making the CoilCell vibrate at different saved frequencies.
myCoilCell.Tone(); // Plays varying tones
5. Drive(bool direction, uint8_t power_percent)
By using the CodeCell or any other ESP32 microcontroller, this function lets control the coil’s magnetic polarity and strength. The magnetic strength is adjusted by the 'power_percent', which controls how far the magnet is pushed from the coil.
myCoilCell.Drive(true, 75); // Drive the coil north with 75% strength
6. Toggle(uint8_t power_percent)
By using the CodeCell or any other ESP32 microcontroller, this function toggles the coil’s polarity at a set power level, useful for simple magnetic flipping actions.
myCoilCell.Toggle(60); // Toggle polarity at 60% power
For other Arduino devices, this command makes the coilcell flip its direction at full power.
myCoilCell.Toggle(); // Toggle polarity at 100% power
7. Vibrate(bool smooth, uint8_t power_percent, uint16_t vib_speed_ms)
This function flips the coil’s polarity at a specified speed and power. Setting 'smooth' to true creates smoother motions, ideal for slow frequencies below 2 Hz.
myCoilCell.Vibrate(true, 50, 1000); // Smooth vibration at 50% power every 1000 ms
For other Arduino devices, this command makes the coilcell flip its polarity at full power.
myCoilCell.Vibrate(100); // Vibrate at 100% power every 100 ms
Here's an example where we initialize a CoilCell to make a 5mm diameter ball magnet bounce. In this example, the CoilCell is initialized with pins 5 and 6. The setup()
function calls myCoilCell.Init()
to configure the CoilCell. In the loop()
, the Bounce()
function is used to make the magnet bounce upwards for 20 milliseconds, followed by a 600 milliseconds delay that attracts the magnet back down.
#include <CoilCell.h>
#define IN1_pin1 5
#define IN1_pin2 6
CoilCell myCoilCell(IN1_pin1, IN1_pin2);
void setup() {
myCoilCell.Init(); /*Initialize the CoilCell*/
}
void loop() {
myCoilCell.Bounce(0, 20); /*Bounce the magnet up for 20ms*/
delay(600); /*Attract the magnet back down for 600ms*/
}
In this next example we use the CodeCell's Motion Sensor to detect tapping. When a new tap is detected the CoilCell flips its magnetic polarity and sets a 1 second delay to flash the onboard LED to yellow.
#include <CodeCell.h>
#include <CoilCell.h>
#define IN1_pin1 5
#define IN1_pin2 6
CoilCell myCoilCell(IN1_pin1, IN1_pin2);
CodeCell myCodeCell;
void setup() {
Serial.begin(115200); /* Set Serial baud rate to 115200. Ensure Tools/USB_CDC_On_Boot is enabled if using Serial. */
myCodeCell.Init(MOTION_TAP_DETECTOR); /*Initializes Tap Detection Sensing*/
myCoilCell.Init();
myCoilCell.Tone();
}
void loop() {
if (myCodeCell.Run()) {
/*Runs every 100ms*/
if (myCodeCell.Motion_TapRead()) {
/*If Tap is detected shine the LED Yellow for 1 sec and flip the CoilCell's polarity*/
myCodeCell.LED(0XA0, 0x60, 0x00U);
myCoilCell.Toggle(100);
delay(1000);
}
}
}
With these basic functions, you can start experimenting with CoilCell in your projects. Whether you’re controlling magnets, creating interactive displays, or experimenting with magnetic forces, CoilCell provides a simple and effective solution.
If you have any more question about the CoilCell feel free to email us and we will gladly help out!
Join our Community ~ Be the first to know about new products and get exciting deals!
© 2025 Microbots.