Tuesday 30 April 2019

DC Motor Speed Controller

DC motor speed controllerHere is a simple DC motor speed controller circuit that can be configured to control the sweep rate of automobiles’ windscreen wiper. The circuit comprises a timer NE555 (IC1), medium-power driver transistor BD239 (T1), high-power switching transistor BD249 (T2) and a few other discrete components. It is configured for automobile usage with negative terminal of […]

The post DC Motor Speed Controller appeared first on Electronics For You.



from Electronics For You http://bit.ly/2ZKasjk

Adjustable AC Circuit Breaker

This circuit breaker employs a single operational amplifier (op-amp) and yet has a wide range and is user-friendly. A circuit breaker is an electrical switch intended to protect an electrical circuit or device from damage caused by excess current flow or short-circuit. A basic circuit breaker includes a simple fuse and a normal miniature circuit […]

The post Adjustable AC Circuit Breaker appeared first on Electronics For You.



from Electronics For You http://bit.ly/2PEuvea

Monday 29 April 2019

How to Simulate a Bidirectional Voltage-Controlled Current Source

Learn about simulating an interesting current source built around an op-amp and an instrumentation amplifier.

from All About Circuits Technical Articles http://bit.ly/2ZMeLe6

Audio SoCs Prove Vital for Always-on Voice Activation Platforms and Edge Device AI

As voice-activated digital assistant devices continue to gain popularity, AI- and audio-focused SoCs evolve.

from All About Circuits News http://bit.ly/2Lqx7hF

Artificial Intelligence: The Latest In AI And Its Applications

AI is becoming a disruptive force that is redefining the modern industry. This article features some exciting applications of AI, along with a glimpse into the future, illustrating how AI will continue to transform industries and our lives. Sophia, an artificial intelligence (AI) humanoid, was in the news recently for becoming the first robot ever […]

The post Artificial Intelligence: The Latest In AI And Its Applications appeared first on Electronics For You.



from Electronics For You http://bit.ly/2WdUjAu

Sunday 28 April 2019

Automatic Plants Watering System with Melody

Here is a circuit for automatic plants watering, which can be undertaken every morning without any human effort. A sensor is used to detect ambient light and activate a pump motor to start watering the plants in the morning. You can set the watering time duration as per your requirement. The author’s prototype is shown […]

The post Automatic Plants Watering System with Melody appeared first on Electronics For You.



from Electronics For You http://bit.ly/2Wd2LQi

Friday 26 April 2019

Around The World: Latest Trends and Innovations

In this article we take a look at the various technology trends and interesting solutions we came across while visiting different parts of the globe throughout the year. Every year brings new opportunities to discover new technological inventions that can deliver real-life improvements. Many of the most-talked-about technologies today were discovered decades ago but have […]

The post Around The World: Latest Trends and Innovations appeared first on Electronics For You.



from Electronics For You http://bit.ly/2vxDbtX

Exploring Power Transformer Protection for Power Systems: Failure Types and Differential Protection

Learn why power transformers are important, where they can fail, and why protection systems are crucial.

from All About Circuits Technical Articles http://bit.ly/2V3JjcB

IEEE Announces 3 Amendments to the IEEE 802.3 Standard for Ethernet

Demand for Ethernet is growing, necessitating updates to the IEEE 802.3 standard for Ethernet use.

from All About Circuits News http://bit.ly/2W7q2Df

Virtual And Augmented Reality Come Of Age

Virtual and augmented reality technologies are coming of age and finding many valuable real-world applications. Once upon a time our physical and digital worlds were quite separate, but technological advances are enabling digital worlds to become real enough to merge with the real world. Technologies such as virtual reality (VR) and augmented reality (AR) have […]

The post Virtual And Augmented Reality Come Of Age appeared first on Electronics For You.



from Electronics For You http://bit.ly/2ZBMGpr

Thursday 25 April 2019

High-Voltage DC Power Transmission: Should HVDC Replace AC in Power Systems?

Is AC energy transmission the most efficient option for the 21st century?

from All About Circuits Technical Articles http://bit.ly/2UCYNil

Dialog Semi Focuses on Ultra-Low-Ripple with New Buck Regulator/LDO and PMIC for Low-Power Devices

Dialog Semi has released a new PMIC and a new buck regulator/LDO combo with a focus on ultra-low ripple.

from All About Circuits News http://bit.ly/2ZBafi8

Wednesday 24 April 2019

How to Design a Simple, Voltage-Controlled, Bidirectional Current Source

This article presents a high-performance current source that requires only a few readily available components.

from All About Circuits Technical Articles http://bit.ly/2ZAj4Zw

STMicroelectronics Annouces Tiny, Low-Power MEMS 3-axis Accelerometer and Thermometer on a Single IC

STMicro claims their new MEMS device is the first to measure acceleration and temperature in one IC package.

from All About Circuits News http://bit.ly/2GEsonZ

Tuesday 23 April 2019

Home Automation System Using A Wi-Fi Module

This home automation system can measure temperature, relative humidity, light intensity and control two electrical equipment on Cayenne IoT (Internet of Things) platform. The two electrical equipment can be a light bulb and a ceiling fan, or any other electrical devices. The author’s prototype is shown in Fig. 1. Basic IoT components An IoT system […]

The post Home Automation System Using A Wi-Fi Module appeared first on Electronics For You.



from Electronics For You http://bit.ly/2ITED1B

How to Interpret IMU Sensor Data for Dead-Reckoning: Rotation Matrix Creation

Working with IMUs can maddening for a variety of reasons, but what scares people the most is usually the math.

from All About Circuits Technical Articles http://bit.ly/2UQdgfT

Monday 22 April 2019

Quantization Noise and Amplitude Quantization Error in ADCs

Learn the methods and applications of modeling the quantization error of an ADC using a noise source.

from All About Circuits Technical Articles http://bit.ly/2UPnqO1

Silicon Labs Releases Next-Gen Wireless Gecko IoT Platform with Eyes on Scaling the Cloud

SiLabs' new IoT platform aims to provide what they think designers need most: tools and flexible, secure SoCs.

from All About Circuits News http://bit.ly/2DrXOvA

Selecting The Right Power Supplies for Electronic Devices

A power supply converts AC voltage into regulated DC voltage. Read on to find out how to select the best power supply for an electronic device. A power supply for an electronic equipment is a circuit that converts AC voltage into regulated DC voltage. An electronic device does not normally use electric energy in the […]

The post Selecting The Right Power Supplies for Electronic Devices appeared first on Electronics For You.



from Electronics For You http://bit.ly/2GqlYHL

Saturday 20 April 2019

Software and Tools to Program Drones

Dronecode Visit: Click here Full version: Free (BSD licence) Dronecode software development kit (SDK) is an unmanned aerial vehicle (UAV) program development platform created under the open source Dronecode project. It allows users to connect up to 255 PX4-based unmanned aircraft systems (UASes) to provide movement control and fetch telemetry data. It runs on different platforms […]

The post Software and Tools to Program Drones appeared first on Electronics For You.



from Electronics For You http://bit.ly/2ILIMnV

Friday 19 April 2019

The Incredible Shrinking Resistor: The Advantages and Drawbacks of Ever-Smaller Components

The advantages and disadvantages of ever-shrinking components.

from All About Circuits Technical Articles http://bit.ly/2Pk3tcb

Diodes Incorporated Announces ReDriver IC to Boost Signal Quality Over High-Speed PCIe Interfaces

The new repeater IC is designed to maintain signal integrity for server, storage, and networking applications.

from All About Circuits News http://bit.ly/2UI87Xj

Make Your Own Mini Pocket PC

In this video, the presenter is going to show you how he has used Raspberry Pi and a 3.5 inches display unit to create his own mini Pocket Personal computer. It is easy to make and take very less time constructing. Courtesy: The Wrench  

The post Make Your Own Mini Pocket PC appeared first on Electronics For You.



from Electronics For You http://bit.ly/2GvbgAR

Optical Fibre Sensors Shaping The New Age of Connectivity

