The post Capacitive Impedance | Circuit Theory appeared first on Circuit X Code.

]]>

When electrical current flows through a material, it meets resistance primarily due to the nature of the material. *Conductors* will resist less and *insulators* will resist more. Voltage pushes the current; the stronger the voltage, the higher the current. And since the higher the resistance, the lesser the current, we have this math relationship:

This is popularly known as * Ohm’s Law*. Here, voltage and current are

However, *alternating *current and voltages both have magnitude and *phase* since they are sine/cosine quantities. The equation for household AC mains, for example, is :

**Phasors **are invented to avoid exhausting calculations of sinusoidal equations. In circuit theory, sinusoids are functions of time and are therefore *time-domain *quantities.

Phasors are **complex numbers** and can be written in rectangular or polar form.

Here, *X* is the *real part* and *Y* is the *imaginary part*. * j* is the imaginary number equal to √-1.

It is customary to use **j** instead of i in circuits to avoid confusion with the symbol for current.

In polar form, *A* is the magnitude and *ϴ* is the phase.

Conversion between two phasor forms are as follows:

*Rectangular to Polar:*

*Polar to Rectangular:*

A cosine equation easily converts to polar phasor:

And so instead of writing AC voltage like this:

We can just have it like this:

Note that phasor quantities are often in bold, capital letters.

Also instead of dealing with this:

We can just use phasor multiplication which is much simpler:

But if voltage and current are now phasors, does Ohm’s Law’s equation hold true? The answer is **no** since you now have both magnitude and phase:

So, what do we now call the ratio of phasor voltage and current? Not resistance but **impedance (Z).**

If an impedance has no phase difference:

In rectangular form,

As you can see, impedance becomes equal to resistance. In fact, in a *resistor*, there is no phase difference between the current and the voltage.

What if the phase is non-zero? Remember that the imaginary component sinϴ will only be zero if ϴ is zero (or 180 but it’s supplementary to 0). Thus, there will always be an imaginary component in impedance if the phase is not zero.

This *imaginary component* of impedance is called **reactance**. Moreover, the *real part* of impedance is the resistance.

Now with a capacitor, the voltage and current have a relationship of:

The equation is due to the ability of the capacitor to hold electric charge. This means that the current in a capacitor is proportional to the change of voltage in a *given point in time*. In short, a steady voltage produces no current across a capacitor.

Now besides sine/cosine equations, you can also convert differential equations to phasor too.

Here, ω is the radian frequency of the voltage or current.

So, the current-voltage differential equation for capacitors now becomes:

Solving for the ratio of phasor voltage and current:

Hence, the impedance of the capacitor is:

As you can see, this value changes when the radian frequency changes. The higher the value of ω, the lower the Z and vice versa.

Finally, since the impedance of a capacitor is an imaginary number, it is also called **capacitive reactance**.

You can also write the above equation like this:

Converting to polar form,

This means that in a capacitor, the voltage is ahead of current in phase by 90°.

The post Capacitive Impedance | Circuit Theory appeared first on Circuit X Code.

]]>The post Light Dimmer Circuit with Arduino appeared first on Circuit X Code.

]]>This post will show you how to create a light dimmer circuit with a TRIAC. As an additional feature, dimming controls is through an Arduino microcontroller.

A TRIAC is a three-terminal device that conducts current in both directions. However, it *doesn’t readily* conduct current across the MT1 and MT2 terminals.

This is unless current through the gate exceeds the *gate triggering current* I_{GT}. Once this condition is true, the TRIAC keeps conducting, and the main terminal current increases following the curve of the AC sine wave. Removing I_{GT} at this point will have no effect on the main terminal current.

The main terminal current value at which the TRIAC starts conducting is the *latching current*. As the AC current across the main terminal goes down and reaches below the *holding current*, then the TRIAC turns off. Hence, the TRIAC requires another gate voltage to fire again.

A typical TRIAC power control circuit is shown below:

Here, the voltage across the gate is controllable via the variable resistor R1. This effectively varies the current I_{GT}. And by controlling I_{GT}, the latching current point can be moved further or closer to the zero-crossing point. Consequently, the amount of current and voltage across the load varies. Here we see the effect of varying gate voltage. The grey area is the voltage on the load (negative half-cycle not included in the diagram). The larger this area, the greater the power at the load.

