Creating a DIY Light Control System Using the ATtiny85 Microcontroller and a 3-Channel Relay Module

Creating a DIY Light Control System Using the ATtiny85 Microcontroller and a 3-Channel Relay Module

Hello and welcome back. In this project, we will learn how to make a DIY light design system using an Attiny85 Microcontroller. This compact microcontroller is perfect for small projects. For that, I used a customized three-channel relay module, allowing us to easily control multiple light sources. You can easily have this PCB printed at JLCPCB using free coupons, making the process cost-effective and accessible for everyone. Also, I used three 12V LED strips for this project, but you can use any other light sources that match the relay module’s ampere rating. That is you can use AC or DC light bulbs for that project. For the lighting effects, I used two simple light patterns, but feel free to modify them as you like. That is you can change speed, lighting sequences, and different types of patterns. You can easily program the ATtiny microcontroller using either an Arduino UNO board or an ATtiny programmer. Also, the Arduino IDE is compatible with the ATtiny85, so you can write, compile, and upload your code easily.

  • What is the ATtiny85, and How to Use It Step by Step – Click Here

OK let’s do this project step by step. The required components are listed below.

  • ATtiny85 Microcontroller x 1 — Our store / Amazon
  • 8 Pin IC socket x 1 — Our store / Amazon
  • 5v Relay x 3 — Our store / Amazon
  • PC817 Optocoupler IC x 3 — Our store / Amazon
  • 1AM SMD Transistor x 3 — Our store / Amazon
  • Three-pin terminal x 3 — Our store / Amazon
  • Two Pin terminal x 1 — Our store / Amazon
  • 1N4148 Diode x 3 — Our store / Amazon
  • 102 Resistor x 3 — Our store / Amazon
  • Red LED x 1 — Our store / Amazon
  • Green LED x 3 — Our store / Amazon

For programming the Attiny85 Microcontroller

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, let’s order the PCBs for this project. Follow the instructions below.

  • First, go to the JLCPCB official website and log in to your account.
  • If you’re a new member of JLCPCB, please sign up using this link to receive an $80 new user coupon.
  • Black Friday exclusive deals and a chance to win amazing prizes! — Click on me
  • Now, click on the “Instant Quote” button and upload the Gerber file. You can download the file using the link provided below.
  • Gerber file — Download
  • I ordered five blue PCBs. Next, select the build time and shipping options, and then click the “Save to Cart” button.

Step 3

Thirdly, unbox your PCB package and inspect the quality of the PCBs.

Step 4

Now, solder the SMD components onto the PCB. You can use a hot air gun or a heat plate for this process. Afterward, clean the PCB with a suitable cleaner to ensure a polished and professional finish.

Step 5

Next, solder the relays and pin terminals onto the PCB one by one.

Step 6

Now, let’s upload the program to the ATtiny85 microcontroller. Follow the instructions below.

  • First, place the ATtiny85 microcontroller on the breadboard and connect it to the Arduino UNO board using the circuit diagram provided below. Then connect the Arduino UNO board to the computer.
Creating a DIY Light Control System Using the ATtiny85 Microcontroller and a 3-Channel Relay Module
  • Next, open the Arduino IDE and upload the “Arduino ISP” program to the Arduino UNO board. You can find it under File > Examples > ArduinoISP.
  • Now, copy and paste the ATtiny board URL into the Additional Boards Manager URLs field. Then, go to Tools > Board > Boards Manager, search for the ATtiny board package, and install it.
  • ATtiny board URL — https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
  • Next, select the ATtiny85 microcontroller in the Tools menu and set the programmer to Arduino as ISP. Then, click on Burn Bootloader. After this, you can program the ATtiny85 using the Arduino UNO board.
  • Finally, copy and paste the following program into the Arduino IDE. Select the ATtiny board and the correct port. Then, click the Upload button to upload the program to the ATtiny85 microcontroller.
  • Code and Circuit diagram — Download

#define t 400
void setup() {
  for (byte a = 0; a <= 2; a++) {
    pinMode(a, OUTPUT);
  }
}

void loop() {
  Pattern1(3);
  Pattern2(3);
}
void Pattern1(byte a) {
  for (byte j = 0; j <= a; j++) {
    for (byte i = 0; i <= 2; i++) {
      digitalWrite(i, HIGH);
      delay(t);
      digitalWrite(i, LOW);
    }

    for (byte z = 1; z > 0; z--) {
      digitalWrite(z, HIGH);
      delay(t);
      digitalWrite(z, LOW);
    }
  }

}


void Pattern2(byte a) {
  for (byte j = 0; j <= a; j++) {
   digitalWrite(0, HIGH);
   digitalWrite(1, HIGH);
   digitalWrite(2, HIGH);
   delay(t);
   digitalWrite(0, LOW);
   digitalWrite(1, LOW);
   digitalWrite(2, LOW);
   delay(t);
  }
}

Step 7


Now, remove the ATtiny85 from the breadboard and install it onto the PCB.

Step 8

Afterward, connect the 12V LED strips to the relays using the circuit diagram provided below.

Creating a DIY Light Control System Using the ATtiny85 Microcontroller and a 3-Channel Relay Module

Step 9

Next, provide a 5V power supply to operate the system and a 12V power supply for the LED strips. Once powered, you should see the LED pattern and hear the relay operating sounds.

Okay, enjoy this project by changing the code patterns and adjusting the light sources. Also, be cautious if you’re working with AC voltage. The full video guide is below. We hope to see you in the next project. Have a great day!

Troubleshooting tips

  • Verify Component Status
  • Check the Arduino UNO to ATtiny Connections
  • Select the Correct Board and Port Settings
  • Check the Power Supply
  • Inspect Code and Upload Process
  • Verify Firmware on ATtiny85

Creating a DIY Light Control System Using the ATtiny85 Microcontroller and a 3-Channel Relay Module

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *