Skip to content

Week 12. Output Devices

This week we learnt about output devices. The content is equivalent to those of last week.

Individual Assignment: add an output device to a microcontroller board you’ve designed, and program it to do something
Group Assignment: measure the power consumption of an output device

Knowledge learnt this week

Electrical Safety

  1. A useful link about electrical safety:

  2. Current:
    (1) 1mA => doesn’t hurt anything
    (2) 10mA => shock, muscle contraction
    (3) 100mA => heart attack
    body: 1mohm outside, 1k ohm inside the body
    20V outside the body is harmless, but 20V inside the body is seriously harmful.

    (4) large capacitors can store a lot of charge.
    (5) breakdown voltage: kv/mm, the voltage you punch through materials.
    (6) magnetic field can generate very high voltage.
    Safety first!!! Do not work alone. Make sure everything is safe before turn on the power.
    (7) Pay attention to polarization. Connect power backward is dangerous.

  3. Power Supply:
    Do not consume batteries until your projects really need to be battery-powered.
    recommend book about electronics: The Art of Electronics by Horowitz Hill.
    Tips about measuring currents:

  4. Use power supply, set the voltage and it will show currents.
  5. add a 1Ω resistor at the circuit that is connected to the ground, measure the voltage on both side of the resistor.
  6. If there is a current going to the ground, there is a magnetic field around it, use a Hall sensor to sense the field.
  7. If it’s AC current going to the ground, can measure it inductively with a coil.

  8. Output devices: (1) RGB LED.
    3 LEDs in one package. Check datasheet to check which pin goes to which LED.—

  9. Red, Green LED: 1k resistor; Blue LED: 499 resistor
  10. PWM: pulse width modulation.

Making skills learnt this week

Output: LED trigged by a sensor

For the individual assignment, I am thinking about combining a buzzer with a light sensor. When the light sensor detect light, the buzzer will buzz. First I identify the components I’ll use in making this project. I couldn’t find any buzzer at SZOIL, so I decided to change the buzzer to an LED.

Item Component Name Quantity
1 10k resistor 2
2 20 MHz resonator 1
3 1uF capacitor 1
4 ATtiny 45 IC 1
5 2x03pin header (AVRISP) 1
6 Light Sensor (input) 1
7 LED (output) 1

Output: RGB LED

I also want to try other output devices. So I follow Neil’s example and make a RGB LED device.

Here is the list of components needed:

Item Component Name Quantity
1 10k resistor 1
2 1k resistor 2
3 499 resistor 1
4 1uF capacitor 1
5 2x03pin header (AVRISP) 1
6 ATtiny 45 IC 1
7 RGB LED (output) 1

And then I begin designing the board on Eagle. First, I add all the components.

(Components are added)

Now I begin to use Net + Name to connect the components with each other.

And then I create the board at Eagle, change the design rules, move the components, and then use “Autorouter” to route up the parts. When finish routing, I add my name onto the board.

And then I move the whole part to the lower left corner, change the outline dimension to make it fit for milling. I set the width of the outline as 16mil the same as the design rules I make for the routes.

Next, I export the traces and the outline respectively.

(PCB traces - Output RGB LED)

(PCB outline - Output RGB LED)

I used Fab Modules to create rml. files for milling on the Roland SRM-20.

For making traces, I follow these steps:
input format => image (.png) => select the traces file => output format => Roland mill (.rml) => process => PCB traces (1/64) => invert image => and then change the following setting => calculate => save.

Setting values for traces - Speed(mm/s): 4
x0(mm): 0
- y0(mm): 0
- z0(mm): 0
- zjog(mm): 2
- Cut depth(mm): 0.13
- Tool diameter(mm); 0.4
- Number of offsets: 2
- Offset overlap(%): 50

For making outline, I follow these steps:
input format => image (.png) => select the outline file => output format => Roland mill (.rml) => process => PCB outline (1/32) => invert image => and then change the following setting => calculate => save.

Setting values for outline - Speed(mm/s): 4
x0(mm): 0
- y0(mm): 0
- z0(mm): 0
- zjog(mm): 2
- Cut depth(mm) 0.6
- Stock thickness(mm) 1.7
- Tool diameter(mm);0.79
- Number of offsets: 1
- Offset overlap(%): 50

