I'm building a (LED) blinker circuit for my motorcycle. It will have the basic on/off blinking for left and right (J1 & J2) and an "emergency" mode (J3) for more "aggressive" LED blinking, which will increase the visibility when driving between lanes during traffic jams.
J1, J2 and J3 are the inputs for the switches (L, R, both). J5 and J6 are the outputs to the LED blinkers. J4 and J7 are GND and +12V from the motorcycle.
There's a ATTiny45 which reads the inputs L or R. If both are high, it will go into emergency blinking mode. It uses two output pins with pulses that will blink the LEDs. (if anyone is interested in the code, I'd be happy to share it).
Now, the circuit works on my breadboard (and I hope I correctly transferred it into Fritzing). But since this is my first project in electronics I have a ton of questions and doubts. Now, I'm not asking you guys to review my project (however, would be appreciated), but want to focus on my biggest question for this circuit, the isolation between the "dirty" 11-14V inputs and the "delicate" ATTiny micro controller.
On the input side I've used an opto coupler. But I'm actually wondering if this de-couples anything, since there's a common ground.
On the output side I've used transistors + MOSFETS. I couldn't drive the MOSFETS directly, although I forgot why. I'm wondering if it's not safer to use an opto coupler here in stead of the transistors.
All parts used are in the diagram.
Not sure if it matters much, but the environment on a motorcycle is relatively hostile, vibrations, voltage spikes, etc.
I hope I didn't make too many stupid mistakes! Many thanks for your input!
Thanks, Sjoerd (NL)
--- EDIT, REPLY TO ASMYLDOF ---
Hi Asmyldof,
Thanks for your time to write this amazing reply. This is really helping me learn creating good circuits. I really appreciate it! I've spent quite a number of hours reading and researching the things you wrote down. In return:
- The KA78M05TU is rated at max. 30V. Doing some research I found in a TI white paper that 12V systems may have pulses up to 87V, and 24V systems up to 174V (and I was planning a unit for my 24V Defender). I could not find any through hole LDO's at Conrad or Farnell with such a high max. input voltage. But perhaps the max. input voltage is not the spec I should be looking for here (?).
Could perhaps the transient and negative voltage problem be adequately resolved with a TVS-diode? Vishay has the P4KA series TVS, especially designed for automotive conditions. http://www.vishay.com/docs/88364/p4ka.pdf
- Good point, added the N4148's for added protection.
The idea for the existing N4148's in the diagram was to stop current flowing into both inputs, as they're connected because of the "hazard" switch, that signals to both the inputs.
Reversed. (they were correct on my breadboard, hence the circuit worked in real life).
Added. (they were present on my breadboard, hence the circuit worked in real life).
Interesting point. I'd have to read more about it to fully understand it. For now, I think I will leave the opto-coupler out, to keep it simple, especially if chances for problems are quite low.
I've upped them factor 10 to 4.7k. Although I'm not fully understanding the math behind the base resistors. From what I've read, transistors are current controlled (vs. MOSFETS, which are voltage controlled). Looking in the 2N3904 I cannot find the value that determines at what current the transistor reliably switches.
I added the 22ohm resistor on the ATTiny VCC to make sure it didn't get more than the specified 200mA. Is this unneccessary, or is your point to add a capacitor across the VCC and GND of the microcontroller? How would I calculate the capacitor value?
Ah. Good point, in my case not relevant, as I'm driving quite a bare bone motorcycle; the Yamaha XT600 (kickstart version). I was thinking of making a few of these for some friends of mine, so I will look into this.
At some point I have been thinking to source the input voltage from the switches, as I noticed the ATTiny had practically no boot up time. But I abandoned it since I would have to beef up the switch wires somewhat. The upside however is that I would need one less connector, have no sleep current and would mitigate your point raised.
About the input clamp: See point #1.
About the opto-coupler protection: I will dive into this deeper. I'm leaving it out for now.
Power supply filtering: I'm not neccesarily sticking to the bare minimum, space is a concern on a motorcycle, when I'm leaving certain protection/filtering/etc. out, it's more because of ignorence and lack of experience on my side :). I'd say I'm aiming for a somewhat overengineered circuit, without going overboard :). Having said that, again, see point #1, could this be adequately solved by TVS diode?
I took the values of the two capacitors on the regulator from the datasheet, on my breadboard I'm actually using higher values. You explain that C2 must be quite a bit smaller than C1. But what would be a good way to calculate the values. Is it possible to use values that are too high?
I'm sorry if I'm stealing your time. You've been a great help so far. It's OK to be brief in your answer and give me the pointers to continue the research on my own. Again, many thanks, Sjoerd.