optical fibreIn this era of communication and connectivity, optical-fibre sensors find many applications, some of which are discussed in this article. For ages, sensors have been used in hazardous environments. These sensors often contain electronic components. In the past, it was a challenge for engineers to make sensors work at extremely high temperatures, such as in […]

The post Optical Fibre Sensors Shaping The New Age of Connectivity appeared first on Electronics For You.



from Electronics For You http://bit.ly/2UQ81Nu

Thursday 18 April 2019

A Novel Architecture For Decimal Conversion In 8-Bit MCU

A Novel Architecture For Decimal Conversion In 8-Bit MCUThis article highlights common errors in 8-bit instruction sets, and introduces a novel architecture for decimal conversion instructions, especially in 8051, 8086, 8085 and PIC microcontrollers (MCUs). Statistical analysis of different methodologies has revealed that decimal conversion instructions in microprocessors and MCUs do not offer an error-free process. Bugs can be common for the above-mentioned […]

The post A Novel Architecture For Decimal Conversion In 8-Bit MCU appeared first on Electronics For You.



from Electronics For You http://bit.ly/2W23bZG

How the Weibull Distribution Is Used in Reliability Engineering

This article discusses the Weibull distribution and how it is used in the field of reliability engineering.

from All About Circuits Technical Articles http://bit.ly/2II7oya

Wednesday 17 April 2019

Understanding Amplitude Quantization Error for ADCs

This article examines the quantization error of an analog-to-digital converter.

from All About Circuits Technical Articles http://bit.ly/2UqLGRo

TT Electronics Announces New Gate Drive Transformers for Automotive Battery Management Applications

As the EV market grows, TT Electronics offers new small, rugged gate drive transformer options for automotive.

from All About Circuits News http://bit.ly/2GnR9TW

What is a Flyback Diode?

In this tutorial, we will learn about one of the major applications of a PN Junction Diode as a Flyback Diode or Freewheeling Diode. The diode is such applications may also be called as Suppression Diode, Snubber Diode, Kickback Diode, Clamp Diode etc.

An important point to note is that this tutorial is explained with DC Circuits in mind. In AC Circuits, a special circuit called Snubber Circuit (which is a combination of a capacitor and a resistor) is generally used for the same purpose.

Introduction

Switching inductive loads like motors, relays, transformers (in SMPS), solenoids etc. is an extremely common application. When designing switching circuits for such inductive loads, you need to take special care about high voltage spikes or also known as Inductive Flyback.

Without proper circuit protection embedded in your circuit design, the switches (either mechanical or semiconductor) would be seriously damaged and may result in circuit failure. Before understanding what is an inductive Flyback, how a Flyback diode works and other related aspects, first let us briefly take a look at the working of a Diode.

How a Diode Works?

We know that a diode is a semiconductor switch i.e. a switch that does not require any mechanical motion to change its state. When the diode is forward biased and the voltage is greater than the threshold voltage, the diode acts as a closed switch and a large current flow in the forward direction i.e. Anode to Cathode.

Flyback Diode Characteristics of Diode

When the diode is reverse biased, very small current (usually in µA) flows and the diode essentially acts as an open switch.

Keeping this in mind, let us proceed with inductive loads and high voltage spikes.

Inductive Loads in DC Circuits

A conductive loop of wire, when subjected to an electric current through it, generates a magnetic field around it. This conductive loop is known as Inductor.

Flyback Diode Inductor Symbol

In fact, in case of electronics and circuits, even a small piece of wire or a trace on PCB can also be considered as an Inductor (or an inductive element) as it has inductance i.e. ability to store energy in the form of electromagnetic field.

As mentioned earlier, some of the commonly known devices with inductors (also known as inductive loads) are motors, solenoid, electromagnetic relay, transformer etc.

The following circuit shows a simple inductor connected to a DC Power supply with a switch.

Flyback Diode Inductor in DC Circuit Switch Closed

When the switch is closed, the inductor builds up magnetic field and gets fully energized. The current flows from positive terminal of the power supply to the negative terminal through the inductor i.e. the inductor inhibits the flow of current in the circuit while it building up energy.

If the switch is now opened, the flow of current is interrupted and the magnetic field starts collapsing. As per Lenz’s law, the collapsing magnetic field induces a current in the circuit but in opposite direction.

As a result, a negative potential is created on the inductor where there was once a positive potential due to forward flow of current. This is commonly known as Back EMF or Counter EMF or Flyback Voltage.

Flyback Diode Inductor in DC Circuit Switch Opened

Now, due to the Flyback voltage, the inductor essentially becomes a power source with a significantly greater potential the actual power supply itself. For a 12V DC Power supply, the Flyback voltage spike can be few hundreds of volts. The high voltage spike is determined by the following equation.

V = L di/dt, where

  • V is the voltage across the inductor
  • L is the Inductance
  •  di/dt is the rate of change of current

This means that the faster the current through the inductor is changed, the higher the voltage spike.

Flyback Voltage and its Origin

A Flyback voltage or an Inductive Flyback is a voltage spike created by an inductor when its power supply is removed abruptly. The reason for this voltage spike is the fact that there cannot be an instant change to the current flowing through an Inductor.

Time Constant of the Inductor determines the rate at which the current can change through an inductor. This is similar to the time constant of a Capacitor, which determines the rate at which its voltage can change.

Time Constant of Inductor Ï„ = L/R, where L is Inductance in Henries and R is series resistance in Ohms.

Similar to a capacitor, it takes nearly 5 time constants (5Ï„) to dissipate the current in an inductor.

Assume, in the above circuit, the inductor is 10H and the series resistor is 10Ω. So, when the switch is closed, maximum current flows through the inductor.

Flyback Diode Current Flow through Inductor

Now, let us see what happens when the switch is opened suddenly.

Flyback Diode No Current Flow through Inductor

First, let us calculate the time constant. Using the formula of time constant and substituting the above assumed values, it is clear that the time constant is 1 second.

So, it will take approximately 5 seconds from the moment the switch is open, to completely stop the flow of current. This means that current flows in the circuit even after the switch is open (assuming it would take a few milli seconds to completely open the switch). How is this possible?

This can be understood from the inductors point of view. The switch gap, which is essentially air, is viewed as a huge resistor by the inductor and the resistance is in the order of few mega Ohms. This means that the circuit is still closed from inductor’s point of view with a huge resistor filling in the air gap.

Now that it is confirmed that the circuit is still closed, the inductor will try to dissipate the current and in order to do so, the inductor will drop voltage across the air gap resistance by reversing its polarity by using the energy stored in it in the form of magnetic field.

Flyback Diode Flyback Voltage Origin

Now, the inductor tries to flow current as per its current dissipation curve. This could be problematic according to Ohm’s Law, V = I x R.

Even for a small current, when it is multiplied by the huge air resistance (few hundreds of Mega Ohms) will lead to a very high voltage across the air resistor. This is the origin of the Flyback Voltage or Voltage Spike.

Impact of Flyback Voltage on Switches

As there is no physical resistor when the switch is opened, sparks / arcs will occur between the switch and the other terminal, if a mechanical switch is used. All the energy from the arc is usually discharged across the contacts of the switch in the form of heat.

This could potentially damage the switches permanently or drastically reduce the lifetime of the switches. when speaking of switches, they can be mechanical switches or semiconductor switches like Transistors.

How Flyback Diode can prevent Voltage Spikes?

To protect the switch from being damaged due voltage spikes or inductive Flyback, a Flyback Diode or a Freewheeling Diode is used. The basic idea behind the use of a Flyback Diode is to provide an alternative path for the inductor for its current to flow.

Flyback Diode using Flyback Diode

The above image shows the same inductor circuit but with additionally a Flyback Diode. It is important to note that the diode is connected in reverse bias when the switch is closed.

As a result, the diode doesn’t impact the operation of the rest of the circuit when the switch is closed and maximum current flows through the inductor.

Flyback Diode Open Circuit with Flyback Diode

