Menu
Microbots
0
  • Learn
    • Getting Started
    • Maker Builds
    • Education
  • Shop
    • Modules & Parts
    • Tools & Gears
    • Robots & Displays
  • About
    • Our Story
    • Reach Out
    • FAQs
  • Sign in
  • English
  • Your Cart is Empty
Microbots
  • Learn
    • Getting Started
    • Maker Builds
    • Education
  • Shop
    • Modules & Parts
    • Tools & Gears
    • Robots & Displays
  • 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:

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!

© 2026 Microbots.

★ Reviews

Let customers speak for us

50 reviews
Write a review
84%
(42)
4%
(2)
2%
(1)
4%
(2)
6%
(3)
21
46
B
CodeCell C6 Drive
Brandon

Awesome product with great tutorials and example code

G
MotorCell
Gerald Kendrick

Very happy with my MotorCell. I'm incorporating it into a prototype project that will hopefully result in me needing a few more!

User picture
A
CodeCell C6 Drive
Anonymous

Great product! Having the IMU, motor driver, and battery management directly on the board is incredibly handy for quick prototyping. Love it!

Improvement ideas:
- using an ESP32 other than the C6 to get more cores. On a single-core chip, WiFi tasks often interfere with real-time applications.
- adding two more motor drivers (with a slightly higher current rating) would be awesome for drone projects!
- I know the compactness of the board is a huge selling point and really optimised, but exposing a few more pins would be great. With the motor drivers already occupying 4 pins, having only 4 GPIOs left can be tight for complex projects (though I’m nitpicking, I’m really pushing this board to its limits!).

A
CodeCell C6
Anonymous

I use CodeCell C6, like all the Features, and compactness. The remote Link to the iPhone with some Controls for 2 Motors is just perfect for the job.

O
CodeCell C6 Drive
Odd_Jayy

This is one of my Favorite finds, this board has everything you need to make a quick and small robot, easy to set up and install. Perfect for beginners or a person who needs to save room in their build.

User picture
123