Cable-Driven Arduino Spacecraft Motion Simulator _ Science Project

Terrific Physics
37 followers
Apr 10, 2026
This is a cable-driven spacecraft motion simulator.
A model spacecraft is suspended in the middle of this PVC pipe frame by three cables. Each cable
is tied to the spacecraft and runs through a hook attached to the frame, then to a winch mechanism
made from a continuous rotation servo motor. Each motor is controlled by two buttons connected to
an Arduino that wind and unwind the cable. By coordinating the motions of the cables,
I can move the model spacecraft around in three-dimensional space and simulate things
like docking or landing maneuvers. We have a separate video that shows you how to build this
frame and control the spacecraft manually by pulling on the strings, so if you haven't already,
you can check that out first to build the frame. In this video, we're going to focus on the
connections to the Arduino and using the buttons to control the servo motors. First, let's take a
look at the physical connection to the servos before we switch over to the computer to look
at the circuit diagram and code. It's important to note that these are continuous rotation servos
which can go through complete 360-degree revolutions, unlike positional servos which
can only rotate through a range of 180 degrees. I have the servo attached to the PVC frame with hot
glue and the string wrapped around a spool that I made from a wooden dowel and a small piece of
cardboard to prevent the string from sliding off the end of the dowel. The dowel is hot glued to
the servo horn. These servos have a small calibration screw on the bottom that adjusts
their neutral position, so you will need to adjust this screw to avoid drift when you are not sending
the servo a command to move from the Arduino. You can see that I have this servo adjusted to
hold still right now, but if I turn that screw just a tiny bit, it will start drifting in one
direction, and if I turn it the other way, it will start rotating in the other direction. So again,
for each of your servos, you are going to need to adjust that screw independently to make sure
the servo holds still. On the breadboard here, I have six buttons, two for each servo, one to make
the servo spin in one direction to wind the cable, and the other to make it spin in the other
direction to unwind the cable. Switching over to the computer, we are going to be looking at this
in software called Tinkercad Circuits, which is a free online circuit and Arduino simulator.
You can find a tutorial about Tinkercad Circuits in our YouTube tutorial playlist linked in the
description of this video, along with individual tutorials about parts like buttons and continuous
rotation servo motors, and the difference between continuous rotation motors and positional servo
motors. So in this video, we are going to put all of these things together for this more advanced
project, but if you are new to Arduino and need to learn how to use the individual parts, we highly
recommend walking through the earlier tutorials in that playlist before you tackle this project.
Each of these six buttons is placed straddling the middle gap of the breadboard. We talk about
how the buttons are wired more in the individual button tutorial video, and each button then gets
two connections. One side is connected to the breadboard's ground bus, and the other side is
connected to one of the Arduino's input pins. We are using pins 2 through 7 for the buttons.
Each of these servos has three connections. The brown wire is ground, which goes to the
breadboard's ground bus. The red wire is power, which goes to 5 volts, and the orange wire is
signal, which goes to one of the Arduino pins. We are using pins 8 through 10 for the servos.
Note that this is just one of several color conventions for servo motors. You might also
buy motors with red, black, and white wires, so you will need to look up which one is power,
which one is ground, and which one is signal for your servo. Now let's look at the code. You can
download this code or access this Tinkercad model from the link in the video description.
First, we are going to include the servo library, which will allow us to control the servos.
I then defined three constant variables for the servo pins. Make sure these variables match the
pins you have your servos wired to. Again, I am using pins 8, 9, and 10, but you could choose
different pins as long as you then change the corresponding variables in the code. I also have
six variables defined for my six buttons. Again, I'm using pins 2 through 7. Make sure they match
the pins that you have your buttons wired to, but you can change them if you want. Next, I declare
variables for the state of each button and added a comment saying what I want each button to do. So,
for example, button 1 is going to make servo 1 go forward, button 2 is going to make servo 1 go
backward, and so on. These variables are not constants because they can change, so I have just
defined them with int, not const int. Next up, I define variables for my motor speeds, and this is
usually what students find the most confusing when it comes to using continuous rotation motors. The
Arduino servo library is really designed to control positional servo motors and send them an
angle between 180 degrees. You can still use this library to control a continuous rotation servo
motor, but you are controlling the speed, not the angle, and the speed will be zero or the motor will
be stopped when you send it a signal of 90. So, sending it zero does not mean that the speed is
zero and you will stop it. That actually means it will be full speed in one direction. It will be
full speed in the other direction when you send it 180, and it will be stopped when you send it a
90, assuming you have that calibration screw set so it's not drifting and it does actually stop at
90. So, again, remember that you are not sending it a command to control the angle. You are controlling
the speed, and it will be stopped at 90. The farther away from 90 you are, the faster the
motor will spin. So, in our example code, we have the motor set to full speed in both directions
with 180 and zero. If you find that your cables are moving too fast and the motors are spinning
too quickly when you hold the buttons down, you can change these numbers and make them closer to
90 to slow down your motors. So, for example, if I want to slow this motor down, I could change this
to 170 instead of 180, and I could change this to 10 instead of zero, and that's going to slow down
my motor. To use the servo library, I then need to create three servo objects. You can name them
whatever you want, but I call them Servo1, Servo2, and Servo3. In my setup function, I then use the
servo library to tell it which pin is attached to which servo. So, Servo1, I'm using Servo1 pin,
which I defined way up here, and so on, and then I am also setting all six of my button pins
as inputs with the internal pull-up resistor enabled. So, that is why you may have noticed
I do not have external pull-up or pull-down resistors connected to my buttons, and we talk
about this more earlier in our tutorial series, but that just saves you some clutter on the breadboard
with not needing the external resistors. I then initialize serial communication, which is always
useful for debugging and printing out values when you're trying to figure out what your program is
doing. We then use the digital read command to read the state of all six of our buttons, and I'm
using the not operator here to make things a little more intuitive. So, these values will be low when
the button is not pushed and high when the button is pushed. You don't have to do that, but I find
that more intuitive than having the button value be high by default when it's not pushed, which is
what you get when you are using the internal pull-up resistor, and then the button value would go low
when you push the button, but if you use the not operator here, it inverts that. So, this variable
will again be low when the button is not pushed and high when the button is pushed. Next, we have
the logic in our program that is going to tell the motors what to do depending on which buttons are
pushed. So, for each pair of buttons, we really have four possibilities. You can have neither of the buttons
pushed, you can have one button pushed but the other button is not pushed, or you can flip that,
you can push the second button and not push the first button, or you can push both buttons. And
in our case, we really only want to have three actions. We want the motor to either stop,
spin one way, or spin the other way. So, I wrote code. I have a series of nested if-else statements
here that will do three things. If only the forward button is pushed, so if one button is
pushed and the other button, the backward button, is not pushed, then I'm going to send my forward
speed value to the motor to make it spin forward. I'm also going to print that out to the serial
monitor so I know that motor one should be spinning forward. Else if, if the forward button is not
pushed and the backward button is pushed, then I am going to spin my motor backward by sending the
backward speed variable to the motor using the servo write command and print out that motor one
is spinning backward. Finally, I just have an else to catch all of the other possible conditions. So,
if neither button is pushed or if both buttons are pushed, I don't really care which, there is no
special action for pushing both buttons. I'm just going to stop the motor by writing the stop speed
variable to it, which again is 90, which should stop it, but you may need to adjust the calibration
screw to make sure the motor actually stops, and I'm going to print out motor one stopped. So, that
is the structure to control a single motor with two buttons. I then just repeat that for motors
two and three, so the code here is the same. I just have all the numbers change, so this is servo two
forward and servo two backward for the button values, servo two right, and so on. Same thing
for motor three. I have servo three forward and servo three backward and servo three right. So, if
I run this simulation, we will see the motors all spinning slightly. Tinkercad does not actually have
a little calibration screw to adjust on the motors, but if I open the serial monitor, we will see that
as far as my code is concerned, all three motors should be stopped right now, and I am sending that
stop speed variable to the motors. If I hold down one of the buttons, for example, hold this one down
for motor one, we'll see that it spins much faster, and my serial monitor is now printing
out that motor one spins backward, or if I switch and click the other button, it's going to say motor
one is spinning forward. So, you can adjust this in Tinkercad. Since there's no calibration screw,
you can try changing the stop speed variable slightly. So, for example, if I change that
to 92 and start the simulation again, now the motors are spinning a little more slowly or
closer to stopped. So, don't worry about that not being perfect in Tinkercad. Again, with your
physical servos in the real world, you're going to have that little adjustment or calibration screw
you can use to stop the servos, and you shouldn't need to change this value. So, that is an overview
of how you can set this up with three motors to control each motor with two buttons to wind and
unwind the cables. However, if you want to do this for a science project, you can think about how you
could really add more to the project to make this more challenging or unique. For example, you may
have noticed that with three motors, I can control the satellite's position in this three-dimensional
volume, but I cannot independently control its rotation. I cannot keep it in place and just
rotate it. To do that, I need more cables, but if I add more cables, then I could potentially have
two cables pulling against each other at the same time. So, I need to automatically unwind or loosen
one cable when I am winding or tightening another one, and setting that up becomes much more
complicated. You don't really have to worry about that with just three cables. I also don't have to
worry about cable collisions with just three cables. You can imagine as I have more and more cables in
here, as the satellite is moving around, there's a chance that the cables might collide either with
each other or with the satellite. Instead of programming the motors for manual control with
buttons, you could also try to automatically program certain maneuvers, again like landing
or docking. So, you can imagine trying to land vertically on the surface, or maybe move horizontally
to dock with a space station, and you could try to figure out how using the motors moves the satellite
around, how it responds to each of the three cables being tightened or loosened, and then how you can
combine or synchronize them, again to have vertical or horizontal motions to practice a
certain maneuver. So, we are not going to give you instructions to do all of that. Those are just some
additional ideas or challenges that you can try yourself to make this project more unique, but
again remember that you can find all the instructions to get started linked in the description
of this video, and you can find instructions for over a thousand other projects in all areas of
science and engineering on our website www.sciencebuddies.org
