Servo Controlled Crane
Made by Adwoa Asare
Made by Adwoa Asare
Origami crane that moves its wings via a servo.
Created: November 20th, 2024
Originally my goal was to make a crane that would flap for different weather updates, but the HttpClient library for Particle was giving me too many issues so I scaled down the scope to just be an origami crane that would flap using a function that could be called using the console or by pushing a button.
I was inspired by this project called Automation Origami on Instructables (Automaton Origami : 8 Steps (with Pictures) - Instructables ). I switched up the functionality a bit, made everything out of recycled materials, and added internet connectivity.
I can't fold origami no matter how hard I try, so I used a crane someone had given me as a gift. I cut out a cardboard to use as a base and use sewing pins to make holes to tie the string. I used tied the end of the strings not attached to the wings to the attachment at the end of the servo.
I used a Particle Photon 2 microcontroller to control the servo, as well as a button in pull up configuration.
// Include Particle Device OS APIs
#include "Particle.h"
//by Adwoa Asare
//Started: 14 November 2024
//Last update: 14 November 2024
// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);
// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
SerialLogHandler logHandler(LOG_LEVEL_INFO);
#define SERVO_PIN A2
#define BUTTON_PIN D3
Servo swan;
int servoPos = 0;
int buttonState;
bool flying = FALSE;
int speed = 5;
bool opening = TRUE;
// setup() runs once, when the device is first turned on
void setup() {
//PARTICLE FUNCTIONS
Particle.function("fly",swan_flight);
Particle.function("land",swan_stop);
Particle.function("control",servo_control);
//INITALIZE PINS/MODES
swan.attach(SERVO_PIN);
pinMode( BUTTON_PIN , INPUT_PULLUP);
}
// loop() runs over and over again, as quickly as it can execute.
void loop() {
buttonState = digitalRead( BUTTON_PIN );
if (buttonState == LOW){
swan_flight("NORM");
}
swan.write(servoPos);
delay(20);
}
//function to make the wings move until limit reached and then reverse
int swan_flight(String command){
flying = TRUE;
if( command == "SLOW")
speed =2;
else if ( command == "NORM")
speed = 5;
else if ( command == "FAST")
speed = 10;
//movement
if (servoPos < 180 && opening)
servoPos += speed;
else if (servoPos >0 && !opening)
servoPos -= speed;
if (servoPos >= 180)
opening = FALSE;
else if (servoPos <= 0)
opening = TRUE;
swan.write(servoPos);
return 1;
}
int swan_stop(String command){
swan.write(0);
flying = FALSE;
return 1;
}
//function to control servo
int servo_control(String command)
{
// Convert
int newPos = command.toInt();
// Make sure it is in the right range
// And set the position
servoPos = constrain( newPos, 0 , 180);
// Set the servo
swan.write( servoPos );
// done
return 1;
}
Click to Expand
I leaned how the servo could be used in a more artistic way than what I usually use them for. I think in the future I would try my original project idea with the weather updates, but instead of trying to read the data directly into the Particle 2 I would make a separate program. The separate program would run on my PC and parse the relevant data from online periodically and then call the function from the particle console with the appropriate commands periodically.
Origami crane that moves its wings via a servo.