Skip to content

9. Output Devices

This week, I wanted to use the servo motor as it is a crucial element in my final project. The idea is simple. The servo motor will be used to open and close mini doors on my board game map.

Group work

Check the Power consumption of an output device.

We did this using a multimeter by measuring the potential difference (V) and the flow of current (I) when conencted to an output device. since P=VI, we can get the power consumption of the connected device.

For this, I took my development board milled in W8 and connected it to a servo. Next, I ran the Servo sweep code from the Examples.

Make sure to connect the red probe to the plug marked V on the multimeter and the black one to COM common ground. The dial of the multimeter should be set to the one marked V and use the function button to set it to DC as we are measuring DC voltage (it will show a small DC ion the screen).

For reading the voltage of the servo, I brought the positive (red) probe of the multimeter in contact with the 5V pin of the Xiao RP2040 where the servo was also connected, and the negative (black) probe with the GND pin.

For the current measurements, connect the red probe to the plug marked mA as we are measuring in milliAmperes.The black one remains on the COM common ground. The dial of the multimeter should be set to the one marked mA and using the function button, set it to DC as we are measuring DC voltage (it will show a small DC ion the screen).

For reading the current of the servo, I brought the positive (red) probe of the multimeter in contact with the 5V pin of the Xiao RP2040 where the servo was also connected, and the negative (black) probe with 5V pin of the servo. This means that you connecting the multimeter between the Xiao 5V pin and the servo 5V pin (The multimeter is connected in series). The multimeter will conduct the electricity and read the current at the same time.

From here we got the V and I values:

V = 5 V
I = 50 mA = 0.05 A

P = VI
P = 5 V x 0.05 = 0.25 watts

According the details of the SG90 servo: LINK

Process

I started out by refering to this youtube Here and understood how a rack and pinion can help convert the rotational motion of the servo into linear motion.

Next up, I downloaded the Mini Versions of the Rack and pinion, and the servo holder STL files from the Thingiverse link on the above mentioned youtube video. Here is a link to that:
https://www.thingiverse.com/thing:3170748/files

Next, since I wanted to use a door at the end of the rack, I popped open a bottle of Fusion 360 and began making my door. I started with a very basic door design- the kind you would see in typical cartoons or TV shows.

Next, I thought about making a more “flavored” door, meaning that it would have more character.

I took the reference of Medieval castle doors which are usually made of metal, such as this:

Along with the doors in the Fire Nation empire in one of my favorite shows- Avatar the Last Airbender.

I went on to make this door on fusion based on these two references:

I then combined my door to the end of the Rack model I had taken.

Quick tip here: STL files are Mesh files. It gets a bit tricky to use mesh files on fusion has most of your other models would probably be Solid bodies. So what I usually do is convert the Mesh body into a Solid body before doing any operations on it. To do this, go to the Mesh tab of Fusion from the Nav bar above and click on “Convert Mesh” tool under the Modify option.

I also ended up modifying the Servo holder a bit as I decided that there was an extra few mm in the thickness which I didn’t need.

This I took to the 3D printer along with the Servo holder and Pinion STL.

Once the prints came, I attached the pinion to the servo motor and assembled the rest as well.

Servo Attachments

The servo I was using is the SG90 micro servo. It is a 180 degree servo.

Working of the servo:

A servo moves to specific angles based on the duration of the PWM signal it receives. The Servo library in Arduino IDE simplifies controlling the servo by handling the PWM signals for you. You just need to create a servo object, attach it to a pin, and use the write() method to set the desired angle.

A servo typically has three main parts: a motor, a control circuit, and a set of gears.

There are usually has three wires coming out of it:
1. Power (Red): Supplies the necessary power (usually 5V).
2. Ground (Brown): Completes the circuit.
3. Control (Yellow): Receives the control signals.

Connect the RED wire of the servo to the 5V pin on the Xiao. Here, I use my Xiao RP2040 PCB made in Week 8

Next, connect the YELLOW wire to the Signal pin A0 on the Xiao and finally the BROWN wire to the GND.

Once, you upload the example Sweep code provided below, you can have your servo to move!

Code breakdown

First, you include the Servo library in your code by using #include <Servo.h>.

Then, you create a servo object that will represent the servo in your code: Servo myServo;

You attach the servo object to the pin that the control wire of the servo is connected to using myServo.attach(A0); given that we are connecting the control YELLOW wire to A0.

Finally, you can then use simple commands to move the servo with myServo.write(90); which moves the servo to 90 degrees. You can change this number to move the servo to a specific value, or run it within a loop where the value increases/decreased between 0 and 180 to have a smooth motion.

Hero shots

As you see here, the PCB that is connected to the servo is my Dev board which I had designed in week 8. Here is the link to that page to check out the design and production process of the Dev board: Sid’s Electronic Design

Working

As mentioned, for the code, I installed the <Servo.h> library. And under examples, I used the Sweep code example.

Changing speeds of the Servo:

First Method: Decrease the Delay
Reduce the delay value in the code to make the servo move faster between steps. For example, changing delay(15); to delay(5); will make the servo move faster as the time between each step reduces.

Second Method: Increase the Step Size
Increasing the step size so the servo moves a greater distance each time will result in a speed increase. For example, changing pos += 1 to pos += 20 in the for loop will make the servo move 20 times faster.

Lastly, you can use a combination of both methods to get the desired outcome.

Moreover, depending on which for loop you choose to alter, you can have the servo move faster in one direction and slower in the other.

Project Files

Fusion Files
Basic door STL
Fire Castle door STL
Door + Rack STL
Modified Servo holder STL
Link to Original Thingiverse STLs
Servo Sweep Example code