Flag Waver

Introduction: Flag Waver

This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com). I was inspired to do this project because I wanted to make something that would be cool enough and suitable for a dorm room or as a gift for another person. As a student at USF, I thought it would be really fun if I made a flag waver!

Supplies:

  • Arduino UnoServo
  • Motors (x4) with plastic adapters
  • HC-SR04 Proximity Sensor
  • 16x2 LCD display
  • Breadboard
  • 3D printed box
  • 3D printed servo floor
  • 3D printed cover
  • 1" felt pads (x4)
  • Chopsticks (x2)
  • Fabric
  • Hot glue gun
  • Super glue
  • Portable charger

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Prepare the Flags

In order to make the flags, first cut pieces of fabric into 3" x 5" triangles as shown in the picture above. Next, cut slits into the top of each chopstick long enough to fit the shortest side of the triangle inside the slit. Before placing the fabric inside the chopstick slit, you need to first put super glue on the fabric and on the inside of the chopstick so that the flag stays attached. After the fabric is attached to the chopstick, the next step is to attach the bottoms of the chopsticks to any of the plastic adapters that come with the servo motors. I would recommend using the adapters that are double sided as it would be easier to hold and to maneuver withing the box of the project later. Cut at least half of each wing off so that there is still enough for you to hold or push down with. Hot glue the chopstick flags to each adapter. Let all of the glue dry, and you have finished making the two flags for the project!

Step 2: 3D Print the Parts

3D print the files attached to the link below. The files contain the box for the project, the second floor that houses the servos to turn the flags, the cover of the box to hide all of the mechanical components within the box, and 2 servo holders that will be used for stability.

3D Parts Link

Step 3: Circuitry Setup

At first glance, the wiring might seem overwhelming, but it's actually a lot easier than you might think! First, let's setup the servo motors. Each motor has a female prong with three wires extending from it to the servo motor. These are the ground wire, the power wire, and the pin wire. To explain the motor setup, we are going to divide the 4 motors into 2 groups. These will simply be called Group 1 and Group 2, meaning, whenever a group is mentioned, you will want to perform the following instruction on BOTH motors in that group. The image above will serve as a guideline for the instructions. On the power rails closest to the arduino, connect a wire from the positive rail to the 5V pin, and a wire from the negative rail to the ground. Next, connect the power wire of each servo to the positive rail, and the ground wire to the negative rail. Connect a wire (as shown by the green wire in the image above) to a terminal strip in the middle of the bread board and to the pin 8 on the arduino. Next, connect the servo pin wires from Group 1 (as shown by the yellow wires extending from the servos in the image above) to the same terminal strip as the pin 8 wire so that both of the Group 1 servos are connected to pin 8. Next, connect a wire (as shown by the purple wire in the image above) to another terminal strip in the middle of the breadboard and to the pin 9 on the arduino. Next, following similarly to Group 1, connect the pin wires (as shown by the yellow wires extending from the servos in the image above) to the same terminal strip as the pin 9 wire so that both of the Group 2 servos are connected to pin 9. At this point, all of the servos should be completely connected to the arduino.

The next step is to connect the HC-SR04 sensor to the arduino and the breadboard. It is important that the sensor be placed as far left of the breadboard as possible so that it can fit into its cutout of the box. There are four pins labeled as VCC, Trig, Echo, GND (Ground) on the sensor. Connect a wire from the VCC pin to the positive power rail so that it is connected to the 5V pin. Next, connect a wire from the Trig pin to pin 7 (as shown by the orange wire in the image above). Connect a wire from the Echo pin to pin ~6 (as shown by the blue wire in the image above). Finally connect a wire from the GND pin to the negative power rail so that it is connected to the ground pin. Now the ultrasonic proximity sensor connected to the arduino.

Finally, it's time to connect the LCD display to the arduino. There are also four pins on the LCD display, labeled as GND, VCC, SDA, and SCL. A wire needs to be connected from the GND pin to the negative power rail, and another to be connected from the VCC pin to the positive power rail. A wire needs to be connected from the SDA pin to the arduino SDA pin (the second to last pin). Finally, a wire needs to be connected from the SCL pin to the arduino SCL pin (the last pin). Now all of the circuitry is set up and it is time to work on the code!

