This issue was caused by the choice of SOT-23 symbol when creating my PCB in KiCAD.
As you can see in the picture below, there are a number of symbols associated with transistors in the KiCAD default library:
When mocking up my circuit I chose the first option ‘Q_NPN_BCE’. The key elements here are the last three letters which define the pinout in KiCAD. What I didn’t know at the time, but know now, is most common SMD transistors have a ‘BEC’ pinout rather than ‘BCE’ (or ‘CBE’, ‘CEB, etc…).
If you are running into a similar issue, you can verify which pinout your transistor is by referring to the datasheet.
The pinout of a SOT-23 package is counted from the first of the two pins going in a clockwise motion:
To determine which symbol you should pick in KiCAD, just read out the pins in the same order.
In my case it’s Base, Emitter, & Collector, or ‘BEC’. So when choosing the symbol from the KiCAD library, I should choose the ‘Q_NPN_BEC’ option.
Hopefully this can help someone having a similar issue in their circuit design!
I guess I should preface this with the fact that I’m definitely a beginner when it comes to electronics and circuit design/debugging. Thanks for the help!
I recently developed a circuit board for use with my Raspberry Pi 3 A+. The purpose of the board is to accept various inputs, but also toggle some relays (two solid state, and two regular). My current issue is that I can’t seem to turn relays C and D on. I’d hoping someone could help me find out where I went wrong.
This is what I know so far:
- All the outputs on the pi are working properly (I can see ~3.3v at R2 – R5 when I toggle the respective pins on).
- All channels of the optocoupler are working properly (I can see ~5v at R6 – R9 when I toggle the respective pins on).
- I’m unsure of exactly how to tell if a transistor is doing it’s job with a multimeter, but if I plug a resistor and led into J8 or J9 I can verify those channels are working as the led lights up when I toggle the respective pin on.
- I can say it’s not the protection diode installed wrong, as removing it had no effect.
- If I run a wire from GND to pin 2 of either of the relays, they click.
My best guess right now is that I chose the values for R6 – R9 incorrectly for the application.
It was brought to my attention that the collector and emitter of my transistor may be flip-flopped. After reviewing my design and the datasheet I’m inclined to agree. Here’s a picture for reference: pcb-designrelayraspberry-pischematicskicadshareedit follow flagedited 10 hours agoasked yesterdayToms Jensen4344 bronze badges New contributor
- 1how are the grounds connected? – jsotola yesterday
- 1On my PCB, I filled all the area between the traces with a common ground plane. Everything marked GND is connected directly to that. – Toms Jensen yesterday
- 1Test if the relay portion is actually working (irrespective of your control circuit): take a short wire from ground and touch it to pin 2 of the relay. You should hear it click. – td127 yesterday
- 4You get a click, good – your relay is fine. So now, when you turn assert your on condition the transistor should be saturated and its collector voltage something like 0.3V. Do you see that? – td127 yesterday
- 2What voltages do you measure between collector and ground when you toggle the pin? – ocrdu 16 hours ago
This may be the answer, as I don’t see anything else wrong in the schematic, and your other tests point to the transistors’ not switching properly: according to its datasheet, pin 3 of the MMBT3904 is the collector, and pin 2 is the emitter; in your schematic, they have been swapped.
You may want to measure the voltages between the collector and ground when you toggle the pin to see if the transistors are behaving as they should and are connected properly. The measured voltages should be about 5V and about 0.3V.shareedit follow flagedited 15 hours agoanswered 16 hours agoocrdu61522 silver badges1212 bronze badges
- Hey, I checked and I think your guess is correct. I added an additional image above for context. I’ll have to conduct a test later when I have a moment. – Toms Jensen 12 hours ago
- Assuming the transistor is backwards, though, why would I be able to turn on an LED connected to J8? The fact that I was able to test the circuits for A & B made me rule out any architecture issues before the diode in the chain. – Toms Jensen 12 hours ago
- Alright, this was it. I jury-rigged the transistor into the correct position and everything works. I guess I’ll need to source a different part with the correct pin-out… – Toms Jensen 11 hours ago
- 1If you swapped collector and emitter you may have gone beyond the transistor’s CE reverse breakdown voltage, which makes them leak current in an unelegant way. Either that, or I’m wrong and there is another problem 8-). Only measuring the transistors will give you an answer. Edit: or change the connections and test, that will do as well. – ocrdu 11 hours ago
- Ah, that’s probably correct. The circuit seems to be working well now though. I really appreciate the help! Thanks! – Toms Jensen 10 hours ago
How come my relays C and D do not turn on?
I read your design and found everything looking good. I will later look at the datasheets you referred and see if there are other complications.
But first thing first, I would suggest a couple troubleshooting tricks as summarized below.
Part A – Troubleshooting suggestions
(1) Preparation for offline testing.
(a) Remove the 120VAC 1.5A load and put it aside. The reason is that when the relay switch is on, you should hear a click sound, and another click sound when switch is off.
In other words, there is no need to use the high voltage, heavy current load, especially if it is a big motor which generates EMI spikes and noises. If you like, you can use a LED in series with a 1k as the load and status indicator.
(b) Have you multi-meter ready to measure voltage in a range less than 5V.
(c) It would be nice if you have a NE555 timer module and set it to very roughly to 5Hz (Note 1) , 50% duty cycle to be used as input signal at T1. But this is not at all necessary. You can just use a jumper wire and by hand connect T1 to 0V (Ground) and 3V.
Note 1 – relay switch max frequency is roughly 10Hz, ie, it cannot toggle more than 10 times a second.
Part B – Relay design notes
Please see Appendices below for detailed analysis and design.
Appendix A – Relay, Optocoupler Sample Specifications
Appendix C – The OP’s design with additional status LEDs
Appendix D – Analysis of the OP’s relay switch driver part of design (ie, without the front optoisolated input section)
Appendix E – 2N3904 NPN BJT Datasheet Reading Make Simple Part 1 of 2
Appendix F – 2N3904 NPN BJT Datasheet Reading Make Simple Part 2 of 2
Newbies often found semiconductor devices datasheets difficult to understand. There are many reasons, including the following.
Take the simplest semiconductor device the diode as an example. Let me first explain what is meant by linearity. If the relation of two variables, say independent variable x and dependent variable y, and
y = 3x.
Then we say the relation between y and x is linear. For linear relationship y = kx, the plot of y vs x is straight line with gradient k.
Now if y = x², or y = x³ etc, then we say z and z has a non-linear relationship, and the plot of y against x is a curve.
The 2N3904 can be over simplified as two diodes glued together, and the current I vs voltage V relationship is also non-liner as shown below:
(2）Now that we know what is the meaning of non linearity using the diode I-V equation. Let us use another example, 2N3904 hFE vs Ic, 25C as another example, the left of the following graph:
In real life, things are a little more complicated: If temperature rises, say to +125C, the hFE vs Ic curve is shifted a little bit upwards, and downwards for -55C.
So we see that if we superimpose three hFE vs Ic curves (pink, green, blue) on the same graph, we have a dependent variable hFE vs two independent variables Ic and temperature.
Similarly, the 2N3904 datasheet has other graphs of one dependent variable vs two independent variables.
Appendix G – Calculating the biasing resistor values of the OP’s relay circuit
The time has come to answer the OP’s question: How to calculate the values of the biasing resistors.
Let us start with 2N3904, which is used to drive the Songle relay switch. We learnt form the experimental hysteresis chart that the relay switch starts to switch on around very roughly at 35mA and fully on around 70mA so we decide this very first
(1) 2N3904 Ice(sat) to full switch on Songle relay ~ 70 mA
(2) We read that 2N3904 Ic max = 200 mA, so it should be safe to drive the Songle relay at 70mA.
(3) Now we know that for Ic < 100mA, the hFE > 30. So if
Ic/Ib = 30 => Ib = Ic / 30 = 100mA / 30 ~= 3mA
(4) Now if we assume the optocoupler’s Ice(sat) = 0.2V, then we can calculate the value of the biasing resistor Rb by the following equation:
Rb = Vrb / Ib
= （Vcc – Vce(sat) of optocoupler – Vce(sat) of 2N3904)）/ Ib
= (5V – 0.2V – 0.2V) / 3mA
= 4.6V / 3mA
= 4600 / 3
So using Rb = 1k5 should be enough drive 2N3904 to 70mA to drive Songle relay switch. However, to give some safe margin, it is OK to use smaller Rb, say 470R, 330R, or even the OP’s value of 220R.
(a) This is the initial draft design. I have not proofread my always dodgy calculations.
(b) Me only a friendly hobbyist. No guarantee no nothing won’t melt down or blow up.
- 1Hey, thanks for taking the time to post! A) Indeed, for testing, I have made sure to disconnect any potentially unsafe voltages. B) Yes, I have a multimeter handy. C) I unfortunately don’t have a 555 timer on hand, but I can trigger parts of the circuit with a jumper wire or my Raspberry Pi. – Toms Jensen 22 hours ago
- @Toms Jensen, (1) Thank you for your confirmation. As I said, NE555 timer is just a handy tool for second stage troubleshooting. For initial troubleshooting. using a jumper wire to select 0V or 3V signal to input the relay is already very effective. (2) You mention that: (a) “I couldn’t find any rationale as to why one would choose a resistor value to go in front of the base of a transistor. (b) I also got extremely confused trying to decypher the datasheet for the MMBT3904 Reading transistor 3904 is a bit advanced. Perhaps I can later give an introduction to newbies. / to continue, … – tlfong01 22 hours ago
- You need to have some prerequisite knowledge in suing NPN BJT as a switch, to understand 2N3904 NPN BJT datasheet. I would suggest you to first read Ref 6 of my answer, to know the basic theory of using NPN BJT as a switch (that is hwat your are doing in your relay design) and then skim Ref 7 the 2N3904 datasheet. The most important parameters for using 2B3904 are the following: (a) hFE Ic/Ib current gain), (b) max Ic. / to continue, … – tlfong01 21 hours ago
- The optocoupler datasheet is a bit hard to understand, unless you already know NPN BJT. That is why I suggest you to forget the optocoupler part, and focus on the 2N3904 driving relay switch part. It might take you some time to digest things, but you don’t need to understand everything before you move. So I will perhaps wait for a couple of days before you come back to ask more newbies questions, before we move on. Happy learning. Cheers. – tlfong01 21 hours ago
- ×Comments on locked posts are not eligible for voting-1 Please, please, please, if you are going to participate here write actual answers which concisely address the problem of the post. These overly-long “personal blog posts” of yours are just random noise which distract more than they help. – Chris Stratton 1 hour ago
comments disabled on deleted / locked posts / reviewsAdd Another Answer
Not the answer you’re looking for? Browse other questions tagged pcb-design relay raspberry-pi schematics kicad or ask your own question.