Skip to content

10. Output Devices

Group Assignment:

  • Measure the power consumption of an output device

Individual Assignment:

  • Add an output device to a microcontroller board you’ve designed and program it to do something

Creating my new board

At the beginning of this week, I decided to choose a servo as the output device I would program. This was mostly due to the fact that I will use servos/motors in the next week, machine week, and because I will likely also use a servo or motor in my final project (to rotate my lazy susan). There was one issue which I encountered, however, which was the fact that my current board which I made during electronics design week only has one conn header with 1 power, ground, and UDPI respectively. Because of this, I had to make a new version of my board that includes two 1x3 conn headers. the process of doing this was very simple, as all I did was add a single 1x3 conn header to my original design. The following picture shows my new KiCAD design in the schemati editor.

In the PCB editor, I placed the new conn header at the bottom of my board, very close to the ATtiny chip. This was to make it easier to create traces.

I then went to the milling machine to mill out my new board. I went through the same workflow as when I used the milling machine in previous weeks, and I made sure to double check that I made the trace clearance 1.5 mm (so as to not repeat my past mistakes, cough cough). After milling out the board, it looked fine, and so I took about 20-30 minutes to solder on all of the components. This is what the board looked like after having everything soldered onto it.

After finishing soldering this board, I had to take a break from this week’s assignment to finish my assignment for CNC week (this took the rest of the day). Because of this, I only got to begin programming the day after.

Programming the Servo

After coming back to this week’s assignment, the first thing I did was make sure that my board actually worked and didn’t have any connection errors. To do this, I simpoly connected my board to my computer to see if the indicator LED would light up. Luckily, it did!

Then, I opened Arduino IDE and took the same steps as I did during electronics design week to setup the board, port, and programmer settings correctly. Then, I did some basic Google searches on how to program servos to rotate. I ended up also asking ChatGPT how to write basic servo rotation code (180 degrees in both directions indefinitely) which I based my final code on. My final code is shown below.

#include <Servo.h>

Servo myServo;  // Create a servo object

void setup() {
  myServo.attach(2);  // Attach the servo to pin 2
}

void loop() {
  // Rotate the servo 180 degrees clockwise (to the right)
  for (int angle = 0; angle <= 180; angle++) {
    myServo.write(angle);  // Set the servo angle
    delay(15);  // Delay for smooth movement
  }
  delay(1000);  // Wait for 1 second

  // Rotate the servo 180 degrees counterclockwise (to the left)
  for (int angle = 180; angle >= 0; angle--) {
    myServo.write(angle);  // Set the servo angle
    delay(15);  // Delay for smooth movement
  }
  delay(1000);  // Wait for 1 second
}

I proceeded to upload this code and it worked well! The video below shows my code working with a small fan attached to the servo.

Group Assignment

This week’s group assignment required us to measure the power consumption of an output device. The output device my partner Angelina Yang and I chose was a servo. In order to test its power consumption, we used a multimeter to find both the voltage and current running through the board it was connected to and then used the formula Power = Voltage x Current (where power is measured in watts). Our group’s findings can be found on our website, linked here.

Reflection and Files

Overall, this week wasn’t too difficult for me. This was mostly because the output device I chose, the servo, was on the simpler side when it came to programming. I did feel a bit regretful at the beginning because I only put one 1x3 conn header on my original board, but making an updated board wasn’t too difficult in the end. This week, I mostly expanded on my skills from previous weeks like electronics design and also learned more about how to program servos. My files for this week can be found here.


Last update: March 31, 2024