But when the switch is opened, the change in polarity of the inductor will make the diode to be placed in forward bias. Hence, the diode will allow current to flow at a rate determined by the time constant of the inductor.

The resistance of the diode, when it is forward biased, is very less and hence the voltage drop across the diode will be significantly less for the current to flow. This prevents arc at the switching device and as a result protects the switching device from damage.

The post What is a Flyback Diode? appeared first on Electronics Hub.



from Electronics Hub http://bit.ly/2V4wzS5

LM386 Audio Amplifier

Here is a simple LM386 based audio amplifier circuit with the author’s prototype shown below. LM386 based audio amplifier: circuit and working Circuit diagram of the LM386 based audio amplifier is shown in Fig. 2. It is built around popular amplifier LM386 (IC1), an 8-ohm, one-watt speaker (LS1), four capacitors and a few other components. […]

The post LM386 Audio Amplifier appeared first on Electronics For You.



from Electronics For You http://bit.ly/2VPfZTp

Tutorial: Antenna Gain and Directivity

RF antennas or aerials do not radiate equally in all directions. It is found that any realisable RF antenna design will radiate more in some directions than others. The actual pattern is dependent upon the type of antenna design, its size, the environment and a variety of other factors. This directional pattern can be used […]

The post Tutorial: Antenna Gain and Directivity appeared first on Electronics For You.



from Electronics For You http://bit.ly/2IDZW7d

Multipurpose Configurable Audio Buffer For Headphones

This article presents a simple, low-cost stereo headphones buffer using two LM358 operational amplifiers (op-amps). It is used to connect the headphones to line outputs capable of driving loads up to 600-ohm. The circuit has a high input impedance, low quiescent current and large voltage operating range. Power can be taken either from a USB […]

The post Multipurpose Configurable Audio Buffer For Headphones appeared first on Electronics For You.



from Electronics For You http://bit.ly/2GkGRnB

Tuesday 16 April 2019

Monday 15 April 2019

What is a Bypass Capacitor? Tutorial | Applications

In this tutorial, we will learn about one of the major applications of Capacitors as Bypass Capacitor or Decoupling Capacitor.

We know that a Capacitor is an electrical device that is capable of storing energy in the form of electric field and releasing it at a predetermined time and rate. Also, Capacitors block direct current and pass alternating current.

Both these features (or functionalities) of the Capacitor are used in a Bypass Capacitor.

Introduction

Imagine you have designed a nice Op-Amp circuit and started prototyping it and disappointed to find that the circuit doesn’t work as expected or doesn’t work at all. The main reason for this may be Noise from power supply or internal IC Circuitry or even from neighbouring ICs may have coupled into the circuit.

The noise from the power supply due to regular spikes is undesirable and must be eliminated at any cost. Bypass Capacitors act as the first line of defence against unwanted noise on power supply.

What is a Bypass Capacitor?

A Bypass Capacitor is usually applied between the VCC and GND pins of an integrated circuit. The Bypass Capacitor eliminates the effect of voltage spikes on the power supply and also reduce the power supply noise.

The name Bypass Capacitor is used as it bypasses the high frequency components of power supply. It is also called as a Decoupling Capacitor as it decouples one part of the circuit from other (usually, the noise from power supply or other ICs is shunted and its effect is reduced on the other part of the circuit).

Bypass Capacitors are generally applied at two locations on a circuit: one at the power supply and other at every active device (analog or digital IC).

The bypass capacitor placed near the power supply eliminate voltage drops in power supply by storing charge and releasing them whenever necessary (usually, when a spike occurs).

Bypass Capacitor Tutorial Image 1

Coming to the bypass capacitor placed near VCC and GND pins of an IC will be able to instantaneous current demands of a switching circuit (digital ICs) as the parasitic resistance and inductance delay the instantaneous current delivery.

How Bypass Capacitor Eliminates Power Supply Noise?

To understand how a bypass capacitor eliminates noise, you need to first understand how a capacitor works in DC and in AC. When a capacitor is connected across a DC power supply, like a battery from example, an electric field is developed across the dielectric with a positive charge on one of the conductors and negative charge on the other.

As the capacitor charges, a transient current flows from the supply. But as the charge on the capacitor reaches its maximum (determined by Q = CV), the electric field between the conducting plates of the capacitor nullifies the electric field of the power supply and no more charges flow through capacitor.

Hence, in a DC Circuit, the capacitor charges to the supply voltage and blocks the flow of any current through it.

When a capacitor is connected across a time varying AC power supply, the current flows with little or no resistance due to charging and discharging cycles.

Keeping this in mind, when a Bypass Capacitor is placed across the power supply, it provides a low resistance path for the noise (which is essentially an alternating signal) from supply to ground. Hence, the bypass capacitor shunts the power supply with the nose signals.

Since DC is blocked by the capacitor, it will pass through the circuits instead of passing through the capacitor to ground. This is the reason; this capacitor is also known as Decoupling Capacitor.

Bypass Capacitor Considerations

A circuit without Bypass Capacitor or improper Bypassing can create severe power disturbances and may lead to circuit failure. Hence, an appropriate Bypass Capacitor must be used in the circuit.

The following are a few considerations that must be taken into account when selecting a Bypass Capacitor.

  • Capacitor Type
  • Capacitor Placement
  • Capacitor Size
  • Output Load Effect

Capacitor Type

In high frequency circuits, the lead inductance of the bypass capacitor is an important factor. When switching at high frequencies like > 100MHz, a high frequency noise is generated on the power rails and these harmonics in power supply in combination with high lead inductances will cause the capacitor to act as an open circuit.

This prevents the capacitor to supply the necessary current when needed in order to maintain a stable supply. Hence, when selecting a capacitor for bypassing power supply from internal noise of the device (integrated circuit), a capacitor with low lead inductance must be selected.

MLCC or Multilayer Ceramic Chip Capacitors are the preferred choice for bypassing power supply.

Capacitor Placement

The placement of a Bypass Capacitor is very simple. Generally, a Bypass Capacitor is placed as close as possible to the power pin of the device. If the distance increases, the extra tack on the PCB can translate into a series inductor and a series resistor, which lowers the useful bandwidth of the capacitor.

Hence, longer PCB traces between the power pin and the bypass capacitor increases inductance and defeats the purpose of introducing the bypass capacitor in the first place.

Capacitor Size

The size of a bypass capacitor is crucial in determining the ability of the capacitor to supply instantaneous current to the device when needed. There are two things to be considered when determining the size of a capacitor.

  • The amount of current required when switching a pin from low to high
  • Maximum Pulse Slew Rate to calculate the maximum current of a capacitor

Output Load Effect

If the output load is purely resistive, then the frequency doesn’t affect the rising and falling times of the output. However, if the output load is capacitive, an increase in frequency will cause higher transient current and oscillations in the supply.

Role of Bypass Capacitor in Amplifiers

The following image shows the circuit diagram of a voltage divider biased Amplifier. Resistors R1, R2, RC and RE help the transistor to bias with Q point approximately at the middle of the load line. The resistor RE adds stability to the Q point.

Bypass Capacitor Tutorial Bypass Capacitor in Amplifier

There are two coupling capacitors C1 and C2 at input and output respectively. C1 couples the alternating signal source to the base of the transistor while C2 couples the amplifies signal to the load.

But the device of discussion is the Bypass Capacitor CE. The magnitude of the emitter current is large due to amplification of the ac signal. If there is no bypass capacitor, the large ac emitter current flows through the emitter resistor RE with a large ac voltage drop across RE.

This results in a small ac base current as the voltage drop across the RE subtracts from Vin. Hence, the output voltage decreases and the voltage gain reduces drastically.

We need to provide a low impedance path for the ac emitter current to flow from emitter to ground to prevent a loss of voltage gain. This can be achieved by connecting a capacitor between emitter and ground and this acts as a Bypass Capacitor for bypassing ac emitter current.

Where Bypass Capacitors are used?

Almost all analog and digital devices use bypass capacitors. In both these devices, a bypass capacitor, usually a capacitor or value 0.1µF, is placed very closely to the power pins. Power supply sources also use bypass capacitors and they are usually the larger 10µF capacitors.