The capacitor adds more control as it forms a capacitive impedance with the resistor R1 that shifts the phase of the gate voltage between 0 to 90 degrees.

The delay from the zero-crossing point to the trigger point is the *firing delay angle* (alpha). Varying the resistor R1 in the circuit will vary the firing delay angle. The greater the alpha, the less power the load receives. If a light bulb or an LED is a load, then its light will dim as we vary the gate voltage!

The TRIAC circuit above is already a light dimmer. Now, what if instead of a variable resistor, we use an Arduino to control the dimming instead?

This is entirely possible through *pulse width modulation* (PWM). This is a method of varying the width of a series of pulses in order to vary its average voltage. The average voltage of a PWM is:

The duty cycle is the ratio of the positive cycle width of the PWM signal to its period. *V _{amp}* is the amplitude of the PWM signal. Hence by varying the duty cycle, we can have a changing average voltage.

However, an Arduino operates at DC voltage levels while our TRIAC circuit is at mains voltage! To solve this problem, we need an isolation circuit, particularly an optocoupler IC. The MOC3021 optocoupler IC handles DC voltage at its input and AC mains voltage at its output.

Another good reason for using an Arduino is detecting the zero-crossing point. As shown above, the zero-crossing point indicates the start (or end) of the positive or negative half-cycle of the sine wave. Hence, if we know *when* is this point, then we can adjust the firing delay angle accordingly.

*Zero-crossing detection* can be achieved by adding a second optocoupler. Here we use an MCT2E IC which has a higher voltage tolerance than the MOC3021.

The AC mains is stepped down to a lower voltage, rectified, and applied to the input of the MCT2E. At the peak value of that voltage, the MCT2E triggers, and at its output is a logic HIGH voltage. Otherwise, the MCT2E’s output is low. The output pin of the MCT2E connects to the Arduino’s interrupt pin (2).

The interval between peak values will be the same as the interval between zero-crossing points. And since the interrupt triggers every peak value, the Arduino now determines *when* the zero-cross occurs.

With all of the previous discussion in mind, here’s is now our final Arduino light dimmer circuit:

Here we omit the capacitor because we already have a zero-cross detection circuit for adjusting the firing delay angle. Note that the load can be an incandescent or LED lamp but never a fluorescent lamp as it is not suitable for dimming.

Here’s the code for the Arduino for our light dimmer circuit. First, you need to install the Dimmable Light and ArduinoSTL libraries.

#include "dimmable_light.h" const int syncPin = 2; const int thyristorPin = 5; DimmableLight light(thyristorPin); // Delay between a brightness changement in millisecond int period = 50; void setup() { Serial.begin(115200); while(!Serial); Serial.println(); Serial.println("Dimmable Light for Arduino: first example"); Serial.print("Init the dimmable light class... "); DimmableLight::setSyncPin(syncPin); // VERY IMPORTANT: Call this method to start internal light routine DimmableLight::begin(); Serial.println("Done!"); } void loop() { for(int i=0;i<256;i++){ light.setBrightness(i); delay(period); } }

If you are having errors in compiling the sketch, particularly these kinds:

C:\Users\CxC\Documents\Arduino\libraries\ArduinoSTL-master\src\del_opvs.cpp:25:53: error: 'std::size_t' has not been declared _UCXXEXPORT void operator delete[](void * ptr, std::size_t) throw(){

Go to *C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino* and then locate the “new” file (without extension). Rename it to something else. This solves the compile error.

Have any questions about this tutorial? Drop them as comments below!

The post Light Dimmer Circuit with Arduino appeared first on Circuit X Code.

]]>The post Analog to Digital Conversion Calculator appeared first on Circuit X Code.

]]>Microcontrollers are essentially computers. And like computers, they only understand two numbers: a 1 and a 0. So when a microcontoller needs to read a quantity with varying numbers in a period of time (a.k.a. analog), an analog-to-digital conversion is necessary.

An ADC (analog-to-digital) converter takes samples of an analog signal at equal intervals of time. These samples are used to create a digital representation of the analog signal. Another term for this process is *quantization. *

Moreover, an ADC has a step size or *resolution*, which is a representation of the smallest quantity it can detect. Resolution is often given as the number of bits. The higher the number of bits, the higher is the likeness of the digital representation to that of the original analog signal.

