Hi everyone. In this video, we will discuss some electronic components that will help you learn ESP32 and Arduino much faster. We'll understand what each one does using real circuits and practical examples. So, let's get started. If you've ever searched for an ESP32 or Arduino LED blink project, you've definitely seen this tiny resistor connected in series with the LED. But what is it actually doing here? Let's find out. Here's the circuit. Right now, the LED is blinking normally, and the multimeter shows that around 6 milliamp of current is flowing through it. Now, let's remove the resistor. The LED still blinks, but it's much brighter. And if we look at the multimeter again, the current has increased to around 34 milliamp. It's clearly visible that the resistor's job is to limit the amount of current flowing through the LED and the GPIO pin of the ESP32. But why do we need to limit it? Because every GPIO pin can safely supply only a limited amount of current. If we allow too much current to flow, we risk damaging the pin or in the worst case, even the microcontroller itself. That's why almost every LED circuit you'll find online has a resistor connected in series with the LED. Now, you might be wondering if the resistor is so important, why are people using different resistor values like 100, 220, or 330 ohms? How do you choose the correct value? We'll answer that in the LED section when we talk about them in more detail. But here's an interesting fact. A resistor may not always limit current. Take a look at this circuit here. We have two push buttons connected to an ESP32. Pressing button A turns the LED on, while pressing button B turns it off. Notice these two resistors connected to the input pins. Let's remove them and look at the output. Even though I'm not pressing any button, the input keeps randomly changing between high and low. Sometimes the LED even turns on by itself. We can see a random set of values on the serial monitor as well. This happens because when a button isn't pressed, the input pin is actually connected to nothing. It's floating. A floating pin can pick up tiny electrical noise from its surroundings and randomly read high or low. To prevent that, we connect a resistor between the input pin and 3.3 volt or 5 V. Now, even when the button isn't pressed, the pin always stays high. And when we press the button, the pin is directly connected to ground, so it reliably reads low. This resistor is called a pull-up resistor because it keeps or pulls the input pin high. Similarly, you can connect the resistor to ground instead. In that case, the pin normally stays low and the resistor is called a pull down resistor. One more thing, you'll notice these resistors usually have a large value like 10 kiloohms. This is because the input pin doesn't need much current. It only needs a clear high or low voltage. So, a large resistor is more than enough to keep the pin stable. Secondly, when the button is pressed, almost all the current flows through the lowresistance button path instead of the resistor, and that's what we want. Earlier, we mentioned this question. How do you choose the correct resistor value for an LED circuit? To answer that, we first need to understand how they work. A light emmitting diode allows current to flow in one direction only. If you connect it backwards, it simply won't light up. And it is very easy to identify the terminals. The longer leg is the anode or positive terminal. The shorter leg is the cathode or negative terminal. Even if the legs have been trimmed, you can identify the cathode by looking for the flat edge on the LED body. But not all LEDs are the same. Here we have a red, green, blue, and a white LED. The voltage across each LED is different. The red one has around 1.9 volt. The green one has around 2 V. The blue and white has much more, typically around 3 V. This voltage is called the forward voltage or voltage drop. That's why if you replace a red LED with a blue one, the brightness may change even if you're using the exact same resistor. Now, earlier we said the resistor protects the ESP32's GPIO pin. So, what if we connect an LED directly to a battery instead? Let's try it. For a brief moment, the LED becomes extremely bright and then it burns out. Just like the GP IO pin, an LED also has a maximum current rating. Most standard ones are designed to operate at around 10 to 20 milliamp. If much more current flows through them, it heats up rapidly and gets permanently damaged. Now, we finally have enough information to answer this question from the resistor section. All you need to do is a simple calculation. Suppose we're using a 3.3 volt ESP32 GPIO and a red LED. The LED itself drops about 2 V. That means the resistor has to drop the remaining 1.3 volt. Now imagine we want around 10 milliamps of current through the LED. Using Ohm's law, the resistor value becomes 130 ohms. Since 130 ohms isn't a common resistor value, we'd simply choose the nearest standard value like 150 or 220 ohms. If we use a larger resistor like 330 ohms, less current flows, so the LED becomes slightly dimmer, but it's still perfectly safe. If we use a very small resistor, much more current flows, making the LED brighter. But now we risk damaging both the LED and the ESP32. That's why you'll often see values like 220 or 330 ohms in beginner circuits. They're safe choices that work well for most indicator LEDs. Before we move forward, a word from our sponsor. If you're working on electronics projects, you know how important it is to have an ECAD environment that keeps your designs organized and reliable. A good workflow should offer clear version control, rule-based checks, real-time collaboration, and visibility into component availability so you can move from concept to a manufacturable board with fewer mistakes. That's the approach Altium focuses on, helping engineers maintain consistency and manage their projects more efficiently. And for students who want to learn these skills early, there's Altium Student Lab. It's a free learning program that introduces professional design workflows through guided lessons, a cloud workspace, collaboration tools, and certification. To get more details, visit the link in the description. Take a look at this circuit. As I rotate this knob, the LED becomes brighter and dimmer. I am not using any button or any program to control it. Just turning this little component changes the output instantly. This component is called a potentiometer or simply pot. It has three terminals. The two outer terminals are connected to the two ends of a resistor inside. The middle terminal is connected to a movable contact called the wiper. As we rotate the knob, the wiper slides along the resistor. This changes the voltage available at the middle pin. Let's measure the voltage. The outer pin is connected to 3.3 volts while the other is connected to ground. On connecting the multimeter to the middle pin, the voltage changes from zero to 3.3 volts as we rotate the knob. So the potentiometer is acting like an adjustable voltage divider. Now let's connect this middle pin to one of the ESP32's analog input pins. As I rotate the potentiometer, the voltage on the ESP's input pin changes. The ESP senses this changing voltage and based on it adjusts the LED brightness. So, the higher the voltage, the brighter the LED, and the lower the voltage, the dimmer it becomes. If you take a close look at the schematic of an ESP32 or Arduino or almost any microcontroller board, you'll notice capacitors everywhere. In fact, you'll even find a large capacitor connected between the VIN and ground pins. So, why is it there? Unlike a resistor whose job is to limit current, a capacitor's main job is to store electrical charge. You can think of it as a tiny rechargeable battery. Of course, it isn't a replacement for a battery. It can't power an ESP for seconds or minutes, but it can store enough energy to keep a circuit alive for a very short time whenever the supply voltage suddenly drops. Let's see that in action. Here I have an LED connected in series with a resistor. Across the supply, I've connected a 1,000 microfarad capacitor. Now, let's simulate a sudden drop in the supply voltage. For demonstration, I'll slightly disconnect the positive terminal. Watch the LED carefully. Instead of turning off immediately, it slowly fades away. That's because the capacitor stored energy while the supply was connected. As soon as the supply voltage disappeared, it started releasing that stored energy through the LED and resistor. Once the supply becomes stable again, the capacitor charges back up, ready for the next voltage drop. When capacitors are used like this, they're called bypass or decoupling capacitors. And this is by far the most common reason you'll find capacitors in electronic circuits. Now, you might be wondering why the LED stayed on a couple of seconds instead of turning off instantly. That's because a capacitor doesn't release all of its stored energy at once. It discharges gradually. As you can see on the oscilloscope, the capacitor doesn't lose its charge instantly. Instead, the voltage decreases gradually over time. Charging works exactly the same way. The speed at which it charges or discharges depends on two things. The capacitance of the capacitor, the resistance in the circuit. Together, these determine what's called the RC time constant. Here, R is the resistance in ohms and C is the capacitance in farads. So, by changing either of these values, we can control how quickly a capacitor charges or discharges. Capacitors have many other applications as well. In power supplies, they smooth out small voltage ripples, giving the circuit a cleaner and more stable DC supply. And in audio or communication circuits, they're often used as coupling capacitors, allowing AC signals to pass while blocking unwanted DC voltage. Now, when working with ESP32 or Arduino projects, you'll mainly come across two types of capacitors. The first is the ceramic capacitor. These are the tiny capacitors you'll find all over development boards. They're non-polarized, meaning they can be connected in either direction. They're most commonly used as bypass or decoupling capacitors. The second is the electrolytic capacitor. These are the larger cylindrical capacitors. Unlike ceramic capacitors, they are polarized. The longer lead is positive while the stripe on the body marks the negative terminal. Always connect them with the correct polarity, unless you're trying to build a tiny rocket. Earlier in this video, we saw that a GPIO pin can safely supply only a limited amount of current. So, what if I want to control something that needs much more current, like a relay or a motor? That's exactly where a transistor comes in. Here, I have built a circuit to control a relay using the ESP32. The relay turns on and off with a 3-second delay. And you can also hear the clicking sound of the relay as it switches. Since the GPIO pin cannot drive the relay directly, a transistor is used as a switch. Here the GPIO pin simply sends a small signal to the transistor. The transistor turns on and current starts flowing from the external power supply to the relay through the transistor which activates the relay. As you can see, the high current never passes through the ESP32. It flows through the transistor instead. When the GPIO goes low, the transistor switches off and the relay turns off. But how does the transistor know when to switch? An NPN transistor has three terminals: the collector, the base, and the emitter. You can remember them as C, B, and E. The base is the control terminal. A very small current flowing into the base controls a much larger current to flow from the collector to the emitter. We can see this in action by measuring the current at the base and through the relay in the last circuit. The relay is drawing around 57 milliamp when turned on. But the GPIO is supplying tiny current around 10 milliamp to the base to control the big load. That's why a transistor is often described as a current controlled switch. A little current controls a much bigger current. One more thing, notice this resistor connected to the base. Why is it needed? Just like an LED, the base also draws current. Without a resistor, too much current could flow from the GPIO into the transistor. So, we add a resistor to safely limit the base current. Take a look at this simple circuit. When I connect the diode like this, the LED lights up. Now, let's reverse the diode. Nothing happens. Why? Because a diode only allows current to flow in one direction. You can think of it as a one-way gate for electricity. If current tries to flow in the allowed direction, the gate opens. If it tries to flow in the opposite direction, the gate stays closed. That's why the LED stopped glowing. But how do we know which way to connect a diode? Most diodes have a silver or white band on one side. This band marks the cathode or the negative side. Current flows from the anode to the cathode. So if you accidentally reverse it, the diode simply blocks the current. So where do we actually use it in ESP32 or Arduino projects? Let's look at a real example. Here's the same relay circuit we saw earlier. Let's first remove this diode connected across the relay coil. When the relay turns off, its coil suddenly collapses and produces a high voltage spike in the opposite direction. That spike can easily damage the transistor MOSFET or even the ESP32 controlling the relay. Now let's connect the diode again. This time when the relay switches off, the diode gives that stored energy a safe path to circulate through the relay coil. Instead of reaching the ESP32, the energy safely dies out inside the coil. There's one more place you must have seen a diode and it's in the DC motor control circuit. As the motor also contain coils, when you suddenly switch it off, it produces the same kind of voltage spike. That's why you'll often see a diode connected directly across the motor terminals. This diode is called a flyback diode or freewheing diode. And you'll almost always find one across relays, motors, and other inductive loads. Now, diodes have another important job, reverse polarity protection. Take the ESP32 schematic for example. Notice the diode between VUSB and the V and power rail. Why is it there? If an external supply is connected to V and while the board is also powered over USB, the diode prevents that external voltage from flowing back into the computer's USB port. So, it blocks reverse current and helps protect the computer from damage. Just like a transistor, a MOSFET is also an electronic switch, but for many applications, it's simply better. How? Let's take a look at this circuit first. Instead of using a transistor, we've connected an end channel MOSFET to control this DC motor. When the GPIO goes high, the MOSFET turns on. Current flows through the motor and it starts rotating. When the GPIO goes low, the MOSFET switches off and the motor stops. So, just like a transistor, a MOSFET allows a GPIO pin to control a much larger load. But what makes it different? Unlike a transistor which needs a small current at its base to switch on, a MOSFET is controlled by voltage at its gate. That means the ESP32 doesn't need to continuously supply base current. It simply applies a voltage to the gate and the MOSFET turns on. That's why a MOSFET is known as a voltage controlled switch. Just like a transistor has three terminals, a MOSFET also has three. The gate, the drain, and the source. or simply remember them as G, D, and S. Notice something interesting. There's no base terminal here. Instead, the gate is the control terminal. So, if both transistor and MOSFET can do the same job, why should you use a MOSFET? First, a MOSFET requires almost no continuous control current from the ESP32. Since it's controlled by voltage, it's much more efficient. Second, a MOSFET wastes much less power while it's on. That means it generates much less heat, especially when controlling larger loads. And finally, MOSFETs can handle much higher currents than most small transistors. That's why they're commonly used for controlling these applications. But if you're controlling small loads, like a simple relay, buzzer, or a few LEDs, a transistor works perfectly well. One important thing before you buy a MOSFET, not every MOSFET works properly with an ESP32 or Arduino. The GPIO pin outputs only 3.3 volts. Many MOSFETs require a higher gate voltage to switch fully on. If you use the wrong one, the MOSFET may partially turn on, causing it to heat up and the load to perform poorly. You can always check the required gate voltage by looking at the data sheet of the MOSFET. That's why for ESP32 and Arduino projects, you should always look for a logic level MOSFET. These are specifically designed to switch fully using the 3.3 volts or 5V output from a microcontroller. Some popular examples are shown here. We've been using this relay circuit throughout the video. The transistor switches it. The diode protects it. But what exactly is this blue box doing? Let's find out. A relay is simply an electrically operated switch. Unlike a transistor or MOSFET which switch electronically, a relay contains a real mechanical switch inside. When we apply voltage to its coil, the coil becomes an electromagnet. It pulls a metal contact and the switch changes its position. When the voltage is removed, the spring pulls the contact back again. So, even though the ESP32 never physically touches the switch, it can still control it electrically. But here's the real reason relays are so popular. Imagine you want to control a 230 volt AC bulb using an ESP32. Can we connect the ESP directly to the mains? Absolutely not. It's extremely dangerous and it isn't designed to handle such high voltages. Instead, the ESP only powers the relay coil through a transistor or MOSFET. The relay then switches the high voltage AC circuit completely separately. This is called electrical isolation. The low voltage ESP circuit and the high voltage AC circuit are electrically isolated from each other. And that's one of the biggest advantages of a relay. You'll usually see five pins on a relay. Two are for the coil. The remaining three are the switch contacts, common, normally open, and normally closed. When the relay is off, COM is connected to NC. When the relay turns on, COM switches over and connects to N. This is why relays are so versatile. You can choose whether you want a device to be on by default or off by default. So if MOSFETs can also switch loads, why do we still use relays? Because it can safely switch AC as well as DC. They provide complete electrical isolation between the control circuit and the load. And they can handle relatively high voltages with ease. On the other hand, relays are slower. They make a clicking sound, and because they contain moving parts, they eventually wear out. But mechanical relays aren't the only option. You'll also find solid state relays. Unlike mechanical ones, they have no moving parts, so they operate silently, switch faster, and last much longer. However, they are generally more expensive, and are used for specific applications. And one last thing, most projects don't use a bare relay like this. Instead, they use a relay module. A relay module already includes the transistor, flyback diode, indicator LED, and the required resistors that we learned about earlier. So for most beginner projects, the standard 5V electromechanical relay module is the one you'll encounter most often. If you've made it till here, then drop a like and subscribe to our channel to keep supporting us. We will see you soon. Goodbye.
If you're just getting started with ESP32 and trying to build your first project, understanding a few fundamental electronics components can make the learning process much easier. ----------------------------------------------------------------------------------------------------------------------- “Want to be job-ready in electronics design? Try Altium Student Lab! https://www.altium.com/in/yt/topprojects Altium helps engineers streamline their electronics design process with organized workflows, version control, rule-based checks, and smooth collaboration from concept to production. --------------------------------------------------------------------------------------------------------------------------- In this video, I explain the essential components you'll encounter in almost every ESP32 and Arduino project using practical demonstrations and real circuits instead of textbook theory. Whether you're a beginner in electronics, an engineering student, or a hobbyist building embedded systems and IoT projects, this video will help you build a stronger foundation before diving deeper into ESP32 programming and hardware. If you found this video helpful, consider subscribing for more practical tutorials on ESP32, Arduino, Raspberry Pi, embedded systems, sensors, communication protocols, electronics fundamentals, and DIY projects. --------------------------------------------------------------------------------------------------------------- Chapters: 00:00 Intro 00:13 Resistor 03:10 LED 05:44 Altium 06:31 Potentiometer 07:47 Capacitor 11:04 Transistor 13:00 Diode 15:16 MOSFET 17:59 Relay 20:40 Outro