---
# System prepended metadata

title: Simple Electronics
tags: [NTURT, CAN bus, electrical_system, tutorial]

---

# Simple Electronics
###### tags: `tutorial` `electrical_system` `NTURT` `CAN bus`
##### Author: @solarLiterature 
## Prologue
<!---
Some basic electronics knowledge is needed for the CAN bus group when we are working with microcontrollers and sensors. Besides the basic passive components(resistors, capacitors, inductors), modern electronics consists of 3 more basic semiconductors, namely diodes, BJT and MOSFETs. We sometimes directly use them, but since ICs are also made from these 6 basic components, knowing how they work is important to understand some behaviors of ICs as well.
-->
A fundamental understanding of electronics is essential for the firmware/hardware group, particularly when dealing with microcontrollers and sensors. In modern electronics, apart from the basic passive components such as resistors, capacitors, and inductors, there are three other crucial semiconductors: diodes, BJT, and MOSFETs. While we occasionally utilize these components directly, it is vital to comprehend their functioning as integrated circuits (ICs) are also constructed from these six foundational elements. Having this knowledge is significant as it allows us to grasp the behaviors of ICs effectively.

For those who are unfamiliar with the topics, here are some quick start links to get you going. At the bottom, you'll find the main topic for this section along with some additional links. ⚡️