The value of bypass capacitor is dependent on the device i.e. in case of power supplies it is between 10µF to 100µF and in case of ICs, it is usually 0.1µF or determined by the frequency of operation.

If the bandwidth of the device is approximately 1MHz, a 1µF bypass capacitor is used. If the bandwidth is approximately 10MHz or above, a 0.1µF capacitor is used.

In some applications, a network of bypass capacitors in parallel is used to filter a wide range of frequencies.

Bypass Capacitor Tutorial Multiple Bypass Capacitors

Every active device in a circuit must have a bypass capacitor placed close to the power supply pin. In case there are multiple bypass capacitors, the smaller capacity capacitor must be placed close to the device.

In analog circuits, a bypass capacitor generally redirects the high frequency components on the power supply to ground. Otherwise, these signals would enter into the sensitive analog IC through the power supply pin. If a bypass capacitor is not used in an analog circuit, there is a good chance that noise is introduced into the signal path.

The use of bypass capacitors in Digital circuits with microprocessor and controllers is slightly different. The major function of bypass capacitors in digital circuits is to act as charge reservoirs.

In digital circuits, where the logic gates are switched at high frequency, there is requirement for a large current during the switching. The parasitic resistance and inductance will not allow sudden flow of huge current that is required in the switching process.

Hence, a Bypass, which is placed as close to the power pin as possible to reduce parasitic inductance, will provide the instantaneous current before the power supply could kick-in.    

Applications of Bypass Capacitors

The main purpose of a bypass capacitor is to shunt the undesirable high frequency components of a power supply while passing the desirable DC. The following are the three main areas of application of Bypass Capacitors.

Compensate Current Demands

Bypass capacitors are used to provide the necessary current when demanded. For example, the drive current to a loudspeaker from an amplifier varies according to the signal and the current demands of the amplifier’s output are dependent on the loudness of the signal.

Such varying current at the output causes a varying current drawn from the supply. These variations in the power can cause fluctuations that may be coupled to the signal line as noise through the power supply.

Bypass Capacitors can be helpful in reducing the fluctuations by acting as temporary current sources.

Power Supply Filters

In power supplies, large bypass capacitors usually 100µF or 1000µF or more, are used to filter the ripples of the rectified sine wave.

Digital Systems

In digital circuits, a bypass capacitor is used between VCC and GND pins of all the IC. This helps in maintaining a stable power supply within the recommended range of the IC and also to eliminate high frequency signals from entering the power supply. Additionally, they also act as instantaneous current providers in fast switching circuits.

The post What is a Bypass Capacitor? Tutorial | Applications appeared first on Electronics Hub.



from Electronics Hub http://bit.ly/2Kemgq7

Input Capacitance in Analog Circuits: How to Compensate for Input Capacitance of Op-Amps

Learn about the effect of input parasitic capacitance and how to compensate for it in analog circuit design.

from All About Circuits Technical Articles http://bit.ly/2UAZE8d

DESIGN: Selecting The Right PCB Board Materials

Electronic devices, microwaves and other household devices rely on PCB technology to stay in working condition. Lifetime and performance of a PCB board depend on the choice of circuit board material. To select the right circuit board material, it is important to examine the materials available for different board categories. There are different properties and […]

The post DESIGN: Selecting The Right PCB Board Materials appeared first on Electronics For You.



from Electronics For You http://bit.ly/2UAgC6w

Sunday 14 April 2019

Digital Protractor And Angle Measurement Device With Arduino(Hindi & English).

A compass and a protractor are two of the most basic tools used in geometry. For mathematics and engineering students, these tools are a must. But sometimes it is difficult to get accurate angle measurement for certain structures and geometrical shapes using these traditional tools. So, I thought of developing a digital compass to make […]

The post Digital Protractor And Angle Measurement Device With Arduino(Hindi & English). appeared first on Electronics For You.



from Electronics For You http://bit.ly/2Gmu9pw

Smart Arduino Touch Switch Board For Home Automation Under Rs 1,700(Hindi & English)

If you are still using the traditional switches, then I’m sorry to say this but they are outdated now.  Moreover, these traditional switches have mechanical moving parts which get damaged on continuous use. Nowadays, old switch boards are getting replaced by modern touch switches that not only enhance the look of our homes but are […]

The post Smart Arduino Touch Switch Board For Home Automation Under Rs 1,700(Hindi & English) appeared first on Electronics For You.



from Electronics For You http://bit.ly/2Ix4D2z

How e-Commerce Websites Use Recommendation Systems To Generate Repeat Purchases?

e-Commerce Website Recommendation SystemsImprovements to recommendation systems is a low-hanging fruit that would not only ensure that customers have a high repeat rate but also improve customer experience. Recommendation systems are one of the primary ways in which e-commerce websites tend to generate repeat purchases, that is, getting a purchase from an already registered customer. Repeat purchase is […]

The post How e-Commerce Websites Use Recommendation Systems To Generate Repeat Purchases? appeared first on Electronics For You.



from Electronics For You http://bit.ly/2UZwKhm

Saturday 13 April 2019

Control Panel For Submersible Monoblock Pumpset

Presented here is a submersible pump starter circuit using electronic overload relay, solid-state relay and adjustable startup delay. A submersible pump is a type of centrifugal pump designed to function with the pump and the motor completely submerged in the water. The motor is sealed in such a way that it prevents any ingress of […]

The post Control Panel For Submersible Monoblock Pumpset appeared first on Electronics For You.



from Electronics For You http://bit.ly/2X6sKsP

Friday 12 April 2019

Introduction To Real-Time Embedded Systems

This article looks at real-time embedded systems including classifications, constraints, and design patterns.

from All About Circuits Technical Articles http://bit.ly/2UeR2Pu

How Does a Lithium-ion cell Works?

In this video, the presenter is going to share with you the working principle of a Li-ion cell and how it is used in Electric cars. He is going to also explain why Li-ion cell technology is superior to other conventional vehicle technology like combustion engines, induction motors etc. Courtesy: Learn Engineering

The post How Does a Lithium-ion cell Works? appeared first on Electronics For You.



from Electronics For You http://bit.ly/2P50kww

Exploring The Applications of Nanotechnology and Nanomaterials

nanotechnologyIn simple terms, nanotechnology is the part of science that deals with the control of matter with dimensions smaller than 100 nanometres, and can go down to atomic and molecular scales. The study and manipulation of matter, particles and structures on the nanometer scale is referred to as nanoscience. Nanotechnology is the application of nanoscience […]

The post Exploring The Applications of Nanotechnology and Nanomaterials appeared first on Electronics For You.



from Electronics For You http://bit.ly/2v3oqie

Thursday 11 April 2019

Trinamic Introduces the TMC5160 SilentStepStick for Silent Stepper Motor Operation

The TMC5160 SilentStepStick is a tiny breakout board that can drive motors up to 3A phase current at 35V.

from All About Circuits News http://bit.ly/2URDaix

Wednesday 10 April 2019

TI Technology Enables High-Power EV DC Fast Charging Stations

The post TI Technology Enables High-Power EV DC Fast Charging Stations appeared first on Electronics For You.



from Electronics For You http://bit.ly/2Z6aLEW

The Future of Renewable Energy

The post The Future of Renewable Energy appeared first on Electronics For You.



from Electronics For You http://bit.ly/2X2XcnO

The Arm Architecture Explained

Learn more about the Arm computer architecture, including ISA, execution states, and processor families.

from All About Circuits Technical Articles http://bit.ly/2GfjkWv

Trinamic Introduces High-Power Gate Driver for BLDC and PMSM Motor Control Solutions

The TMC6200 integrates in-line current sensing for complete Field Oriented Control solutions for servo motors.

from All About Circuits News http://bit.ly/2IbgRhS

Alarm using your own Voice