And then I have two .rml files for milling traces and the frame/outline respectively.

I used the Roland-SRM20 to mill the PCB. I milled 2 pieces in case I need an extra one. Since I set the Z axis lower when milling the 2nd PCB, the traces are more obviously. After sandering the board, there are some scratches on the board and I am worried it the copper layer might got grind off the surface. So I used a multimeter to check the traces. Happy to see the board is good! (PCB board - Output RGB LED)

And then I begin soldering the components onto the board. I checked the components boxes at SZOIL, and finally got some reels of LEDs. I did not know how to identify the polarization of the RGB LEDs, so I searched for answers on the internet. And I found this article on CSDN, which is very helpful. Thank you the powerful internet and the sharing from AnthonyYMH at CSDN.

(SMD RGB LED polarization Picture credit: DocIn & CSDN)

After soldering all the components onto the board, here comes the programming. Since I have been behind the schedule since the week of Embedded Programming, I haven’t managed to use Arduino with ATtiny yet. When I open Arduino IDE, but couldn’t find ATtiny on the list of existing boards. So I searched for solutions as to how to set it up. Thanks to this lovely tutorial on Instructables, I managed to add ATtiny. And here are some a simplified steps:

In Arduino IDE:
(1) Arduino => Preference => Additional Boards Manager URLs, add this URL “” => OK => restart Arduino IDE.

(Arduino IDE interface)

(after putting in the url, I am able to install attiny)

And then according to my own IC etc., I make the following settings:
(2) Tools => Board => Select “ATtiny25/45/85” => Processor => Select “ATtiny 45” => Clock => Select “internal 8MHz” => Progammer => Select “USBtinyISP” => Burn Bootloader

(Now I can choose ATtiny45)

Here an error popped up.

It showed the following error messages:

Arduino: 1.8.8 (Mac OS X), Board: "ATtiny25/45/85, ATtiny45, Internal 8 MHz"

avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

Error while burning bootloader.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Since when I was soldering, I noticed the LED lit up a bit, I do not think there is any problem with the board. So I tried to unplug the cap on the AVRISP and plug it in again in a different direction. And then click “Burn Bootloader” again. Now it worked. Debugging succeed!

(3) And then I copied Neil’s C language codes into the Arduino IDE, and then clicked Upload button. The LED blinks. However, it doesn’t show red, green and blue, it only blinks red. When reflecting the process of soldering when the hot solder dip touched the LED, it only blinked red. I guess the LED I found is just a normal red LED, not RGB LED. But I am so happy that it worked. Especially when I have been behind in my assignments for so many weeks. This is an encouraging triumph.
(happy blinking red LED :D )

I will try & find RGB LED to reply the current one tomorrow. And will try designing other output devices as well. :)

And then my local instructor Felix ordered RGB LEDs. When they arrived, I replaced the red LED with a RGB LED. And here is the updated board with the RGB LED in the red circle.

(replaced RGB LED)

And then I began connecting it to my laptop and upload codes.

int red = 1;
int blue = 2;
int greenn = 0;

void setup() {
  pinMode(red, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(greenn, OUTPUT);

void loop() {

  digitalWrite(red, HIGH);
  digitalWrite(blue, LOW);
  digitalWrite(greenn, LOW);


  digitalWrite(red, LOW);
  digitalWrite(blue, HIGH);
  digitalWrite(greenn, LOW);


    digitalWrite(red, LOW);
    digitalWrite(blue, LOW);
    digitalWrite(greenn, HIGH);


However, the LED still only blinks red and I do not know what is the problem. And then my colleague Nicho had a look at it and he mentioned I did not solder it well. Two of the pins (must be the Green and Blue pins were not soldered well.) And when I fixed the soldering, it worked!

Thanks to my friend and instructor from Lab Lab Kochi - Salman, I now know the term of the above problem is called “cold solder joints” in English.

And with the following code, the RGB LED blinks! Yayyyy! (Happy Face. gif)

Files for downloading