Face-Tracking Animatronic Dragon Robot – an Artificial Intelligence Robot!

by Random Stuff We Make in Circuits > Robots

2373 Views, 21 Favorites, 0 Comments

Face-Tracking Animatronic Dragon Robot – an Artificial Intelligence Robot!

Husky Lens Face Recognition Dragon Robot | Artificial Intelligence | AI Projects | DIY AI Robot
VID_20230630_214144_AdobeExpress.gif

Hey Dragon Tamers! 🐉 Ready to bring the mythical creatures of yore to life? We're going to build a face-tracking animatronic dragon robot that follows your every move! You'll be the Daenerys Targaryen of the DIY world!

Follow us

Youtube: Random Stuff We Make!

Instagram: Random Stuff We Make!

What Will You Learn?

  • Crafting a dragon from cardboard, dreams, and sheer determination
  • Using Husky Lens to teach your dragon to recognize its master
  • Coding with Arduino to animate your dragon's movements
  • Taming a cardboard beast (not covered in standard dragon lore!)

Supplies

DFRobot-Gravity-HUSKYLENS-An-Eas.png
robu-3-10.png
Arduino-Uno-Rev3-SMD-2.png
cardboard-.jpg
Asset 1.png
  • DF Robot Husky Lens (For the eyes of the dragon!)
  • Servo Motor (Muscles for the dragon's neck!)
  • Arduino Board (The brain of the dragon!)
  • Cardboard & Dragon Template (The flesh and scales!)
  • Wit & Grit (Sprinkle generously!)

Assemble Your Dragon

Asset 1.png
Step 1.png
Step 2.png
Step 3.png
Step 4.png
Step 5.png
Step 6.png
Step 7.png
Step 8.png

Time to release your inner origami master!

  1. Download our fabulous dragon template, print on A4 sheet, and cut.
  2. Assemble the cardboard pieces following the template.
  3. Attach the servo motor to the body & the servo arm to the neck.
  4. Feel free to name your dragon something epic like "Draco."

Learn a Face With Husky Lens

3.jpg

Your dragon needs to know its master!

  1. Connect Husky Lens to the power using USB.
  2. Target the camera to the face.
  3. Click on the Learning button in the top right corner.
  4. High-five yourself, you're now friends with a dragon!

If you need a visual guide, check this out: Face Recognition Husky Lens

Programming the Arduino Board

Time to breathe life into your cardboard creature!

  1. Connect the Arduino board to your computer.
  2. Open the Arduino IDE.
  3. Add Husky Lens Library.
  4. Use the code below to control the servo motor based on the face position.

Connect Servo to your Arduino board:

  • Red Wire - 5V Arduino
  • Brown Wire - GND Arduino
  • Orange Wire - Digital Pin 9 Arduino

Note: Change the "int threshold" value for fine-tuning the tracking.

#include <HUSKYLENS.h>
#include <Wire.h>
#include <Servo.h>


HUSKYLENS huskylens;
Servo servo;


int lastServoPosition = 90; // Initial position
int threshold = 5; // Set a threshold for position changes


void setup() {
    servo.attach(9); // Connect the servo to pin 9
    servo.write(90);
    Serial.begin(115200);
    Wire.begin();
    while (!huskylens.begin(Wire)) {
        Serial.println(F("HUSKYLENS not connected!"));
        delay(100);
    }
    huskylens.writeAlgorithm(ALGORITHM_OBJECT_TRACKING);
}


void loop() {
    if (!huskylens.request()) return;
    
    for (int i = 0; i < huskylens.countBlocks(); i++){
        HUSKYLENSResult result = huskylens.getBlock(i);
        
        int x_center = result.xCenter;
        int width = result.width;
        int y_center = result.yCenter;
        int height = result.height;
        int ID = result.ID;
        
        Serial.print("Object tracked at X: ");
        Serial.print(x_center);
        Serial.print(", Y: ");
        Serial.print(y_center);
        Serial.print(", Width: ");
        Serial.print(width);
        Serial.print(", Height: ");
        Serial.println(height);
        Serial.print("Tracked ID: ");
        Serial.println(ID);
        delay(100);


        // Map the x-coordinate to the servo range (0-180 degrees)
        int servoPosition = map(x_center, 0, 320, 180, 0);
        
        // Calculate the adjustment needed
        int servoAdjustment = servoPosition - lastServoPosition; 


        // Limit the adjustment to prevent the servo from moving too quickly
        if (servoAdjustment > threshold) {
            servoAdjustment = threshold;
        } else if (servoAdjustment < -threshold) {
            servoAdjustment = -threshold;
        }


        // Adjust the servo position and update the last position
        servo.attach(9);
        servo.write(lastServoPosition + servoAdjustment);
        lastServoPosition += servoAdjustment;


        delay(15); // Add a delay to allow the servo to move to the new position
        //servo.detach();
    }
}

Tame Your Dragon

The bond is complete!

  1. Connect everything.
  2. Power up your Arduino board.
  3. Stand in front of your dragon.
  4. Watch in awe as it tilts its head, following your every move!
  5. Optional: laugh maniacally – you've earned it!


Conclusion

Congratulations, Dragon Whisperer! You've created a fantastical face-tracking animatronic dragon robot, using the powers of Arduino, Husky Lens, and cardboard wizardry!

Now go out there and conquer the world with your new pet dragon! Or at least share your accomplishment on social media.

Need more visual guidance? Visit our YouTube channel for tutorials, behind-the-scenes footage, and endless dragon fun!

Youtube: Random Stuff We Make!

Instagram: Random Stuff We Make!

Happy Crafting, fellow Dragon Tamers! 🐉

Please note: No dragons were harmed in the making of this tutorial. Always practice safe dragon-handling. Not responsible for any dragon-induced infernos.