Step 4: Code

#include // includes library code
#include // includes library code
#include // includes library code
LiquidCrystal_I2C myDisplay(0x27,16,2); // initialize the library with the numbers of the interface pins
#define trigPin 2 // defines the trigPin as pin 2
#define echoPin 3 // defines the echoPin as pin 3
Servo servo1; // creates servo object
int angle1; // defines angle1 as a variable
Servo servo2; // creates servo object
int angle2; // defines angle2 as a variable</p><p>void setup() {
Serial.begin (9600); // starts the serial communication
pinMode(trigPin, OUTPUT); // sets the trigPin as an output
pinMode(echoPin, INPUT); // sets the echoPin as an input
angle1 = 45; // sets the starting angle for the angle1 variable
angle2 = 0; // sets the starting angle for the angle2 variable
servo1.attach(8); // attaches servo variable to pin 8
servo1.write(angle1); // sets the variable for the angle of the servo
servo2.attach(9); // attaches servo variable to pin 9
servo2.write(angle2); // sets the variable for the angle of the servo
myDisplay.init(); // initializes the LCD screen
myDisplay.backlight(); // turns on the backlight for the LCD screen
}
void loop() {
long duration, distance; // defines the variables
digitalWrite(trigPin, LOW); // trigPin is cleared
delayMicroseconds(2);
digitalWrite(trigPin, HIGH); // trigPin is set to HIGH for 10 microseconds
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); // echoPin is read and translates the travel time to microseconds
distance = (duration/2) / 29.1; // calculates distance
if (distance < 10) { // if the distance from the proximity sensor is less than 10 cm, initiate the function
Serial.println("the distance is less than 10"); // print information to the serial monitor
myDisplay.setCursor(3,0); // places the starting point for the message on the LCD screen
myDisplay.print("Go Bulls!!"); // prints the message onto the LCD screen
for(angle1 = 0; angle1 < 90; angle1++) // spins the first pair of motors 90 degrees
  {
    servo1.write(angle1);
    delay(5);
  }
for(angle2 = 0; angle2 < 180; angle2++)  // spins the second pair of motors 180 degrees
  {                                  
    servo2.write(angle2);        
    delay(2);                   
  }
for(angle1 = 90; angle1 > 0; angle1--) // spins the first pair of motors back 90 degrees
  {
    servo1.write(angle1);
    delay(5);
  }
for(angle2 = 180; angle2 > 0; angle2--)  // spins the second pair of motors 180 degrees
  {                                  
    servo2.write(angle2);        
    delay(2);                   
  }
 }
 else{ // if the distance from the proximity sensor is greater than 10 cm, initiate the function
  myDisplay.init(); // resets the LCD screen
  servo1.write(45); // resets the angle of the first pair of motors
  servo2.write(0); // resets the angle of the second pair of motors
 }
if (distance > 10 || distance <= 0){
Serial.println("The distance is more than 10"); // prints information to the serial monitor
}
else {
Serial.print(distance); // prints distance on the serial monitor
Serial.println(" cm");
}
delay(2);
}

Code Description:

This code was written in the C++ language.

The beginning of the code is what includes all of the libraries for the sensor, the motors, and the LCD display, and it also defines most of the variables that the code will need, initializes the LCD display.

The void loop() is the main function of the code that controls all of the systems and circuitry that we set up on Step 3. First we set up the ultrasonic proximity sensor. In order to do so, we must first set up the measurements and trig pin. We set the trig pin to 10 microseconds, and convert the information that the echo pin receives into centimeters. By converting it into centimeters we can use the data in real-world measurements. After the ultrasonic sensor has been set up with its proper units, we can use an if statement for when the proximity sensor measures any object that is within 10 centimeters.The if statement states that when an object is less than 10 centimeters from the sensor, the sensor will tell the arduino to print "Go Bulls!" onto the LCD display. After the LCD display, the code uses a for loop in order to make the motors move. First, the 'servo1' object is written to 90 degrees, which turn the Group 1 motors 90 degrees. This gives the flags the waving movement. Next, the 'servo2' object is written to 180 degrees. This gives the flag the rotational movement that turns them around. Following the rotation, the 'servo1' object is rewritten to go in the opposite direction. The 'servo2' object is rewritten as well, rotating the flags back in their original rotational, then the loop starts again. This loop gives the flags their waving and turning movements by using a duel-motor system. After the for loop, an else statement is written for when the distance between any object and the proximity sensor is greater or equal to 10 centimeters. This statement refreshes the LCD display to no longer have "Go Bulls!" written on it, and it also resets the motors back to their starting positions.