voice alarmThis alarm plays your prerecorded voice message. It is built around the readily available quartz clock. Take the buzzer out of the quartz clock and connect its positive terminal to pin 1 and negative terminal to pin 2 of optocoupler IC MCT2E (IC2). Pin 4 of IC2 is grounded and pin 5 is connected to […]

The post Alarm using your own Voice appeared first on Electronics For You.



from Electronics For You http://bit.ly/2VI2cO8

Wireless Caller ID Display for Bikers

Wireless Caller IDThis simple telephone caller identification display can be very useful for bikers. While riding a bike or any two-wheeler, the cellphone is usually kept in a pocket. When you receive a phone call on your cellphone, you do not know who is calling unless you look at the screen. And sometimes you may not even […]

The post Wireless Caller ID Display for Bikers appeared first on Electronics For You.



from Electronics For You http://bit.ly/2Ia3X3Q

Tuesday 9 April 2019

Python vs. C/C++: Why Should Electrical Engineers Bother Learning Python?

Why should an electrical engineer bother learning Python, anyway?

from All About Circuits Technical Articles http://bit.ly/2WVzWIc

Apple Cancels AirPower Program Just as the Wireless Charging Power Application Heats Up

Apple pulls its wireless charging platform as the application gets more chip-level hardware. What gives?

from All About Circuits News http://bit.ly/2X495df

DIY Arduino Gimbal | Self-Stabilizing Platform

In this tutorial we will learn how to build an Arduino Gimbal or a self-stabilizing platform with servo motors. This tutorial is actually an extension of the previous tutorial about the MPU6050 tutorial.

Overview

I designed the gimbal using a 3D modeling software. It consists of 3 MG996R servo motors for the 3-axis control, and a base on which the MPU6050 sensor, the Arduino and the battery will be placed.

Arduino Gimbal 3D Model

You can find and download this 3D model as well as the STL files which are used for 3D printing on here:

DIY Gimbal 3D Model:

STL Files:

 

Using my Creality CR-10 3D printer, I 3D printed all the parts and they came of just perfect.

DIY Gimbal 3D printed parts

Assembling

Assembling the gimbal was quite easy. I started with installing the Yaw servo. Using M3 bolts and nuts I secured it to the base.

Arduino Gimbal servo motor installation

Next, using the same method I secured the Roll servo. The parts are specifically designed to easily fit the MG996R servos.

For connecting the parts to each other I used the round horns which come as accessories with the servos.

First, we need to secure the round horn to the base with two bolts, and then attach it to the previous servo using another bolt.

Assembling the Arduino gimbal

I repeated this process for assembling the rest of the components, the Pitch servo and the top platform.

Arduino Self-Stabilizing Platform

Next, I passed the servo wires through the holders openings in order to keep them organized. Then I inserted the MPU6050 sensor and secured it on the base with a bolt and a nut.

Arduino Self-Stabilizing Platform with MPU6050 sensor

For powering the project, I used 2 Li-ion batteries which I placed in this battery holder. I secured the battery holder to the base using two bolts and nuts.

Li-ion batteries holder

The 2 Li-ion batteries will produce around 7.4V, but we need 5V for powering the Arduino and the servos. That’s why I used a buck converter which will convert 7.4V to 5V.

Arduino Gimbal Circuit Diagram

What’s left now, is to connect everything together. Here’s the circuit diagram of this project and how everything needs to be connected.

DIY Arduino Gimbal - Self-Stabilizing Platform

You can get the components needed for this Arduino Tutorial from the links below:

*Please note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

At the end I squeezed the electronics components and the wires into the base, and covered them using this cover at the bottom.

With this the self-balancing platform or the Arduino gimbal is done and it works well as expected. What’s left is to take a look at the program.

DIY Arduino Gimbal Self-Stabilizing Platform with MPU6050 sensor

Arduino Code

The Arduino code for this example is a modification of the MPU6050_DMP6 example from the i2cdevlib library by Jeff Rowberg.

Here’s you can download the code:

 

Code description: So, we are using the output readable yaw, pitch and roll.

// Get Yaw, Pitch and Roll values
#ifdef OUTPUT_READABLE_YAWPITCHROLL
    mpu.dmpGetQuaternion(&q, fifoBuffer);
    mpu.dmpGetGravity(&gravity, &q);
    mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);

    // Yaw, Pitch, Roll values - Radians to degrees
    ypr[0] = ypr[0] * 180 / M_PI;
    ypr[1] = ypr[1] * 180 / M_PI;
    ypr[2] = ypr[2] * 180 / M_PI;
    
    // Skip 300 readings (self-calibration process)
    if (j <= 300) {
      correct = ypr[0]; // Yaw starts at random value, so we capture last value after 300 readings
      j++;
    }
    // After 300 readings
    else {
      ypr[0] = ypr[0] - correct; // Set the Yaw to 0 deg - subtract  the last random Yaw value from the currrent value to make the Yaw 0 degrees
      // Map the values of the MPU6050 sensor from -90 to 90 to values suatable for the servo control from 0 to 180
      int servo0Value = map(ypr[0], -90, 90, 0, 180);
      int servo1Value = map(ypr[1], -90, 90, 0, 180);
      int servo2Value = map(ypr[2], -90, 90, 180, 0);
      
      // Control the servos according to the MPU6050 orientation
      servo0.write(servo0Value);
      servo1.write(servo1Value);
      servo2.write(servo2Value);
    }
#endif

Once we get the values, first we convert them from radians to degrees.

// Yaw, Pitch, Roll values - Radians to degrees
    ypr[0] = ypr[0] * 180 / M_PI;
    ypr[1] = ypr[1] * 180 / M_PI;
    ypr[2] = ypr[2] * 180 / M_PI;

Then we wait or make 300 readings, because the sensor is still in self-calibration process during this time. Also, we capture the Yaw value, which at the beginning is not 0 like the Pitch and Roll values, rather it’s always some random value.

// Skip 300 readings (self-calibration process)
    if (j <= 300) {
      correct = ypr[0]; // Yaw starts at random value, so we capture last value after 300 readings
      j++;
    }

After the 300 readings, first we set the Yaw to 0 by subtracting the above captured random value. Then we map the values of the Yaw, Pitch and Roll, from – 90 to +90 degrees, into values from 0 to 180 which are used for driving the servos.

// After 300 readings
    else {
      ypr[0] = ypr[0] - correct; // Set the Yaw to 0 deg - subtract  the last random Yaw value from the currrent value to make the Yaw 0 degrees
      // Map the values of the MPU6050 sensor from -90 to 90 to values suatable for the servo control from 0 to 180
      int servo0Value = map(ypr[0], -90, 90, 0, 180);
      int servo1Value = map(ypr[1], -90, 90, 0, 180);
      int servo2Value = map(ypr[2], -90, 90, 180, 0);
      
      // Control the servos according to the MPU6050 orientation
      servo0.write(servo0Value);
      servo1.write(servo1Value);
      servo2.write(servo2Value);
    }

Finally using the write function, we send these values to the servos as control signals. Of course, you can disable the Yaw servo if you want just stabilization for the X and Y axis, and use this platform as camera gimbal.

Please note this far from good camera gimbal. The movements are not smooth because these servos are not meant for such a purpose. Real camera gimbals use a special type of BLDC motors for getting smooth movements. So, consider this project only for educational purpose.

That would be all for this tutorial, I hope you enjoyed it and learned something new. Feel free to ask any question in the comments section below and don’t forget to check my collection of Arduino Projects.

The post DIY Arduino Gimbal | Self-Stabilizing Platform appeared first on HowToMechatronics.



from HowToMechatronics http://bit.ly/2GbN72g

Arduino and MPU6050 Accelerometer and Gyroscope Tutorial

In this tutorial we will learn how to use the MPU6050 Accelerometer and Gyroscope sensor with the Arduino. First, I will explain how the MPU6050 works and how to read the data from it, and then we will make two practical examples.

Overview

In the first example, using the Processing development environment, we will make a 3D visualization of the sensor orientation, and in the second example we will make a simple self-stabilizing platform or a DIY Gimbal. Based on the MPU6050 orientation and its fused accelerometer and gyroscope data, we control the three servos that keep the platform level.

