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 ist eine kompakte Planarspule, die für verschiedene DIY-Projekte entwickelt wurde. Egal, ob Sie gerade erst anfangen oder ein erfahrener Hersteller sind, CoilCell bietet eine einfache Integration, um Ihre Kreationen zu vereinfachen. In diesem Tutorial erklären wir:
Was ist CoilCell?
CoilCell ist eine dünne, planare Spule auf einer mehrschichtigen Leiterplatte mit integriertem Treiber, der die Steuerung der magnetischen Polarität und Stärke vereinfacht. Sie ist in zwei Konfigurationen erhältlich:
Magnetische Anwendungen
Sicherheitstipps
Bei Verwendung der 2,5 W 200-Windungen -Spulenzelle kann es zu einer Erhitzung von bis zu 110 °C kommen, insbesondere in Kombination mit der Eisenrückplatte. Befolgen Sie diese Vorsichtsmaßnahmen:
Wie funktioniert CoilCell?
CoilCell verwendet einen integrierten DRV8837-H-Brückenchip zur Steuerung des Stromflusses durch die Spule, wodurch die magnetische Polarität gewechselt werden kann:
Der DRV8837-Chip verfügt über Überstromschutz, Unterspannungssperre und thermische Abschaltungsfunktionen und gewährleistet so einen sicheren Betrieb.
Erste Schritte mit CoilCell
Wenn Sie einen der Eingangspins mit VCC verbinden, wird die CoilCell sofort eingeschaltet. Um es noch intelligenter zu machen, haben wir auch eine Arduino-Softwarebibliothek entwickelt, die Ihnen den Einstieg erleichtert.
Sie müssen einen einfachen Code schreiben, um CoilCell mitzuteilen, was zu tun ist. Keine Sorge, das ist ganz einfach! Laden Sie zunächst die Bibliothek „CoilCell“ aus dem Bibliotheksmanager von Arduino herunter. Sobald diese installiert ist, können wir Ihr Gerät steuern. Es gibt mehrere Beispiele, die Ihnen den Einstieg erleichtern können, aber als Nächstes werden wir alle Funktionen aufschlüsseln und verstehen:
Bevor wir beginnen, stellen Sie sicher, dass Sie die CoilCell an Ihren Mikrocontroller anschließen. Wir empfehlen die Verwendung einer CodeCell , die Pin-zu-Pin-kompatibel ist, die gleiche Größe hat, alle Bibliotheksfunktionen unterstützt und drahtlose Steuerung und interaktive Sensorik hinzufügen kann.
1. CoilCell initialisieren
#include <CoilCell.h>
CoilCell myCoilCell(IN1, IN2); // Replace IN1 and IN2 with your specific pins
void setup() {
myCoilCell.Init(); // Initializes the CoilCell
}
Dieser Code konfiguriert die CoilCell und richtet sie basierend auf den von Ihnen ausgewählten Pins und dem Mikrocontroller für die magnetische Steuerung ein.
2. Bounce (bool Richtung, uint8_t ms_Dauer) Die Funktion Bounce()
lässt einen Magneten auf und ab hüpfen. Der erste Parameter legt die Polarität der CoilCell fest und delay_ms
legt die Dauer fest, für die der Magnet abgestoßen wird./
myCoilCell.Bounce(true, 20); //Bounce the magnet up for 20ms
3. Buzz (uint16_t us_buzz)
Erzeugen Sie ein summendes Geräusch, indem Sie die Polarität der Spule schnell ändern. Passen Sie „us_buzz“ an, um die Frequenz des Summens zu steuern.
myCoilCell.Buzz(80); // Generates a buzzing effect at 80 microseconds intervals
4. Ton()
Diese Funktion spielt einen Standardton ab, indem sie die CoilCell mit verschiedenen gespeicherten Frequenzen vibrieren lässt.
myCoilCell.Tone(); // Plays varying tones
5. Antrieb (bool Richtung, uint8_t Leistung_Prozent)
Mithilfe der CodeCell oder eines anderen ESP32-Mikrocontrollers können Sie mit dieser Funktion die magnetische Polarität und Stärke der Spule steuern. Die magnetische Stärke wird durch den Wert „power_percent“ eingestellt, der steuert, wie weit der Magnet von der Spule weggeschoben wird.
myCoilCell.Drive(true, 75); // Drive the coil north with 75% strength
6. Umschalten (uint8_t power_percent)
Durch die Verwendung der CodeCell oder eines anderen ESP32-Mikrocontrollers schaltet diese Funktion die Polarität der Spule bei einem festgelegten Leistungsniveau um, was für einfache magnetische Umklappaktionen nützlich ist.
myCoilCell.Toggle(60); // Toggle polarity at 60% power
Bei anderen Arduino-Geräten bewirkt dieser Befehl, dass die Spulenzelle bei voller Leistung ihre Richtung ändert.
myCoilCell.Toggle(); // Toggle polarity at 100% power
7. Vibrieren (bool glatt, uint8_t Leistung_Prozent, uint16_t vib_Geschwindigkeit_ms)
Diese Funktion kehrt die Polarität der Spule mit einer bestimmten Geschwindigkeit und Leistung um. Wenn Sie „smooth“ auf „true“ setzen, entstehen sanftere Bewegungen, ideal für langsame Frequenzen unter 2 Hz.
myCoilCell.Vibrate(true, 50, 1000); // Smooth vibration at 50% power every 1000 ms
Bei anderen Arduino-Geräten bewirkt dieser Befehl, dass die Spulenzelle bei voller Leistung ihre Polarität umkehrt.
myCoilCell.Vibrate(100); // Vibrate at 100% power every 100 ms
Hier ist ein Beispiel, bei dem wir eine CoilCell initialisieren, um einen Kugelmagneten mit 5 mm Durchmesser hüpfen zu lassen. In diesem Beispiel wird die CoilCell mit den Pins 5 und 6 initialisiert. Die Funktion setup()
ruft myCoilCell.Init()
auf, um die CoilCell zu konfigurieren. In loop()
wird die Funktion Bounce()
verwendet, um den Magneten 20 Millisekunden lang nach oben hüpfen zu lassen, gefolgt von einer Verzögerung von 600 Millisekunden, die den Magneten wieder nach unten zieht.
#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*/
}
Im nächsten Beispiel verwenden wir den Bewegungssensor der CodeCell, um ein Antippen zu erkennen. Wenn ein erneutes Antippen erkannt wird, wechselt die CoilCell ihre magnetische Polarität und stellt eine Verzögerung von 1 Sekunde ein, damit die integrierte LED gelb blinkt.
#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); /* Stellen Sie die serielle Baudrate auf 115200 ein. Stellen Sie sicher, dass Tools/USB_CDC_On_Boot aktiviert ist, wenn Sie die serielle Schnittstelle verwenden. */ myCodeCell.Init(MOTION_TAP_DETECTOR); /*Initialisiere die Antipperkennung*/ meineCoilCell.Init(); meineCoilCell.Tone(); } void schleife() { wenn (myCodeCell.Run()) { /*Läuft alle 100 ms*/ wenn (myCodeCell.Motion_TapRead()) { /*Wenn ein Tippen erkannt wird, leuchtet die LED 1 Sekunde lang gelb und die Polarität der CoilCell wird umgekehrt*/ myCodeCell.LED(0XA0, 0x60, 0x00U); meineCoilCell.Toggle(100); Verzögerung (1000); } } }
Mit diesen Grundfunktionen können Sie mit CoilCell in Ihren Projekten experimentieren. Egal, ob Sie Magnete steuern, interaktive Displays erstellen oder mit magnetischen Kräften experimentieren, CoilCell bietet eine einfache und effektive Lösung.
Wenn Sie weitere Fragen zur CoilCell haben, senden Sie uns einfach eine E-Mail und wir helfen Ihnen gerne weiter!
Erfahren Sie als Erster von neuen Projekten und sichern Sie sich spannende Angebote!
© 2025 Microbots.