I2C Relay Timer
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
To make this relay timer we will need:
- ATtiny Device PCB - https://www.tindie.com/products/25521/
- Attiny85 - https://s.click.aliexpress.com/e/_AABr5K
- DIP8 IC socket - https://s.click.aliexpress.com/e/_AXAcR2
- Female pin headers - https://s.click.aliexpress.com/e/_9Awnay
- Male pin headers - https://s.click.aliexpress.com/e/_A2s3Yu
- 5V relay board (isolated) - https://s.click.aliexpress.com/e/_AZa5Ip
- Arduino Nano (for testing) - https://s.click.aliexpress.com/e/_9uMmsh
- Arduino Uno (for programming) - https://s.click.aliexpress.com/e/_9ItJEi
Solder the Required Components
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
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.
Downloads
Device Operation
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!