How It Works

The MPU6050 IMU has both 3-Axis accelerometer and 3-Axis gyroscope integrated on a single chip.

The gyroscope measures rotational velocity or rate of change of the angular position over time, along the X, Y and Z axis. It uses MEMS technology and the Coriolis Effect for measuring, but for more details on it you can check my particular How MEMS Sensors Work tutorial. The outputs of the gyroscope are in degrees per second, so in order to get the angular position we just need to integrate the angular velocity.

MPU6050 IMU 3-Axis Accelerometer and 3-Axis Gyroscope

On the other hand, the MPU6050 accelerometer measures acceleration in the same way as explained in the previous video for the ADXL345 accelerometer sensor. Briefly, it can measure gravitational acceleration along the 3 axes and using some trigonometry math we can calculate the angle at which the sensor is positioned. So, if we fuse, or combine the accelerometer and gyroscope data we can get very accurate information about the sensor orientation.

The MPU6050 IMU is also called six-axis motion tracking device or 6 DoF (six Degrees of Freedom) device, because of its 6 outputs, or the 3 accelerometer outputs and the 3 gyroscope outputs.

Arduino and MPU6050

Let’s take a look how we can connect and read the data from the MPU6050 sensor using the Arduino. We are using the I2C protocol for communication with the Arduino so we need only two wires for connecting it, plus the two wires for powering.

Arduino and MPU6050 Circuit Diagram

You can get the components needed for this Arduino Tutorial from the links below:

*Please note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

MPU6050 Arduino Code

Here’s the Arduino code for reading the data from the MPU6050 sensor. Below the code you can find a detail description of it.

/*
   Arduino and MPU6050 Accelerometer and Gyroscope Sensor Tutorial
   by Dejan, https://howtomechatronics.com
*/

#include <Wire.h>

const int MPU = 0x68; // MPU6050 I2C address
float AccX, AccY, AccZ;
float GyroX, GyroY, GyroZ;
float accAngleX, accAngleY, gyroAngleX, gyroAngleY, gyroAngleZ;
float roll, pitch, yaw;
float AccErrorX, AccErrorY, GyroErrorX, GyroErrorY, GyroErrorZ;
float elapsedTime, currentTime, previousTime;
int c = 0;

void setup() {
  Serial.begin(19200);
  Wire.begin();                      // Initialize comunication
  Wire.beginTransmission(MPU);       // Start communication with MPU6050 // MPU=0x68
  Wire.write(0x6B);                  // Talk to the register 6B
  Wire.write(0x00);                  // Make reset - place a 0 into the 6B register
  Wire.endTransmission(true);        //end the transmission
  /*
  // Configure Accelerometer Sensitivity - Full Scale Range (default +/- 2g)
  Wire.beginTransmission(MPU);
  Wire.write(0x1C);                  //Talk to the ACCEL_CONFIG register (1C hex)
  Wire.write(0x10);                  //Set the register bits as 00010000 (+/- 8g full scale range)
  Wire.endTransmission(true);
  // Configure Gyro Sensitivity - Full Scale Range (default +/- 250deg/s)
  Wire.beginTransmission(MPU);
  Wire.write(0x1B);                   // Talk to the GYRO_CONFIG register (1B hex)
  Wire.write(0x10);                   // Set the register bits as 00010000 (1000deg/s full scale)
  Wire.endTransmission(true);
  delay(20);
  */
  // Call this function if you need to get the IMU error values for your module
  calculate_IMU_error();
  delay(20);

}

void loop() {
  // === Read acceleromter data === //
  Wire.beginTransmission(MPU);
  Wire.write(0x3B); // Start with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU, 6, true); // Read 6 registers total, each axis value is stored in 2 registers
  //For a range of +-2g, we need to divide the raw values by 16384, according to the datasheet
  AccX = (Wire.read() << 8 | Wire.read()) / 16384.0; // X-axis value
  AccY = (Wire.read() << 8 | Wire.read()) / 16384.0; // Y-axis value
  AccZ = (Wire.read() << 8 | Wire.read()) / 16384.0; // Z-axis value
  // Calculating Roll and Pitch from the accelerometer data
  accAngleX = (atan(AccY / sqrt(pow(AccX, 2) + pow(AccZ, 2))) * 180 / PI) - 0.58; // AccErrorX ~(0.58) See the calculate_IMU_error()custom function for more details
  accAngleY = (atan(-1 * AccX / sqrt(pow(AccY, 2) + pow(AccZ, 2))) * 180 / PI) + 1.58; // AccErrorY ~(-1.58)

  // === Read gyroscope data === //
  previousTime = currentTime;        // Previous time is stored before the actual time read
  currentTime = millis();            // Current time actual time read
  elapsedTime = (currentTime - previousTime) / 1000; // Divide by 1000 to get seconds
  Wire.beginTransmission(MPU);
  Wire.write(0x43); // Gyro data first register address 0x43
  Wire.endTransmission(false);
  Wire.requestFrom(MPU, 6, true); // Read 4 registers total, each axis value is stored in 2 registers
  GyroX = (Wire.read() << 8 | Wire.read()) / 131.0; // For a 250deg/s range we have to divide first the raw value by 131.0, according to the datasheet
  GyroY = (Wire.read() << 8 | Wire.read()) / 131.0;
  GyroZ = (Wire.read() << 8 | Wire.read()) / 131.0;
  // Correct the outputs with the calculated error values
  GyroX = GyroX + 0.56; // GyroErrorX ~(-0.56)
  GyroY = GyroY - 2; // GyroErrorY ~(2)
  GyroZ = GyroZ + 0.79; // GyroErrorZ ~ (-0.8)

  // Currently the raw values are in degrees per seconds, deg/s, so we need to multiply by sendonds (s) to get the angle in degrees
  gyroAngleX = gyroAngleX + GyroX * elapsedTime; // deg/s * s = deg
  gyroAngleY = gyroAngleY + GyroY * elapsedTime;
  yaw =  yaw + GyroZ * elapsedTime;

  // Complementary filter - combine acceleromter and gyro angle values
  roll = 0.96 * gyroAngleX + 0.04 * accAngleX;
  pitch = 0.96 * gyroAngleY + 0.04 * accAngleY;
  
  // Print the values on the serial monitor
  Serial.print(roll);
  Serial.print("/");
  Serial.print(pitch);
  Serial.print("/");
  Serial.println(yaw);
}


void calculate_IMU_error() {
  // We can call this funtion in the setup section to calculate the accelerometer and gyro data error. From here we will get the error values used in the above equations printed on the Serial Monitor.
  // Note that we should place the IMU flat in order to get the proper values, so that we then can the correct values
  // Read accelerometer values 200 times
  while (c < 200) {
    Wire.beginTransmission(MPU);
    Wire.write(0x3B);
    Wire.endTransmission(false);
    Wire.requestFrom(MPU, 6, true);
    AccX = (Wire.read() << 8 | Wire.read()) / 16384.0 ;
    AccY = (Wire.read() << 8 | Wire.read()) / 16384.0 ;
    AccZ = (Wire.read() << 8 | Wire.read()) / 16384.0 ;
    // Sum all readings
    AccErrorX = AccErrorX + ((atan((AccY) / sqrt(pow((AccX), 2) + pow((AccZ), 2))) * 180 / PI));
    AccErrorY = AccErrorY + ((atan(-1 * (AccX) / sqrt(pow((AccY), 2) + pow((AccZ), 2))) * 180 / PI));
    c++;
  }
  //Divide the sum by 200 to get the error value
  AccErrorX = AccErrorX / 200;
  AccErrorY = AccErrorY / 200;
  c = 0;
  // Read gyro values 200 times
  while (c < 200) {
    Wire.beginTransmission(MPU);
    Wire.write(0x43);
    Wire.endTransmission(false);
    Wire.requestFrom(MPU, 6, true);
    GyroX = Wire.read() << 8 | Wire.read();
    GyroY = Wire.read() << 8 | Wire.read();
    GyroZ = Wire.read() << 8 | Wire.read();
    // Sum all readings
    GyroErrorX = GyroErrorX + (GyroX / 131.0);
    GyroErrorY = GyroErrorY + (GyroY / 131.0);
    GyroErrorZ = GyroErrorZ + (GyroZ / 131.0);
    c++;
  }
  //Divide the sum by 200 to get the error value
  GyroErrorX = GyroErrorX / 200;
  GyroErrorY = GyroErrorY / 200;
  GyroErrorZ = GyroErrorZ / 200;
  // Print the error values on the Serial Monitor
  Serial.print("AccErrorX: ");
  Serial.println(AccErrorX);
  Serial.print("AccErrorY: ");
  Serial.println(AccErrorY);
  Serial.print("GyroErrorX: ");
  Serial.println(GyroErrorX);
  Serial.print("GyroErrorY: ");
  Serial.println(GyroErrorY);
  Serial.print("GyroErrorZ: ");
  Serial.println(GyroErrorZ);
}