## Resistor
[Resistors - GreatScott](https://www.youtube.com/watch?v=7w5I-KbJ1Sg&list=PLAROrg3NQn7cyu01HpOv5BWo217XWBZu0&index=38)
<!---
We use resistors whenever we need to deliberately add resistance into the circuit. This video is a brief overview of where you might see a resistor in a low voltage circuit.
-->
Resistors are employed whenever deliberate resistance needs to be added to a circuit. The video provided offers a concise overview of the various scenarios where you might encounter a resistor in a low voltage circuit.
### pullup and pulldown
[Pull-up Resistors - SparkFun](https://learn.sparkfun.com/tutorials/pull-up-resistors/all)
<!---
%pullup and pulldowns are the most ubiquitous resistor application in a digital circuit. They are used to prevent any undefined voltage states from appearing around digital inputs. This is a brief essay by sparkfun explaining pullup resistors.
-->
Pull-up and pull-down resistors stand as the most prevalent resistor applications in digital circuits. Their primary purpose is to eliminate any undefined voltage states that might arise around digital inputs. To delve deeper into the subject and gain a better understanding of pull-up resistors, SparkFun has provided a brief essay explaining their .
### voltage divider and Thevinin Theorem

[Voltage Dividers | Khan academy](https://www.youtube.com/watch?v=t_hPrz7rs34)
[Voltage Divider | EEVblog](https://www.youtube.com/watch?v=xSRe_4TQbuo)
<!---
Voltage divider is a simple circuit that is used to step down a voltage signal by a fixed ratio. Besides knowing what it does, one should know its limitation using Thevinin equivalent circuit.
-->
A voltage divider is a straightforward circuit utilized to reduce a voltage signal by a fixed ratio. Understanding its functionality is crucial, but it is equally important to recognize its limitations by employing Thevenin equivalent circuit analysis. This analysis helps us gain insights into the broader implications and constraints of using voltage dividers in various applications.
:::info
Quiz

![](https://hackmd.io/_uploads/BkQ9HBrj2.png)
1. A is connected to an analog voltage signal line but its voltage is too high so we use a voltage divider to scale the voltage down 5:3. What is now the output resistance of the signal?
(suppose A have no output resistance)
2. If the signal receiver at B has an input resistance of 10k, how much does the actual measured voltage deviates from ideal signal?

Answer: 
:::spoiler
1. short A to Gnd and measure the resistance from B to Gnd. 2k and 3k connected in parrallel is 1.2k Ohm.
2. 1.2k and 10k forms another voltage divider and the voltage gets antennuated by 10/(1.2+10) = 89%.
:::
## Diode
[diodes - SparkFun](https://learn.sparkfun.com/tutorials/diodes)
[LED and current limiting resistors - GreatScott](https://www.youtube.com/watch?v=Qlayua3yjuE)
Indicator lights are all over the racing car, so we use LEDs pretty often. 
## Transistors
<!---
Transistors are tiny switches that allow MCUs to control bigger loads with its tiny pins. Although we usually don't deal with loads that draw anything larger than a few amps, knowing the basics of how to use transistors is still a must for switching "medium sized" loads such as indicator lights.
Note: The below resources touch on a lot of different aspects of transistors, such as signal amplification, ringing, high frequency applications, and so on. We only use transistors in a low frequency low current switching application for now, so anything above that can be consisdered advanced content here.
-->
Transistors serve as miniature switches that enable MCUs to control larger loads through their tiny pins. While we typically handle loads that draw only a few amps or less, having a fundamental understanding of how to use transistors is essential, especially when dealing with "medium-sized" loads like indicator lights.

Please note that the provided resources cover various aspects of transistors, such as signal amplification, high-frequency applications, and more, which may be considered advanced content. However, for our current purposes, we solely focus on low-frequency, low-current switching applications involving transistors.
### BJT
[Transistors - SparkFun](https://learn.sparkfun.com/tutorials/transistors/all)

[Tutorial: How to design a transistor circuit that controls low-power devices](https://www.youtube.com/watch?v=8DMZSxS-xVc)
A quick tutorial on how to make a BJT circuit to switch big loads with small signals.
:::info
Quiz:
![](https://hackmd.io/_uploads/SkT8wLHsn.png)
We have a digital signal in 3.3V that drives a BJT with a series resister. the voltage drop across Base and Emitter of the BJT is 0.7V, and the I through the buzzer is 20mA. Suppose that the worst HFE of the BJT is 100, what is the maximum value of R?

Answer:
:::spoiler
20mA/100 = 0.2mA
3.3 - 0.7 = 2.6V across the R
2.6/0.2 = 13k Ohms 
:::
### MOSFET

[MOSFET as a switch - GreatScott](https://www.youtube.com/watch?v=o4_NeqlJgOs&t=22s)

[Designing Power MOSFET Circuits - MicroType Engineering](https://www.youtube.com/watch?v=56p3_aORiJ0)
:::spoiler
This video mentions a lot about MOSFETs from current and power consideration, drivers to gate charge. Ironically, we mostly use MOSFETs to switch indicator lights and brake lights only. So, don't feel too stressed out with the drivers and timing requirements for now.
:::

[Guide: Properly picking and using MOSFETs! - Tom Sanladerer](https://www.youtube.com/watch?v=ND8uJWlOgIQ)
Note on this video:
:::spoiler
This is a video on switching heaters in 3D printers with control signals from an arduino so there are a couple of special terms mentioned that are not too relavant for us. "heated bed" and "hotend" are just types of resistive heaters used in 3D printers. A MOSFET can switch a brake light as well as a big heater. SSR is another type of switch used in many other applications that involves galvanic isolation. The main discussion about choosing MOSFETs starts at 1:20. We can just skip there.
:::

### Extra
[Choosing Discrete Transistors - Analog Devices](https://wiki.analog.com/university/courses/electronics/text/choosing-transistors)

[How do transistors work? - EEVblog](https://www.youtube.com/watch?v=qUeK7pHe0rI)
::: info
Quiz: 
1. Go look for the datasheet of IRL3705N and find its the resistance between drain and source when we drive the gate at 5V.
2. How much power is wasted when we connect a 3A load on the MOSFET switch?

Answer:
:::spoiler
1. 0.012 Ohms at the second page stated as R_DS(on).
2. roughly 3A^2 * 0.012Ohm = 108mW
:::
## Topic
### Task 1
<!---
There is a sensor on the race car that outputs an analog signl related to the pressure sensed. The MCU used to read the signal draws no current from any inputs, but cannot accept any voltage higher than 3.3V. The name of the sensor is M3041-000005-05KPG and its datasheet is [here](https://www.mouser.tw/datasheet/2/418/8/ENG_DS_MSP300_B1-1130121.pdf). Construct a voltage divider that goes between the output of the sensor and the MCU and state the design requirements you found in case someone wants to replicate the circuit but couldn't find the exact resistors easily. (Voltage, Current draw, availability, etc)

-->
In a hypothetical race car, there is a sensor called M3041-000005-05KPG that provides an analog signal related to the sensed pressure. The MCU used to read this signal draws no current from its inputs but has a voltage limitation of 3.3V. You can find the datasheet of the sensor [here](https://www.mouser.tw/datasheet/2/418/8/ENG_DS_MSP300_B1-1130121.pdf). 

Your task is to design a voltage divider circuit that goes between the output of the sensor and the MCU. The voltage divider should ensure that the signal from the sensor is scaled down appropriately to fit within the 3.3V limit of the MCU.

Additionally, state the design requirements you found during your analysis in case someone else wants to replicate the circuit but faces difficulty finding the exact resistors easily. Consider aspects like voltage range, current draw, resistor availability, and any other relevant factors to guide others in successfully recreating the voltage divider circuit.

### Task 2
Let's say that there's 2 loads that we want to switch:
1. a red LED called QTLP690C, powered at 20mA with a simple series resistor
2. an array of 20 red LED called QTLP690C each powered at 20mA with a series resistor

and there's 4 transistors to choose from

1. 2N2222A
2. IRFZ44N
3. TIP41C
4. IRLR2908

The signal provider for the switches is an MCU that outputs 3.3V with a max rated current of 20mA, and the power source is a 5V constant voltage source with no internal series resistance and inductance.
Pick a transistor and resistors with reasonable values to switch the load for each scenario and give the reasons for it in case someone found your circuit design 30 years later but needed new transistors to rebuild it. (e.g. power loss, temperature, voltage, current, etc...)

Below is a sample circuit for a BJT switch.
![](https://i.imgur.com/9UwXe7n.png)

### How to hand in 
For the 2 tasks above, please give some text description and pictures of the circuits, and put all the information into a folder. After finishing both the topic here and the EasyEDA topic, please zip both parts into a single .zip file and put it on NTUCOOL.(Of course, if you used any other means of designing circuits that is best described with something other than text and pictures, please put it in the compressed file as well!)

## Other Resources
Here are some of my own "goto" websites if I want to learn stuff about electronics. And I want to share with anyone into electronics. 
- [EEVblog](https://www.youtube.com/c/EevblogDave)
Very detailed and extensive knowledge taught by a super enthusiastic man
- [GreatScott](https://www.youtube.com/c/greatscottlab)
Quick videos about actually applying electronics

Another great place to look for is the websites of the component manufacturers and distributors themselves. Some of them are pretty technical, while others can be surprisingly easy to understand.
* Analog Devices
* TI
* Digikey