I Designed A Custom PCB To Avoid Pressing A Button Three Times

I Designed A Custom PCB To Avoid Pressing A Button Three Times

我设计了一块定制 PCB,只为了不用按三次按钮

It’s hard for me to explain why, but ever since I can remember I hated sleeping in full darkness. Perhaps it’s to do with where I was born, where even during the night I could see street lights. Maybe it has to do with me just being a big baby. 很难解释原因,但从我记事起,我就讨厌在完全黑暗的环境中睡觉。也许这与我的出生地有关,那里即使在深夜也能看到路灯。又或许,只是因为我像个长不大的孩子。

But because of also being a nerd I love to automate all sorts of things like this. I use Home Assistant to control basically everything smart around the house, and one of the automations I have is to turn on a dumb night light using a Zigbee wall plug. Basically when my phone goes into the sleep focus mode, it tells Home Assistant that, which in turn runs a few automations around the house, one being turning on this night light. All great right? Well, not really. 但作为一个极客,我喜欢把这类事情自动化。我使用 Home Assistant 来控制家里几乎所有的智能设备,其中一个自动化任务是通过 Zigbee 墙壁插座开启一盏普通的夜灯。简单来说,当我的手机进入睡眠专注模式时,它会通知 Home Assistant,进而触发家里的几个自动化流程,其中之一就是打开这盏夜灯。听起来很完美,对吧?其实不然。

The light that always starts too bright

总是以过亮状态启动的灯

I have bought a cheap night light from the internet that has a button and a switch. The switch basically tells it if it should turn on automatically at night (no thank you, I want that control myself, so the switch is always off), and the button basically jumps between the intensity levels supported. 我从网上买了一个便宜的夜灯,上面有一个按钮和一个开关。开关的作用是决定它是否在夜间自动开启(不用了,谢谢,我想自己控制,所以开关总是关着的),而按钮则是在支持的亮度级别之间循环切换。

Well, here’s the issue. First of all, it doesn’t start on intensity 1. It starts at 3. Then you press once, goes to 4, then again, goes to 5, then yet again and it goes to 1. So every single night when I went to bed, I would have to press that button 3 times because otherwise the light was way too bright. 问题就在这里。首先,它不是从亮度 1 开始的,而是从 3 开始。按一下变成 4,再按一下变成 5,再按一下才回到 1。所以每天晚上睡觉时,我都得按三次按钮,否则灯光实在太刺眼了。

Opening it up

拆解它

I have opened the light to take a look inside, maybe I can gain some information about the chips used there, maybe there is a potentiometer that I can use. But no. The chips didn’t have their names visible. Someone online mentioned that these lights all use the same ICs basically and there’s this trick where if you hold down the switch button for like 10 seconds you set in the EEPROM the new default value (instead of 3). Not on mine. I have tried everything. 我拆开了灯查看内部,想看看能不能找到芯片信息,或者有没有能用的电位器。但并没有。芯片上没有可见的型号。网上有人提到这些灯基本都用同样的 IC,有个技巧是长按开关 10 秒左右,就能在 EEPROM 中设置新的默认值(而不是 3)。但我的灯不行,我试过所有方法了。

So I gave up and just bought a smart night light that I can adjust from Home Assistant, and my nights were perfect since. Thank you for reading. Tune in next time for when I buy the solution to my next problem! 所以我放弃了,直接买了一个可以通过 Home Assistant 调节的智能夜灯,从此我的夜晚变得完美了。感谢阅读。下次当我再次通过“买买买”来解决问题时,记得关注我!

Pressing the button with a chip

用芯片来按按钮

Nope. I did what any normal person would do and went down a rabbit hole of understanding how the circuit worked. In reality it wasn’t anything super complicated, and I realised that my actual best bet at solving this would be a microcontroller that could just press the button for me so to say. 不,我没那么做。我做了任何正常人都会做的事——钻进电路原理的兔子洞里。实际上,这并不复杂,我意识到解决这个问题的最佳方案是使用一个微控制器,让它代我按下按钮。

I decided upon using the ATtiny85. The reason was that this is a super well known chip, from the same AVR family the classic Arduinos use, so you can write the code in the Arduino IDE exactly like you would for an Arduino. And it uses basically 0 power. 我决定使用 ATtiny85。原因在于这是一款非常著名的芯片,属于经典 Arduino 所使用的 AVR 系列,因此你可以像写 Arduino 代码一样在 Arduino IDE 中编写程序。而且它几乎不耗电。

Now the issue is that I can’t just hook this up to power, ground, and the button and be done with it. I also need: 现在的问题是,我不能仅仅把它连接到电源、地线和按钮上就完事了。我还得准备:

  • An HT7333 voltage regulator, because the rail inside the light sits at 8.3 V and the ATtiny wants 3.3 V. (一个 HT7333 电压调节器,因为灯内部的电压轨是 8.3V,而 ATtiny 需要 3.3V。)
  • A 2N3904 transistor, which is the part that actually presses the button. (一个 2N3904 三极管,这是实际执行“按按钮”动作的部件。)
  • A 1 kΩ resistor between the chip and the transistor, so the chip only ever drives a tiny current into it. (一个 1kΩ 电阻,连接在芯片和三极管之间,确保芯片只输出微小电流。)
  • A 10 kΩ resistor to hold the transistor off while everything powers up. (一个 10kΩ 电阻,用于在系统上电时保持三极管处于关闭状态。)
  • Three small capacitors, which smooth out the power going into the regulator and the chip. (三个小电容,用于平滑进入调节器和芯片的电源。)

At the end as you can see there’s a ton of stuff, so I had this brilliant idea of spending even more time and money and creating a PCB for it? Why? Well, cause it would be useful for anyone that needs something like this in their life where they can just have something press a simple switch button for them X amount of times. 最后如你所见,零件非常多,所以我产生了一个绝妙的想法:花更多的时间和金钱去设计一块 PCB?为什么?因为对于任何生活中需要“自动按几次开关”的人来说,这都非常有用。

Designing it in EasyEDA

在 EasyEDA 中进行设计

As I’ve said I’ve never used anything like this to make PCBs, but after some LLMing I have decided to try EasyEDA. Honestly the process was much simpler than I expected. You basically need to lay down a circuit diagram of sorts explaining all the chips and stuff you need, and then the tool lets you show connections. Every one of those that has the same name will be connected then by the router. Neat! 正如我所说,我从未用过这类工具制作 PCB,但在咨询了一些大语言模型后,我决定尝试 EasyEDA。老实说,过程比我预期的简单得多。你基本上只需要画出电路图,说明所需的芯片和元件,然后工具就会帮你显示连接。所有名称相同的节点都会由布线器自动连接。太棒了!