Code Description: So first we need to include the Wire.h library which is used for the I2C communication and define some variables needed storing the data.

In the setup section, we need initialize the wire library and reset the sensor through the power management register. In order to do that we need to take a look at the datasheet of the sensor from where we can see the register address.

MPU6050 Power Management Register x6B

Also, if we want, we can select the Full-Scale Range for the accelerometer and the gyroscope using their configuration registers. For this example, we will use the default +- 2g range for the accelerometer and 250 degrees/s range for the gyroscope, so I will leave this part of the code commented.

// Configure Accelerometer Sensitivity - Full Scale Range (default +/- 2g)
  Wire.beginTransmission(MPU);
  Wire.write(0x1C);                  //Talk to the ACCEL_CONFIG register (1C hex)
  Wire.write(0x10);                  //Set the register bits as 00010000 (+/- 8g full scale range)
  Wire.endTransmission(true);
  // Configure Gyro Sensitivity - Full Scale Range (default +/- 250deg/s)
  Wire.beginTransmission(MPU);
  Wire.write(0x1B);                   // Talk to the GYRO_CONFIG register (1B hex)
  Wire.write(0x10);                   // Set the register bits as 00010000 (1000deg/s full scale)
  Wire.endTransmission(true);
  */

In the loop section we start by reading the accelerometer data. The data for each axis is stored in two bytes or registers and we can see the addresses of these registers from the datasheet of the sensor.

MPU6050 imu accelerometer data registers

In order to read them all, we start with the first register, and using the requiestFrom() function we request to read all 6 registers for the X, Y and Z axes. Then we read the data from each register, and because the outputs are twos complement, we combine them appropriately to get the correct values.

// === Read acceleromter data === //
  Wire.beginTransmission(MPU);
  Wire.write(0x3B); // Start with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU, 6, true); // Read 6 registers total, each axis value is stored in 2 registers
  //For a range of +-2g, we need to divide the raw values by 16384, according to the datasheet
  AccX = (Wire.read() << 8 | Wire.read()) / 16384.0; // X-axis value
  AccY = (Wire.read() << 8 | Wire.read()) / 16384.0; // Y-axis value
  AccZ = (Wire.read() << 8 | Wire.read()) / 16384.0; // Z-axis value

In order to get output values from -1g to +1g, suitable for calculating the angles, we divide the output with the previously selected sensitivity.

mpu6050 accelerometer sensitivity full scale range

Finally, using these two formulas, we calculate the roll and pitch angles from the accelerometer data.

// Calculating Roll and Pitch from the accelerometer data
  accAngleX = (atan(AccY / sqrt(pow(AccX, 2) + pow(AccZ, 2))) * 180 / PI) - 0.58; // AccErrorX ~(0.58) See the calculate_IMU_error()custom function for more details
  accAngleY = (atan(-1 * AccX / sqrt(pow(AccY, 2) + pow(AccZ, 2))) * 180 / PI) + 1.58; // AccErrorY ~(-1.58)

Next, using the same method we get the gyroscope data.

We read the six gyroscope registers, combine their data appropriately and divide it by the previously selected sensitivity in order to get the output in degrees per second.

// === Read gyroscope data === //
  previousTime = currentTime;        // Previous time is stored before the actual time read
  currentTime = millis();            // Current time actual time read
  elapsedTime = (currentTime - previousTime) / 1000; // Divide by 1000 to get seconds
  Wire.beginTransmission(MPU);
  Wire.write(0x43); // Gyro data first register address 0x43
  Wire.endTransmission(false);
  Wire.requestFrom(MPU, 6, true); // Read 4 registers total, each axis value is stored in 2 registers
  GyroX = (Wire.read() << 8 | Wire.read()) / 131.0; // For a 250deg/s range we have to divide first the raw value by 131.0, according to the datasheet
  GyroY = (Wire.read() << 8 | Wire.read()) / 131.0;
  GyroZ = (Wire.read() << 8 | Wire.read()) / 131.0;

Here you can notice that I correct the output values with some small calculated error values, which I will explain how we get them in a minute. So as the outputs are in degrees per second, now we need to multiply them with the time to get just degrees. The time value is captured before each reading iteration using the millis() function.

// Correct the outputs with the calculated error values
  GyroX = GyroX + 0.56; // GyroErrorX ~(-0.56)
  GyroY = GyroY - 2; // GyroErrorY ~(2)
  GyroZ = GyroZ + 0.79; // GyroErrorZ ~ (-0.8)

  // Currently the raw values are in degrees per seconds, deg/s, so we need to multiply by sendonds (s) to get the angle in degrees
  gyroAngleX = gyroAngleX + GyroX * elapsedTime; // deg/s * s = deg
  gyroAngleY = gyroAngleY + GyroY * elapsedTime;
  yaw =  yaw + GyroZ * elapsedTime;

Finally, we fuse the accelerometer and the gyroscope data using a complementary filter. Here, we take 96% of the gyroscope data because it is very accurate and doesn’t suffer from external forces. The down side of the gyroscope is that it drifts, or it introduces error in the output as the time goes on. Therefore, on the long term, we use the data from the accelerometer, 4% in this case, enough to eliminate the gyroscope drift error.

// Complementary filter - combine acceleromter and gyro angle values
  roll = 0.96 * gyroAngleX + 0.04 * accAngleX;
  pitch = 0.96 * gyroAngleY + 0.04 * accAngleY;

However, as we cannot calculate the Yaw from the accelerometer data, we cannot implement the complementary filter on it.

Before we take a look at the results, let me quickly explain how to get the error correction values.  For calculate these errors we can call the calculate_IMU_error() custom function while the sensor is in flat still position. Here we do 200 readings for all outputs, we sum them and divide them by 200. As we are holding the sensor in flat still position, the expected output values should be 0. So, with this calculation we can get the average error the sensor makes.

