Previous blogs | Description |
---|---|
#1 - Introduction, the plan and materials preparation | In this blog post we describe the project's main concept and some initial high-level design of it. |
#2 - Materials and casing assembly | Our journey with selecting proper materials, cutting and assembling the drawer and its casing! |
#3 - Modelling, cutting, planting! | The title says it all: this part describes some modelling we did before cutting some holes in the drawer and finally planted some vegetables! |
#4 - Plants, harvests, and fertilisers | First harvest, problems with plants and used fertilisers. All that went off-script for our plants in the artificial environment. |
#5 - Piping and pumping - water and liquid fertiliser delivery system | Design and development of water supply system. |
#6 - Mix of fixes - various fixes to water supply, lighting and hardware | Polish and fixes of various components of the system, all the small things. |
#7 - Ride the lightning - Wiring diagram, pinout and components discussion | Diagram of the circuit, pinout for most components, wire choices and their connections |
Next blogs | Description |
---|---|
Detailed description of 3D printed components, their presentation and some tips | |
#10 - Software, architecture and the benefits of good preparation | Big explanation of the software and its architecture |
#11 - Summary | Our final post before the end of the challenge! |
Introduction
In this blogpost we will go into detail on the control circuitry and issues we faced when choosing components and finally assembling the circuit during this busy holiday time
First of all let's get back to the circuit diagram from the post 7 where there was a big black box (actually white) screaming Fan and LED control module. Since in real life we usually do not possess such magic black boxes to obey our will, we decided to design and assemble one!
Enter transistors
Every aspiring electronic hobbyist or professional will eventually come across transistors and admire their sheer potential (and intractability for beginners). Since this is our first bigger project and my first custom made circuit (Jakub) I decided to utilize this opportunity to learn more about practical usage of these components. Having some knowledge from my University electronic courses I thought this would be much easier. Clearly I was mistaken
In order to freshen up my knowledge of them, I decided to browse a few videos and read a couple of blogs about usage of BJT's and MOSFET's acting as a switch in a circuit. Without any boot-licking I must admit that the best resources that explained this concisely were from element14, where their key aspects were introduced:
I also stumbled upon a blog describing their usage in 3.3 and 5 V circuits such as Arduino or Raspberry Pi.
I will not cover transistor basics here, instead providing links to excellent resources describing their usage in applications similar to mine and some more general ones too.
Other than the links mentioned above:
Different types of transistors
Low side vs High side transistor switch - really informative article about transistor configurations from AddOhm's creator BaldEngineer
PWM a 3-pin PC fan with Arduino - also from BaldEngineer, really good elaboration on the topic above
Role of resistors for MOSFETS acting as switches - I cannot underline how clear this article made the usage of resistors in this circuit to me, must see!
I decided to use a N type Enhancement MOSFET in the low side configuration in order to control Fans and LEDs in the Envidrawer with our Raspberry. When looking around the internet and some StackOverflow (Electronics subforum) posts I found a post suggesting to use IRF530N MOSFET for this task.
HERE COMES THE WARNING!
I looked through its datasheet and found that indeed drain current is quite big (14 A at 25 degrees) and Vds up to 100 V. Moreover, for a layman such as me the VGS(th) (Gate-Source Threshold Voltage) being between 2 and 4 V seemed ok for me (taking for granted knowledge from SO answer).
So what went wrong? Let's take a look at a datasheet here:
We can see that the Drain to Source voltage can be up to 100 V (we need only 12 V) and Gate Source voltage can be up to +- 20 V (also OK for our application - 3.3 V), the drain current will be maximum of 6 A for two LED strips in parallel.
As you can see, the VGS(th) is specified with a drain current - Id of 250 uA, and taking a look at the graph below we can see that there is no current rating for VGS lower than 4 V meaning the manufacturer does not guarantee that the MOSFET will be ON with voltages lower than 4 V.
Indeed, the transistor did not turn ON and my LEDs remained turned OFF (because there was no current going through them). This is what you get for not using logic level transistors!
Thankfully, we had IRL540N laying around as a long-past present kit of spare components, which came in handy right now We replaced the MOSFET with the logic-level one (having a VGS(th) of 1 to 2 V) and the circuit sparked to life!
Datasheet of IRL540N for comparison:
VIDEO
As can be seen, the VGS(th) is now much below the TTL HIGH level, making it fully turned ON for our GPIO '1'!
Comparing two MOSFET curves we can now see that in case of IRF530N the VGS is not even considered on this scale to be below 4 V and for the logic level one it is drawn up to 2 V (which is maximum VGS(th)) and even at this level the IDS (Drain to Source current is of 1 Amp).
IRF530N
IRL540N
It is a lesson to be learned the hard way, with some hours wasted on soldering and desoldering Knowledge learned the hard way is not forgotten (at least that is what I heard somewhere...).
Not all is gold
Okay, fine, we have our LEDs or Fans powered but not both of them, so what now? Of course, we could connect them all in parallel and be done with it, but our requirement is to have two separate control circuits for that. But because our only power MOSFETs are non-logic level, we have to be creative and utilize some kind of different logic-level control circuitry for that. Does BJT sound familiar? Because following advice from this post, we decided to utilize one just for this purpose.
In the schematic above all is fine, except the transistor acts as a logic inverter (essentially an NOT logic gate). Therefore we decided to do a well-known double inverter in case a programmer who has no idea of how electronics work would not be surprised by our reverse logic behavior. This is visible in the schematics below:
The BJT double logic inversion circuit.
Initial sketch for the wrongly assumed IRF530N with proper resistor values
Final circuit schematic with proper BJT control
The BJT used here is an 2N3904 which is an NPN with a base current much above the source current of the Raspberry GPIO. The first transistor's emitter is connected to the 3.3 V in order not to fry the second one's base. The second transistor acts as the MOSFETs gate activator and is tied up to 12 V.
Configurations of BJT and MOSFETs are very well explained in this article
A small quirk of this configuration came to life once I disconnected Raspberry (testing another cable which was stripped for DC-DC step down connection). The LEDs which are connected to the non-logic level MOSFETs sparked to life. This is the result of the 12 V input to the MOSFET which pulls it high (because there is no 3.3 V applied to the second BJT to activate it effectively making all the current flow through this BJT instead of activating the Gate of MOSFET). Sounds complex, I know. Take a look at the first sketch above with the truth table and markings and it will all be clear. This is visible in the video below.
Behold my first fairly complicated (at least for me) circuit soldered on an universal PCB. Some solder joints are not the prettiest (especially that I forgot about nice jumper cables I bought just for that occasion ). The solder bridges were a pain and I found out that doing them is quite expensive but is probably quite handy for rails in circuits.
Front side of the PCB, GND on the bottom +12 V on the top, left side is connected to the logic level MOSFET, right to the power one. Flywheel diodes are visible on this side.
The back side of the PCB with transistors and some jumper cables, as well as connections to the loads (orange cubes).
A different view of the PCB with two MOSFETs protruding proudly
Details matter
In the circuit drawn above some details are present which are crucial in order to prevent failures of the load or microcontroller. One of them is the flyback diode which is used to prevent a huge voltage spike going across the inductive load once the supply current is turned off. This allows for a gradual voltage reduction when the voltage is dropped across the diode. This article contains good description of this.
Usage of resistors is also important and was well explained in yet another article by BaldEngineer (gosh I am not related to them in any way ), basically the resistor tied to the "upper" part of the transistor be it Drain or Collector, serves as a voltage divider with the load, and the one tied to the "middle" part (either Gate or Base) is the one responsible for protecting the GPIO pin from so called "rush" current which is due to the non-ideal nature of the semiconductor devices. Speaking plainly - there is a small capacitor and inductor hidden in our small neat transistor which can do some harm to fragile digital circuitry.
The R2 in the schematic above, is responsible for pulling down the MOSFET's value when the microcontroller is in a reset state and its pins are floating.
Moreover, we decided to stick a heatsink on the IRF530N even though the loads on it are below the maximum rated ones. This allows for more stability and to reuse the board in future projects and helps us sleep well at night. I found a helpful site while doing research on power resistance and whether this MOSFET would require a heatsink for our loads and voltages. Better be safe than sorry!
Control that fan
Since we would like to PWM the fans (they are terribly loud when at full speed ), we needed to do some research on the topic and yet again found quite a source of information. This post explained various ways to control a PC fan, be it 2,3 or 4 pin. Because our fan is only 2-pin we decided to do a low-frequency PWM with the logic MOSFET IRL540N. If we wanted to do the PWM at higher frequency (as is often the case with some precision circuitry like PC's or CNC machines) we would need an additional capacitor and a resistor to form a simple RC Lowpass filter. BaldEngineer goes at length to descibe it here. Right now, as I have been testing whether the PWM works I found out it does not work as expected, at voltage around 11.5 V (duty cycle 95%) the fans' engines stall and when the duty cycle is set to 100 they get 12 V and are terribly loud. Looking at the article I linked above (from Analog Devices) it looks like most fans should be still spinning at lower voltage, but this one refuses to work and has a really high stall voltage... This has to be fixed!
WARNING
During development of this circuit we had a small fire as one of the pins spontaneously burst in flames and produced quite a bit of smoke (which was quickly removed with the help of our fumes extractor).
This extractor is a simple PC fan with a double carbon-filter layer applied to the back side.
We soldered a nice ending from the LED strip and use it with the power supply that came with one of the 5m LED strips.
It is important to underline that working with 12 V is not as safe as with 3.3 or 5 V. It is not the high voltage that will do the harm, but the quickly accumulating power due to high voltage and current (as was demonstrated with the burning cable). Remember P = V x I or R x I, and taking into account the tiny jumper cable's low diameter size the resistance was quite big. So, the culprit for the small fire was most probably the large heat dissipation due to high resistance.
Summary
At the end of the day, we managed to finish the control circuitry with our limited choice of components and doing some small over-engineering in order to make the programmer's life easier and the overall experience of working with Envidrawer more logical, excuse the pun (everybody hates inconsistent systems).
Next up, designing various 3D parts of the Envidrawer, hooking up sensors and finally software!
Stay tuned for the final batch of blogs arriving soon!
Jakub & Szymon & Michał
Previous post | Next post |
---|---|
#7 - Ride the lightning - Wiring diagram, pinout and components discussion | #9 - 3D printing |