Step 5: Functions of the Device

Before we begin the process of putting together the flag waver, I am going to give a description of all of the parts and how they interact with each other. The 3D printed box is was houses the majority of the circuitry and hardware such as the HC-SR04 sensor, the Arduino Uno, and the 16x2 LCD display. There are empty spaces in the walls of the box that each serve different purposes, the rectangle on the left is where the sensor goes. The rectangle on the right is where the LCD is displayed. On the left side of the box, there is a small square hole that allows for a method of passage to the arduino with a cable from outside the box. Inside the box, there 4 small rectangular extrusions. These allow for the servo floor to rest above all of the components beneath it. The servo floor has four holes which allow the wires of the servos to pass through to reach the top of the servo floor. On the servo floor, there are two extruded holders to house the Group 1 servos. The 3D printed motor holders are what house the Group 2 servos. Once the motors holders containing the Group 2 motors are directly attached to the Group 1 motors, it will create a dual-motor system. The purpose of this system is to allow for the two planes of movement that are to be done to the flag: waving the flags, and rotating them. ow this is accomplished is by the Group 1 motors rotating the Group 2 motors, and then the Group 2 motors rotate the flags afterwards. All of these components can be seen in the sections following this description.

Step 6: Constructing the Device

Now that the circuitry is wired, the 3D parts are printed, and the code is written, all that's left is to assemble all of the hardware together! First, you will need to secure the breadboard,the LCD display, and the arduino in the proper sections of the bottom of the box as shown in the picture above. To do this, you can use glue on the bottoms of the arduino and breadboard, and tape to secure the LCD display to the wall of the box.

Step 7: Servos

Thread the servo wires through the holes of the servo floor and place the Group 1 servos onto the holders that are 3D printed onto the servo floor as shown in the image above. These can be fastened down in however way you would like.

Step 8: Motor Holders

Now that our servos have been threaded through the servo floor, we can now attach the flags to the servos. Super glue works well to keep the servo adapters that are attached to the bottom of flag attached to the servo itself to prevent the flag from falling off. Next, take the remaining two double-sided servo adapters and super glue them to the motor holders as shown in the image above. There are outlines on each holder to indicate where to glue the adapters. Once the glue has dried, place each servo from Group 2 in to each motor holder as shown in the picture above. Next, attach each motor holder to a motor from Group 1 as shown in the image above. You can either screw it in or use super glue, both methods work. Now the servos and the flags are finished! you can now put the servo floor inside the box, but make sure that the wire to plug in the arduino to a power source is fed through one of the side notches of the servo floor as shown above.

Step 9: Flag Waver Lid

All that's left is to finish the lid. Take four of the 1" felt pads and place them about 1 centimeter from each corner in such a way that when the lid is put on the box, they fit snugly against the walls. This is to prevent the lid from sliding while the flags are in motion. Once the felt pads are secured, place the lid over the box, passing the flags through each slit. Plug in your portable charger to your arduino, place it in the box on the servo floor, close the lid, and you are done! Test out the flag waver by place your hand within 10 centimeters from sensor. If they are not working or are working incorrectly, check the code and the wiring to make sure that they match the diagrams. Decorate the box and have fun with it!

Be the First to Share

    Recommendations

    • Magnets Challenge

      Magnets Challenge
    • Raspberry Pi Contest 2020

      Raspberry Pi Contest 2020
    • Wearables Contest

      Wearables Contest

    Discussions