There’s a signed ADC and an unsigned ADC. The difference between the two is that the later considers negative quantities. However, microcontrollers can’t read negative values, hence we are only concerned with unsigned ADC. The resolution for an unsigned ADC is:

Here, V_{ref+} and V_{ref-} are positive and negative voltage references, respectively. In microcontrollers, V_{ref-} is 0 V and V_{ref+} is programmable but equal to the source voltage by default. N is the number of bits of the ADC which is often constant for a particular microcontroller.

A TMP36 is a temperature sensor that gives out 10 millivolts per degree Celsius. We can connect this sensor to an Arduino’s analog pin as shown:

With knowledge on ADC, we can convert the reading into temperature. The *analogRead()* function returns the converted voltage from the sensor. To acquire the voltage, we use:

Here, ADC_{value} is the the value from *analogRead()*, Vref is 5 V (default) and 2^{N}-1 is equal to 1023, with N = 10.

Once the voltage is known, the temperature is now solvable, also considering the 500 mV offset for the TMP36.

The denominator in the above equation is the 10 mV per degree C resolution of the TMP36. Note that 10 x 10^{-3} = 1/100, hence, a simpler formula is:

Finally, the Arduino code/sketch below prints out the temperature reading of the TMP36 on the serial monitor:

void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // convert the input to voltage float volts = (sensorValue * 5.0)/1023.0; // convert voltage to temperature float temperature = (volts - 0.5) * 100; // print out the converted value: Serial.println(temperature); delay(1); // delay in between reads for stability }

This online calculator will compute the minimum and maximum ADC values. Place the sensor minimum and maximum voltages, the reference voltage and the ADC resolution then click “Compute”.

The post Analog to Digital Conversion Calculator appeared first on Circuit X Code.

]]>The post Voltage Divider Calculator appeared first on Circuit X Code.

]]>Resistors are *in series* when the same current flows through them. Consequently, by Ohm’s Law, the total voltage in a circuit of series resistors is the sum of the individual drops on the resistors.

Another way of saying this is that each resistor contributes to the total voltage in the circuit.

Normally, current must be known to determine voltage drop in a single resistor. Each resistor contributes a voltage drop and that drop is proportional to its resistance. Thus, any voltage drop in a series circuit, given only the resistances and total voltage is solvable.

The voltage node V_{O} in the circuit above is the voltage across R_{2}.

Here’s a way to solve for voltage V_{O}:

Since in a series circuit, the total current is equal to the current in each resistor,

And so,

finally,

The above equation is known as a *voltage divider***.**

You can easily modify this equation to solve for the voltage across R_{1}: just replace R_{2} in the numerator with R_{1}.

Voltage dividers are common for scaling down voltages to safe levels. For example, a sensor whose voltage range is from 0 to 9 V damages most microcontrollers.

A voltage divider circuit in between the sensor and microcontroller, preferable two resistors equal in value, can solve this problem. Why two equal values? because if the two resistors are equal in a voltage divider, then the output voltage is half of the input voltage.

Another great use of a voltage divider is resistance-to-voltage conversion. Consider a photocell whose resistance varies with light intensity. A microcontroller wouldn’t be able to read the resistance of the photocell directly. But if the photocell is wired as one of the branches in a voltage divider, then its resistance is converted into voltage.

This online calculator will compute the output voltage in the voltage divider circuit below. Place the input or total voltage value, resistance values and click “Compute”.

Volts (V)

The post Voltage Divider Calculator appeared first on Circuit X Code.

]]>The post CD4013 Dual D Type Flip Flop | Datasheet appeared first on Circuit X Code.

]]>

To understand how to use the CD4013, you must first know how D-type flip-flops work.

Flip-flops have a clock pin, input pin(s) and output pins. The state of the output depends on the state of the input. However, the output doesn’t change unless the clock pin changes. Hence, flip-flops store data, although only 1 bit of it.

The D flip-flop is a type of flip-flop that only has one input, the D pin, and two outputs, Q and Q.

For every *rising pulse* on the CLK pin, the D pin toggles and the Q pin follows its state. *The Q pin is always the complement of the Q pin*.

A variation of the D flip-flop is the inclusion of R (reset) and S (set) pins (shown above). This variation is precisely the type inside the CD4013. When reset is high and set is low, the output Q is always low and the output Q is always high. This is true no matter the state of CLK. Also, the D pin becomes unusable.

