Menu
Microbots
0
  • Learn
  • Shop
    • Maker-Modules
    • Maker-Packs
    • Tools & Gears
    • Robots & Displays
    • All Products
  • Community
    • Education
    • Software
  • About
    • Our Story
    • Reach Out
    • FAQs
  • English
  • Your Cart is Empty
Microbots
  • Learn
  • Shop
    • Maker-Modules
    • Maker-Packs
    • Tools & Gears
    • Robots & Displays
    • All Products
  • Community
    • Education
    • Software
  • About
    • Our Story
    • Reach Out
    • FAQs
  • Language

  • 0 0

FlatFlap - Creating Flapping Motion

This guide explains how the FlatFlap can control its flapping motion, how frequency and polarity affect its movement, and how to generate its drive signals.

How it works?

To make FlatFlap move, an electric current is applied its coil, generating a magnetic field. By reversing the polarity at a set frequency, we create a repetitive push-pull motion that causes the flap to oscillate.

The flapping frequency can be controlled within the range of 1 Hz to 25 Hz, which means FlatFlap can flap 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.

Generating a Square Wave for Flapping

A square wave signal is required to make the FlatFlap flap. An H-Bridge driver like our DriveCell, is needed to power the actuator and switch its polarity, The input signals of the square wave can be generated using a simple digitalWrite() commands in Arduino:

#define FLAP_PIN1 2
#define FLAP_PIN2 3

void setup() {
  pinMode(FLAP_PIN1, OUTPUT);
  pinMode(FLAP_PIN2, OUTPUT);
}

void loop() {
  digitalWrite(FLAP_PIN1, HIGH);
  digitalWrite(FLAP_PIN2, LOW);
  delay(100); // Adjust delay for desired flapping speed
  
  digitalWrite(FLAP_PIN1, LOW);
  digitalWrite(FLAP_PIN2, HIGH);
  delay(100);
}

This simple code creates a square wave oscillation, making FlatFlap flap continuously. You can adjust the delay time to change the flapping frequency.

Flapping Motion & Frequency  

The frequency you select will depends on your project's requirements:

  • Low Frequencies (1–10 Hz): Slow, controlled motion suitable for delicate applications
  • Medium Frequencies (10–18 Hz): Moderate flapping speed for natural motion effects
  • High Frequencies (18–25 Hz): Rapid oscillations for vibration or quick actuation

By adjusting the delay time in the Arduino code, you can fine-tune the frequency to match your project needs.

Factors Affecting FlatFlap’s Motion

Several factors influence the effectiveness of the flapping motion:

  1. Supply Voltage - A higher voltage increases the strength of the magnetic field, resulting in stronger flaps.
  2. Current Flow - Consistent current source ensures stable motion
  3. Mechanical Load - Although FlatFlap can only lift around 2g, any added weight to the flap affects its response time, maximum achievable frequency and resonant frequency.

Optimizing Flapping PWM

The code example above generate a basic square wave, which as you might observed drives the flap in a hard manner, an on-off approach, which at slow frequencies might not be desirable. To smooth this out we need to use Pulse width modulation (PWM) on both outputs. This method gradually changes the magnetic field intensity, reducing mechanical stress on the FlatFlap actuator.

This function is automatically handled within our DriveCell library:

#include <DriveCell.h>

#define IN1_pin1 2
#define IN1_pin2 3
#define IN2_pin1 5
#define IN2_pin2 6

DriveCell FlatFlap1(IN1_pin1, IN1_pin2);
DriveCell FlatFlap2(IN2_pin1, IN2_pin2);

uint16_t flap_counter = 0;

void setup() {
  FlatFlap1.Init();
  FlatFlap2.Init();

  FlatFlap1.Tone();
  FlatFlap2.Tone();
}

void loop() {
  delay(1);
  flap_counter++;
  if (flap_counter < 2000U) {
    FlatFlap1.Run(0, 100, 100); //Square Wave mode
    FlatFlap2.Run(0, 100, 100); //Square Wave mode
  }
  else if (flap_counter < 8000U) {
    FlatFlap1.Run(1, 100, 1000); //Smooth PWM Wave mode
    FlatFlap2.Run(1, 100, 1000); //Smooth PWM Wave mode
  } else {
    flap_counter = 0U;
    FlatFlap1.Drive(0, 100); //Flap South at 100% power
    FlatFlap2.Drive(1, 100); //Flap North at 100% power
    delay(500);
    FlatFlap1.Drive(1, 100); //Flap North at 100% power
    FlatFlap2.Drive(1, 100); //Flap North at 100% power
    delay(500);
    FlatFlap1.Drive(1, 100); //Flap North at 100% power
    FlatFlap2.Drive(0, 100); //Flap South at 100% power
    delay(500);
    FlatFlap1.Drive(1, 50); //Flap North at 50% power
    FlatFlap2.Drive(1, 75); //Flap North at 75% power
    delay(500);
    FlatFlap1.Drive(0, 25); //Flap South at 25% power
    FlatFlap2.Drive(0, 50); //Flap South at 50% power
  }
}

Understanding the Functions:

  • Init() → Initializes DriveCell and sets up the input pins
  • Drive(direction, power) → Controls actuator:
    • direction → 1 (north) / 0 (south)
    • power → Magnetic-field strength (0 to 100%)
  • Run(smooth, power, speed_ms) → Oscillate the FlatFlap in either a square wave or a smoother PWM wave.
    • smooth → 1 (pwm wave) / 0 (square wave)
    • power → Magnetic-field strength (0 to 100%)
    • power → Flipping speed in milliseconds

⚠ Note: The Run() & Drive() function uses a high-speed PWM timer, making it compatible only with CodeCell and ESP32-based devices.

Conclusion

With these techniques, you can integrate FlatFlap into robotics, haptics and art! Check out the DriveCell GitHub Repository for more code examples and technical documentation!

  • Share:


Also in FlatFlap

FlatFlap - Creating Position Control
FlatFlap - Creating Position Control

Read More

FlatFlap - Creating Pulsing Motion
FlatFlap - Creating Pulsing Motion

Read More

Using FlatFlap to Generate Buzzing Tones
Using FlatFlap to Generate Buzzing Tones

Read More

Follow

Github

  • About
  • Software
  • Education
  • Contact
  • FAQs
  • Terms
  • Refund Policy
  • Privacy Policy

Join our Community ~ Be the first to know about new products and get exciting deals!

© 2025 Microbots.