I2C Relay Timer

by taste_the_code in Circuits > Arduino

1322 Views, 3 Favorites, 0 Comments

I2C Relay Timer

thumb instructables.jpg
VID_20211208_091220.mp4.00_01_16_15.Still002.jpg
Main edit.00_00_07_22.Still001.jpg
VID_20211204_073321.mp4.00_00_25_23.Still001.jpg
VID_20211204_073638.mp4.00_00_31_05.Still003.jpg

In this Instructable, we will build a timer relay that can be controlled via I2C. This relay can be used in complex projects where we need precise timing but we don't need to "torture" the main controller with keeping up the timing correctly. By making the relay controlled over I2C, the main controller will just give the instruction to the relay, and the timing will be kept by another microcontroller, the Attiny85 in this case.

The entire project is based on the ATtiny Device board that I made by using Altium Designer (free trial available on the link) and was manufactured by PCBWay that are now running their Christmas sale!

The ATtiny Device PCB can also be made entirely from a protoboard.

You can also get all of the details, and instructions on the video below.

Supplies

Solder the Required Components

VID_20211208_085929.mp4.00_00_06_13.Still001.jpg
VID_20211204_073638.mp4.00_00_08_04.Still001.jpg
VID_20211204_073638.mp4.00_00_14_10.Still002.jpg
VID_20211204_073958.mp4.00_00_04_12.Still001.jpg
VID_20211204_073958.mp4.00_02_06_26.Still003.jpg
VID_20211204_073958.mp4.00_02_32_17.Still005.jpg
VID_20211204_073958.mp4.00_03_28_14.Still006.jpg

To start assembling what we first need is this board that I designed and for that, you have two options.

Option number one is that you build it yourself from a perf board as I did while testing the design.

Another option is to buy this board from me as I've listed the board for sale on my Tindie shop that I just opened.

If you choose to buy it, thank you! That money goes into growing this channel where they allow me to make better projects.

Next, you will need an 8 pin IC socket, an Attiny85 microcontroller, a 4 pin male header, and a 6 pin female header. Additionally, you will need a relay module and a spare Arduino Uno for programming the ATtiny85.

We can start by first soldering the IC socket after we have aligned its notch with the notch on the silkscreen. Since the Attiny85 needs to be programmed, it is necessary that we are able to remove it from the board and the IC socket gives us the perfect option for that.

After the socket, we need to solder the pin headers from where we will connect the I2C control and power on one side, and the relay module on the other. Since the pin headers on the relay stick up, I'll solder the female header upside down so we can then directly plug the relay into it.

This specific relay module can be controlled both with high and low signals. I'll be using the low input signal as per the installed jumper, but since we will connect the relay to a pin header, we need to replace that jumper with a solder bridge on the header.

If you want to know more about relays, I have a dedicated video that you can check.

To power the relay, we will use jumper wires to solder the VCC and ground connections to the provided pads on the ATtiny Device PCB.

Finally, we can connect the middle pin on the header with one of the Arduino pins and our ATtiny Device will be ready to get programmed and receive its brains.

Programming the Attiny85

VID_20211204_073757.mp4.00_00_03_03.Still001.jpg
VID_20211204_081612.mp4.00_00_08_16.Still001.jpg
Tiny85_ISP.jpg

With the device ready, we now need to work on the code that will control it. There are many ways that you can program an ATtiny and to be honest, they are really beyond the scope of this Instructable.

You can check this Instructable to get full instructions but to summarize, you can program a specific sketch onto an Arduino Uno to make it a programmer, and use that Uno to then program the Attiny by connecting it as shown on the images.

In the past, I've built a dedicated programmer on a perf board that I use to this day, but subscribe, and we'll probably make a better one in the future.

Device Operation

VID_20211204_081051_rec.mp4.00_05_07_11.Still003.jpg
VID_20211208_091220.mp4.00_01_37_18.Still001.jpg
2021-12-08 09-12-22.mp4.00_00_35_24.Still001.jpg
2021-12-08 09-24-14.mp4.00_00_05_02.Still001.jpg
2021-12-08 09-36-24.mp4.00_00_08_23.Still001.jpg

When we connect this relay now to a host project, we can choose to send single characters in order to control it.

Based on the provided code, if we send 1 to it, the relay will be on for 2 seconds and it will then turn off. There are a few more cases where if we send 2 as data, the relay will be on for 3 seconds, 3 will turn it on for 5 seconds and 4 will turn it on for 10 seconds.

If we send 0, or any other character, the current timing will be terminated and the relay will be turned off.

The sketch that I used on the Arduino Nano to test this board is also attached here.

You can check the video below for more details on ATtiny Device PCB, why I made it, how I built this timer relay as an example of using the board and also get access to a lot more projects that I've done so far.

Thanks for reading!

Downloads