void calculate_IMU_error() {
  // We can call this funtion in the setup section to calculate the accelerometer and gyro data error. From here we will get the error values used in the above equations printed on the Serial Monitor.
  // Note that we should place the IMU flat in order to get the proper values, so that we then can the correct values
  // Read accelerometer values 200 times
  while (c < 200) {
    Wire.beginTransmission(MPU);
    Wire.write(0x3B);
    Wire.endTransmission(false);
    Wire.requestFrom(MPU, 6, true);
    AccX = (Wire.read() << 8 | Wire.read()) / 16384.0 ;
    AccY = (Wire.read() << 8 | Wire.read()) / 16384.0 ;
    AccZ = (Wire.read() << 8 | Wire.read()) / 16384.0 ;
    // Sum all readings
    AccErrorX = AccErrorX + ((atan((AccY) / sqrt(pow((AccX), 2) + pow((AccZ), 2))) * 180 / PI));
    AccErrorY = AccErrorY + ((atan(-1 * (AccX) / sqrt(pow((AccY), 2) + pow((AccZ), 2))) * 180 / PI));
    c++;
  }
  //Divide the sum by 200 to get the error value
  AccErrorX = AccErrorX / 200;
  AccErrorY = AccErrorY / 200;
  c = 0;
  // Read gyro values 200 times
  while (c < 200) {
    Wire.beginTransmission(MPU);
    Wire.write(0x43);
    Wire.endTransmission(false);
    Wire.requestFrom(MPU, 6, true);
    GyroX = Wire.read() << 8 | Wire.read();
    GyroY = Wire.read() << 8 | Wire.read();
    GyroZ = Wire.read() << 8 | Wire.read();
    // Sum all readings
    GyroErrorX = GyroErrorX + (GyroX / 131.0);
    GyroErrorY = GyroErrorY + (GyroY / 131.0);
    GyroErrorZ = GyroErrorZ + (GyroZ / 131.0);
    c++;
  }
  //Divide the sum by 200 to get the error value
  GyroErrorX = GyroErrorX / 200;
  GyroErrorY = GyroErrorY / 200;
  GyroErrorZ = GyroErrorZ / 200;
  // Print the error values on the Serial Monitor
  Serial.print("AccErrorX: ");
  Serial.println(AccErrorX);
  Serial.print("AccErrorY: ");
  Serial.println(AccErrorY);
  Serial.print("GyroErrorX: ");
  Serial.println(GyroErrorX);
  Serial.print("GyroErrorY: ");
  Serial.println(GyroErrorY);
  Serial.print("GyroErrorZ: ");
  Serial.println(GyroErrorZ);
}

We simply print the values on the serial monitor and once we know them, we can implement them in the code as shown earlier, for both the roll and pitch calculation, as well as for the 3 gyroscope outputs.

MPU6050 Pitch Roll and Yaw outputs

Finally, using the Serial.print function we can print the Roll, Pitch and Yaw values on the serial monitor and see whether the sensor works properly.

MPU6050 Orientation Tracking – 3D Visualization

Next, in order to make the 3D visualization example we just need accept this data the Arduino is sending through the serial port in the Processing development environment. Here’s the complete Processing code:

/*
    Arduino and MPU6050 IMU - 3D Visualization Example 
     by Dejan, https://howtomechatronics.com
*/

import processing.serial.*;
import java.awt.event.KeyEvent;
import java.io.IOException;

Serial myPort;

String data="";
float roll, pitch,yaw;

void setup() {
  size (2560, 1440, P3D);
  myPort = new Serial(this, "COM7", 19200); // starts the serial communication
  myPort.bufferUntil('\n');
}

void draw() {
  translate(width/2, height/2, 0);
  background(233);
  textSize(22);
  text("Roll: " + int(roll) + "     Pitch: " + int(pitch), -100, 265);

  // Rotate the object
  rotateX(radians(-pitch));
  rotateZ(radians(roll));
  rotateY(radians(yaw));
  
  // 3D 0bject
  textSize(30);  
  fill(0, 76, 153);
  box (386, 40, 200); // Draw box
  textSize(25);
  fill(255, 255, 255);
  text("www.HowToMechatronics.com", -183, 10, 101);

  //delay(10);
  //println("ypr:\t" + angleX + "\t" + angleY); // Print the values to check whether we are getting proper values
}

// Read data from the Serial Port
void serialEvent (Serial myPort) { 
  // reads the data from the Serial Port up to the character '.' and puts it into the String variable "data".
  data = myPort.readStringUntil('\n');

  // if you got any bytes other than the linefeed:
  if (data != null) {
    data = trim(data);
    // split the string at "/"
    String items[] = split(data, '/');
    if (items.length > 1) {

      //--- Roll,Pitch in degrees
      roll = float(items[0]);
      pitch = float(items[1]);
      yaw = float(items[2]);
    }
  }
}

Here we read the incoming data from the Arduino and put it into the appropriate Roll, Pitch and Yaw variables. In the main draw loop, we use these values to rotate the 3D object, in this case that’s a simple box with a particular color and text on it.

If we run the sketch, we can see how good the MPU6050 sensor is for tracking orientation. The 3D object tracks the orientation of the sensor quite accurate and it’s also very responsive.

MPU6050 orientation tracking - 3D visualization example

As I mentioned, the only down side is that the Yaw will drift over time because we cannot use the complementary filter for it. For improving this we need to use an additional sensor. That’s usually a magnetometer which can be used as a long-term correction for the gyroscope Yaw drift. However, the MPU6050 actually have a feature that’s called Digital Motion Processor which is used for onboard calculations of the data and it’s capable of eliminating the Yaw drift.

Absolute orientation sensors - MPU6050 BNO055

Here’s the same 3D example with the Digital Motion Processor in use. We can see how accurate the orientation tracking is now, without the Yaw drift. The onboard processor can also calculate and output Quaternions which are used for representing orientations and rotations of objects in three dimensions. In this example we are actually using quaternions for representing the orientation which also doesn’t suffer from Gimbal lock which occurs when using Euler angles.

3D object orientation with MPU6050 DMP feature

Nevertheless, getting this data from the sensor is a bit more complicated than what we explained earlier. First of all, we need to connect and additional wire to an Arduino digital pin. That’s an interrupt pin which is used for reading this data type from the MPU6050.

The code is also a bit more complicated so that’s why we are going to use the i2cdevlib library by Jeff Rowberg. This library can be downloaded from GitHub and I will include a link to in on the website article.

Once we install the library, we can open the MPU6050_DMP6 example from the library. This example is well explained with comments for each line.

Here we can select what kind of output we want, quaternions, Euler angles, yaw, pitch and roll, accelerations value or quaternions for the 3D visualization. This library also includes a Processing sketch for the 3D visualization example. I just modified it to get the box shape as in the previous example. Here’s the 3D visualization Processing code that works with the MPU6050_DPM6 example, for selected “OUTPUT_TEAPOT” output:

/*
    Arduino and MPU6050 IMU - 3D Visualization Example 
     by Dejan, https://howtomechatronics.com
*/

import processing.serial.*;
import java.awt.event.KeyEvent;
import java.io.IOException;

Serial myPort;

String data="";
float roll, pitch,yaw;

void setup() {
  size (2560, 1440, P3D);
  myPort = new Serial(this, "COM7", 19200); // starts the serial communication
  myPort.bufferUntil('\n');
}

void draw() {
  translate(width/2, height/2, 0);
  background(233);
  textSize(22);
  text("Roll: " + int(roll) + "     Pitch: " + int(pitch), -100, 265);

  // Rotate the object
  rotateX(radians(-pitch));
  rotateZ(radians(roll));
  rotateY(radians(yaw));
  
  // 3D 0bject
  textSize(30);  
  fill(0, 76, 153);
  box (386, 40, 200); // Draw box
  textSize(25);
  fill(255, 255, 255);
  text("www.HowToMechatronics.com", -183, 10, 101);

  //delay(10);
  //println("ypr:\t" + angleX + "\t" + angleY); // Print the values to check whether we are getting proper values
}

// Read data from the Serial Port
void serialEvent (Serial myPort) { 
  // reads the data from the Serial Port up to the character '.' and puts it into the String variable "data".
  data = myPort.readStringUntil('\n');

  // if you got any bytes other than the linefeed:
  if (data != null) {
    data = trim(data);
    // split the string at "/"
    String items[] = split(data, '/');
    if (items.length > 1) {

      //--- Roll,Pitch in degrees
      roll = float(items[0]);
      pitch = float(items[1]);
      yaw = float(items[2]);
    }
  }
}

So here using the serialEvent() function we receive the quaternions coming from the Arduino, and in the main draw loop we use them to rotate the 3D object. If we run the sketch, we can see how good quaternions are for rotating objects in three dimensions.

In order not to overload this tutorial, I placed the second example, the DIY Arduino Gimbal or Self-Stabilizing platform,  on a separate article.

 

Feel free to ask any question related to this tutorial in the comments section below and also don’t forget to check my collection of Arduino Projects.

The post Arduino and MPU6050 Accelerometer and Gyroscope Tutorial appeared first on HowToMechatronics.



from HowToMechatronics http://bit.ly/2Kq5xjU