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 est une bobine planaire compacte conçue pour divers projets DIY. Que vous débutiez ou que vous soyez un maker expérimenté, CoilCell offre une intégration facile pour simplifier vos créations. Dans ce tutoriel, nous vous expliquerons :
Qu'est-ce que CoilCell ?
CoilCell est une bobine mince et plane construite sur un PCB multicouche, avec un pilote intégré qui simplifie le contrôle de la polarité et de la force magnétiques. Elle est disponible en deux configurations :
Applications magnétiques
Conseils de sécurité
Lors de l'utilisation du CoilCell 2,5 W 200 tours, il peut potentiellement chauffer jusqu'à 110 °C, en particulier lorsqu'il est combiné avec la plaque arrière en fer. Suivez ces précautions :
Comment fonctionne CoilCell ?
CoilCell utilise une puce de pont en H DRV8837 intégrée pour contrôler le flux de courant à travers la bobine, lui permettant de changer de polarité magnétique :
La puce DRV8837 offre une protection contre les surintensités, un verrouillage en cas de sous-tension et des fonctions d'arrêt thermique, garantissant un fonctionnement sûr.
Premiers pas avec CoilCell
Le câblage d'une des broches d'entrée sur VCC activera instantanément la CoilCell . Mais pour le rendre plus intelligent, nous avons également développé une bibliothèque de logiciels Arduino pour vous faciliter la mise en route.
Vous devrez écrire un code de base pour indiquer à CoilCell ce qu'il doit faire. Ne vous inquiétez pas, c'est assez simple ! Commencez par télécharger la bibliothèque « CoilCell » à partir du gestionnaire de bibliothèques de l'Arduino. Une fois celle-ci installée, nous sommes prêts à contrôler votre appareil. Il existe plusieurs exemples qui peuvent vous aider à démarrer, mais nous allons maintenant décomposer et comprendre toutes les fonctions :
Avant de commencer, assurez-vous de connecter le CoilCell à votre microcontrôleur. Nous vous recommandons d'utiliser un CodeCell compatible broche à broche, de la même taille, prenant en charge toutes les fonctions de la bibliothèque et pouvant ajouter un contrôle sans fil + une détection interactive.
1. Initialiser CoilCell
#include <CoilCell.h>
CoilCell myCoilCell(IN1, IN2); // Replace IN1 and IN2 with your specific pins
void setup() {
myCoilCell.Init(); // Initializes the CoilCell
}
Ce code configure le CoilCell , le configurant pour le contrôle magnétique en fonction de vos broches et de votre microcontrôleur sélectionnés.
2. Bounce(bool direction, uint8_t ms_duration) La fonction Bounce()
fait rebondir un aimant de haut en bas. Le premier paramètre définit la polarité de la CoilCell et le delay_ms
définit la durée pendant laquelle l'aimant est repoussé.
myCoilCell.Bounce(true, 20); //Bounce the magnet up for 20ms
3. Buzz (uint16_t us_buzz)
Créez un bourdonnement en alternant rapidement la polarité de la bobine. Ajustez « us_buzz » pour contrôler la fréquence du bourdonnement.
myCoilCell.Buzz(80); // Generates a buzzing effect at 80 microseconds intervals
4. Tonalité()
Cette fonction joue une tonalité par défaut en faisant vibrer la CoilCell à différentes fréquences enregistrées.
myCoilCell.Tone(); // Plays varying tones
5. Drive(bool direction, uint8_t power_percent)
En utilisant le CodeCell ou tout autre microcontrôleur ESP32, cette fonction permet de contrôler la polarité et la force magnétique de la bobine. La force magnétique est ajustée par le « power_percent », qui contrôle la distance à laquelle l'aimant est poussé par rapport à la bobine.
myCoilCell.Drive(true, 75); // Drive the coil north with 75% strength
6. Basculer(uint8_t power_percent)
En utilisant le CodeCell ou tout autre microcontrôleur ESP32, cette fonction bascule la polarité de la bobine à un niveau de puissance défini, utile pour des actions de retournement magnétique simples.
myCoilCell.Toggle(60); // Toggle polarity at 60% power
Pour les autres appareils Arduino, cette commande fait que la bobine inverse sa direction à pleine puissance.
myCoilCell.Toggle(); // Toggle polarity at 100% power
7. Vibrer (bool lisse, uint8_t power_percent, uint16_t vib_speed_ms)
Cette fonction inverse la polarité de la bobine à une vitesse et une puissance spécifiées. Le réglage « smooth » sur true crée des mouvements plus fluides, idéaux pour les fréquences lentes inférieures à 2 Hz.
myCoilCell.Vibrate(true, 50, 1000); // Smooth vibration at 50% power every 1000 ms
Pour les autres appareils Arduino, cette commande fait que la bobine inverse sa polarité à pleine puissance.
myCoilCell.Vibrate(100); // Vibrate at 100% power every 100 ms
Voici un exemple où nous initialisons une CoilCell pour faire rebondir un aimant à bille de 5 mm de diamètre. Dans cet exemple, la CoilCell est initialisée avec les broches 5 et 6. La fonction setup()
appelle myCoilCell.Init()
pour configurer la CoilCell . Dans la fonction loop()
, la fonction Bounce()
est utilisée pour faire rebondir l'aimant vers le haut pendant 20 millisecondes, suivi d'un délai de 600 millisecondes qui attire l'aimant vers le bas.
#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*/
}
Dans l'exemple suivant, nous utilisons le capteur de mouvement du CodeCell pour détecter les tapotements. Lorsqu'un nouveau tapotement est détecté, le CoilCell inverse sa polarité magnétique et définit un délai d'une seconde pour faire clignoter la LED intégrée en jaune.
#include <CodeCell.h> #include <CoilCell.h> #define IN1_pin1 5 #define IN1_pin2 6 CoilCell myCoilCell(IN1_pin1, IN1_pin2); CodeCell myCodeCell;
vide configuration() { Serial.begin(115200); /* Définissez le débit en bauds série sur 115 200. Assurez-vous que Tools/USB_CDC_On_Boot est activé si vous utilisez Serial. */ myCodeCell.Init(MOTION_TAP_DETECTOR); /*Initialise la détection de pression*/ maCoilCell.Init(); maCelluleCoil.Tone(); } boucle vide() { si (myCodeCell.Run()) { /*S'exécute toutes les 100 ms*/ si (myCodeCell.Motion_TapRead()) { /*Si Tap est détecté, la LED s'allume en jaune pendant 1 seconde et inverse la polarité de la CoilCell*/ monCodeCell.LED(0XA0, 0x60, 0x00U); maCoilCell.Toggle(100); délai(1000); } } }
Grâce à ces fonctions de base, vous pouvez commencer à expérimenter CoilCell dans vos projets. Que vous contrôliez des aimants, créiez des affichages interactifs ou expérimentiez des forces magnétiques, CoilCell offre une solution simple et efficace.
Si vous avez d'autres questions sur le CoilCell, n'hésitez pas à nous envoyer un e-mail et nous serons heureux de vous aider !
Soyez le premier informé des nouveaux projets et bénéficiez d'offres intéressantes !
© 2025 Microbots.