Conversely, when reset is low and set is high, the output Q is always high and the output Q is always low. For normal D flip-flop operation, the R and S pins must be both low.

The CD4013 contains two D flip-flop circuits each with R and S pins. Its pinout is shown below:

Being a CMOS IC, the CD4017 consumes less power than its TTL counterpart. It can operate from 3 V to 18 V while its input pins can tolerate + 0.5 V of its supply voltage.

The function table for the CD4017 is shown below:

As already mentioned, the Q pin follows the state of the D pin for every rising clock pulse. This is only true if both S and R pins are low. The Q pin is always the complement of the Q pin.

In normal D flip-flop operations, the S and R pins are tied to ground.

Consider the circuit shown below:

A 1 second pulse is applied to the CLK pin. If the button is pressed while the pulse is rising, the Q pin goes LOW while the Q pin goes high. Pressing the button while the pulse is going low will not result in any change of state.

We can modify the circuit above to create a debouncing circuit:

A common problem when dealing with buttons is that they “bounce” after pressing, resulting in an undetermined state. With this circuit, the output latches to a single state after every button press.

Here, the button connects to the CLK pin while the D pin connects to the Q pin. At button press, the Q pin follows the D pin but since its complement the Q pin is wired to D, the Q pin now complements its previous state.

Here’s an animation of the circuit above:

CD4013 Full Datasheet:

cd4013bThe post CD4013 Dual D Type Flip Flop | Datasheet appeared first on Circuit X Code.

]]>The post WeMos D1 Mini Schematic Diagram appeared first on Circuit X Code.

]]>Some notes on the schematic:

- The voltage regulator is a ME6211 which has a maximum input voltage of 6.5 V. This input pin is directly wired to the 5V pin which means you can power the WeMos D1 Mini at a maximum of 6.5 V.
- A 0.5 A fuse connects the 5V pin and the USB VBUS. 0.5A or 500 mA is the maximum output current from desktop computer USBs. Using a higher current external power supply through the microUSB will not give higher current to the WeMos D1.
- The USB-serial chip is a CH 340G. For interfacing problems with USB, download the CH340 driver.
- There is an external 4MB flash memory communicating with the ESP8226 through SPI.
- Deep sleep solder joint connects RST to GPIO16.

The post WeMos D1 Mini Schematic Diagram appeared first on Circuit X Code.

]]>The post Using Single-Supply Op-Amps for Microcontroller Projects appeared first on Circuit X Code.

]]>

Operational amplifiers are considered one of the building blocks of electronic circuits. In this note, the author describes the basic op-amp circuits with single-supply. But what we are more interested is the design of a single-supply op-amp circuit for temperature measurement.

An example of such circuit is shown below:

In this circuit, a PT100 is used to measure temperature. Such sensor needs current excitation, thus a current-source op-amp configuration is used. Moreover, gain and anti-aliasing circuits are also provided. The conditioned sensor signal is fed to a 12-bit ADC and then read by an 8-bit microcontroller.

The post Using Single-Supply Op-Amps for Microcontroller Projects appeared first on Circuit X Code.

]]>The post Battery Charger Circuit for NiMH with Status Indicator appeared first on Circuit X Code.

]]>

This design overcomes the disadvantages of trickle chargers. These types of charges, in contrast to fast chargers, are more economical. In this design, a microcontroller provides charge status and detect faults.

This battery charger circuit allows simultaneous charging of up to four NiMH batteries. The circuit for the battery charger is shown here:

The 8-bit microcontroller is responsible for task scheduling, voltage measuring, time-keeping and displaying (if there is).

The post Battery Charger Circuit for NiMH with Status Indicator appeared first on Circuit X Code.

]]>The post How to Use the LM2596S Module appeared first on Circuit X Code.

]]>The LM2596S module is an easy to use **voltage regulator** for people who use multiple power sources in their projects.

The module features the **LM2596S** *SIMPLE SWITCHER® Power Converter* from National Instruments. This voltage regulator IC can provide fixed voltages of 3.3, 5 and 12 V as well as a variable output. Moreover, the LM2596S safely belts out a maximum of 3 A current to its load.

The LM2596S requires only 4 external components to work. Below is an application circuit for fixed output voltage:

