Timed LED Lighting Control – Design

From Logical to Physical

Before I could start to translate the block diagram into KiCad, I needed to be sure about some of the parts I will be using. I want to reuse what I already have installed, so the motion detection module is already a given, along with the LED drivers. The micro controller needs three output pins, three input pins, I2C support as well as the pins for a program header. Since I have worked with Atmel in the clock project and therefore have the tool set I need, I decided for the ATTiny20. The only part I needed to look around for was the relays. As per the block diagram, I decided that the coil would be 12V and the switching contact should be for 240V AC RMS. For the moment I have settled on the JW1AFSN12F from Panasonic.

Translating the block diagrams to KiCad was fairly straight forward. The resulting KiCad diagram pretty much matches the block diagram in so much as the power system, relay driver and the PIR13 interface are modelled in their own sheet. In order to help to keep the 240VAC side separated from the Extra Low Voltage control section as much as possible, I opted to try for a stacked board layout. The two boards will be connected via a pin header and socket (P105 and P107). To simplify this layout I opted to utilise the different notations for the Ground plains. GND for the Extra Low Voltage board and GNDA for the Low Voltage Board.


tl2c-sheet2-powersystemThe Power System comprises of two LDO regulators. One for 12Volt and the other for the 3.3Volt supply. It is expected that the plug pack adapter will probably deliver about 14V – if not, I can always drop the 12V regulator out of the design. It is only provided for extra regulation. As already indicated in the previous post, the 12Volt supply is for the PIR13 modules and relays. The PIR13 modules can handle from 5 to 24Volts as a supply. Because of the distance of the cabling, any voltage drop should be within tolerance. The Micro Controller and therefore the signal lines such as for the I²C bus will be at 3V3 which is compatible with the Raspberry Pi removing the need for any level shifting. The ATTiny20 shares the pins for the I²C bus and SPI bus. At the moment, I have separated these with a couple of resistors as recommended in another article. I have my reservations about this and may yet change this over to a set of jumpers or even a double pole switch.


The signal from the PIR13 is open collector. To avoid having a direct connection between the ATTiny20 and the PIR13 modules, I will be installing some MOSFETs I already have from another project.


I am using the same MOSFETs to drive the relays. As a part of this initial design and a lesson learned in previous projects and Contextual Electronics, I will be including test points and indicator LEDs. An additional lesson learned is to not leave any spare GPIO pins unconnected. These can come in handy and for that reason I have even broken them out onto a pin header. I don’t have to populated the pull-down resistors nor the pin headers for these. But they are provided for if I need it.

Laying it out

I originally envisage the layout as a two piece board that will be separated after assembly. The first attempt was a two layer board and was not nice at all, so I shifted the design to a four layer board. This has pushed the price up enormously. The tip came from Chris Gammell to separate the two sections into their own layouts. One as a two layer board (the 240Volt AC section) and the other as four layer. This has reduced the overall cost significantly and now enables to be enlarge them enough for mounting holes and still be cheaper than the original full layout. The trick with this is how to model this in KiCad. I have tried out my own workflow for this:

  • Model the two boards as needed in the Master Layout PCB as 4-layer. This enables matching the mounting holes and pin-headers without having to swap between layouts
  • At the command prompt, copy the Master Layout PCB twice. Once for the 240V board and the other for the Extra Low Voltage (ELV) board.
  • In each new layout file, delete the section that is not needed and re-adjust, if needed the board layout graphics.
    • Adjust the layers for the 240V board from 4-layers to 2-layers.
“Master Layout” Both boards side by side

Design considerations and constraints

I am reasonable happy with this initial cut of the layout. However, I am not quite ready to send this off to OSH Park. This project and board contains an element I have not worked with before – Hazardous Voltage. This can not be under estimated. One aspect to this is to separate the Low Voltage (LV to ELV boards onto their own. There is still the question of Clearance and Creepage to consider on the LV board. There are a number of very good essays written some with calculators

Trace Width
PCB Trace Spacing
Creepage and Clearance
Clearance and Creepage Rules for PCB Assembly

So I have a bit of a quandary. I don’t want to send off the board for manufacturing before I have sorted out the safety aspects of the design first. I could send it off as-is but if there is a specific requirement I need to meet, I will have to request another. I can, however, make a compromise. With the tip for splitting out the boards as separate PCB files, I can send off the order for the four layer part and leave the two layer, LV board for further consideration. In the mean time, I can bring up and test the control board since the relays either are not needed for the proof of concept or can be simply wired in for basic testing.

At the moment, I have a small uncertainty about the housing and the terminal blocks. It is much easier for me to choose or to know what to look for when I have some actual samples in my hand. So I have ordered a couple of samples to get a better idea of these parts. It is tempting to consider to print the case. However, this would push out the project and shift the focus to a 3d Printing project. I would prefer to keep on track with the Timed LED Lighting Control hardware and firmware.

In the next post, I hope to have the casing and terminal blocks worked out which means that the board will be ready for fabrication. So hopefully then I will be able to talk about bringing the board up.