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 Position Control


FlatFlap is a compact actuator made to flap, however in this guide we will focuses on position control - keeping the flap in a fixed position using a controlled duty cycle. This method is useful for applications that require the flap to stay in a specific angle for long periods of time, instead of continuous oscillation.

How It Works

FlatFlap operates by passing current through its coil, generating a magnetic field that interacts with its magnet. Instead of applying a short pulse or oscillating the square wave, here, we are going to use Pulse Width Modulation (PWM) to hold the flap at a desired angle.

The duty cycle of the PWM signal controls the strength of the magnetic field, thus changing the angle of the flap.

Fine-Tuning Position Control

Several factors influence position accuracy and stability:

  • Voltage Level – Maximum voltage is 5V - this voltage provides the holding force
  • PWM Frequency – PWM signal frequency of 20kHz is recommended not to operate at the audible tones. 
  • Load Conditions – Any attached mass affects how well the flap maintains position.

Using DriveCell for Position Control

If you're using the DriveCell library, the following example demonstrates how to set different positions:

#include <drivecell.h>

#define IN1_pin1 2
#define IN1_pin2 3
DriveCell FlatFlap1(IN1_pin1, IN1_pin2);

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

void loop() {
  FlatFlap1.Drive(true, 100); // Maximum hold strength
  delay(3000);
  
  FlatFlap1.Drive(true, 75); // Hold with 75% power
  delay(3000);
  
  FlatFlap1.Drive(true, 50); // Hold with 50% power
  delay(3000);
  
  FlatFlap1.Drive(true, 25); // Hold with 25% power
  delay(3000);
}

This code gradually adjusts the duty cycle to hold the flap at different positions.

Understanding the Functions:

  • Init() → Initializes DriveCell and sets up the input pins
  • Drive(bool direction, uint8_t power_percent)
    • direction: true (north) / false (south)
    • power_percent: Magnetic force (0 to 100%)

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

If you're not using an ESP32 device, you can adjust PWM in Arduino using the following code. However, ensure that the waveform frequency is set correctly.

#define FLAP_PIN1 2
#define FLAP_PIN2 3

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

void loop() {
  analogWrite(FLAP_PIN1, 191); // 75% Duty Cycle (191/255)
  digitalWrite(FLAP_PIN2, LOW);
  delay(5000); // Hold for 5 seconds
  
  analogWrite(FLAP_PIN1, 127); // 50% Duty Cycle
  delay(5000);
  
  analogWrite(FLAP_PIN1, 63); // 25% Duty Cycle
  delay(5000);
}

 

Conclusion

By using PWM the FlatFlap can maintain specific angles for long peroids of time, making this feature useful for robotics, haptics, and art. Check out the DriveCell GitHub Repository for more code examples and technical documentation!

  • Share:


Also in FlatFlap

FlatFlap - Creating Pulsing Motion
FlatFlap - Creating Pulsing Motion

Read More

FlatFlap - Creating Flapping Motion
FlatFlap - Creating Flapping 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.