As seen above, the designer only needs to determine the values of C_{IN}, C_{OUT}, L_{1} and D_{1} base on his/her requirements.

For example, this circuit provides a regulated 5 V_{DC} for an unregulated 12 V_{DC} output:

Meanwhile this circuit provides an adjustable voltage output:

The output voltage is calculated using the formula:

The easiest way to use the LM2596S, obviously, is to use the module. The module shown below has two input pins and two output pins:

You only need to connect an input voltage to the IN pins (taking note of the correct polarity) and then a regulated DC voltage will be on the OUT pins. The input voltage must be higher than the output voltage at least 1.5 V. For example, if you need an output of 7 V, the input must be at least 8.5 V.

To adjust the output, carefully turn the potentiometer knob using a non-metallic screwdriver.

Below an example circuit where a 12 V_{DC} source is used to power both a microcontroller and a solenoid:

Here, the 12 V solenoid is triggered by a 5 V arduino with a FET acting as the switch. The 12 V source needed to drive the solenoid is isolated from the Arduino, preventing the latter from being damaged.

The post How to Use the LM2596S Module appeared first on Circuit X Code.

]]>The post Mesh Analysis for AC Circuits appeared first on Circuit X Code.

]]>

Mesh analysis is a result of simplifying Kirchoff’s Voltage Law (KVL). Recall that according to KVL, the algebraic sum of voltages inside a loop is zero.

Consider the following loop:

In the loop and for any passive circuit, there are sources and sinks. Sources produce energy while sinks consume energy. In the circuit above, we have one voltage source and two resistors as sinks. We assign a convention where sources have positive signs while sinks have negative signs:

The sign on the sources and sinks have significance: if the loop is traversed from minus to plus, the sign is positive, otherwise, the sign is negative.

Now, when the loop is adjacent to another loop, two currents now pass through an element:

The loop direction for all *mesh currents* is always assumed to be the same. Here, both I1 and I2 are in clockwise direction.

The voltage across the resistor R2 will be:

The expression I1 – I2 here is derived by looking at the junction above R2. The currents in that junction would be:

By KCL, the current equation is:

Hence, the current across R2 is:

Now if we do KVL for the two adjacent loops, our equation for the first loop will be:

Similarly, the equation for the second loop (assuming R2 and R3 are the only elements)

I1-I2 here is now positive because the loop is traversed (looking at I2) from minus to plus across R2.

Normally, the values of the voltage source and resistances are given. Thus, we have two equations with two unknowns.

The aim is to arrive at a number of *mesh equations* for a given number of unknown currents. Generally, the number of unknown mesh currents is equal to the number of loops in the circuit. We then use any system of linear equation techniques to solve for the unknowns.

As mentioned, the only difference between mesh analysis in DC and AC circuits is that AC circuits deal with impedances (capacitive, inductive, or resistive). Consider the circuit below:

This circuit has resistors, capacitors and inductors expressed as phasor elements. Let’s try to solve for the voltage across C1.

At the first loop, the equation is:

Here’s the equation on the second loop:

Finally, here’s the equation for the third loop:

Simplifying, our three equations are now:

We then use techniques like Cramer’s Rule to solve for the first and second loop current. Why these two currents? Because the voltage across the capacitor would be:

We can use a general statement to easily recall mesh analysis for AC:

“Sum of impedances on the loop, multiplied by the loop current, minus the sum of impedances common to this loop and the next loop multiplied by the next loop current is equal to the sum of applied voltages to this loop”

Let’s see if this statement applies to our mesh equations. Let us look back to our AC circuit:

The first part is:

“Sum of impedances on the loop, multiplied by the loop current…”

Assuming this is referring to the 1st loop then:

The next statement,

“minus the sum of impedances common to this loop and the next loop multiplied by the next loop current…”

This should be:

Finally,

“…is equal to the sum of applied voltages to this loop”

The applied voltage here is any voltage source within the loop. There is just one voltage source in the first loop thus,

Altogether, the equation for the first loop is:

This is the same as the first mesh equation, just rearranged!

We can also apply the same statement to the second and third mesh:

Again, this is the same equation we arrived on earlier.

Hopefully, this tutorial achieved its objective which is to make you understand mesh analysis for AC circuits. For questions, reactions and suggestions, please drop a comment below!

The post Mesh Analysis for AC Circuits appeared first on Circuit X Code.

]]>