Sunday, October 10, 2021

Arduino: Lesson 7 - Controlling LED Through Serial Monitor with Arduino

  

Fig 1 - Arduino: Lesson 7 - Controlling LED Through Serial Monitor with Arduino

Welcome to Lesson 7 - Basic Arduino Course

In today's lesson we will learn how to control the state of a LED via the Serial Monitor using the Arduino IDE.

We will use the Serial.readString() function which will cause the Arduino to interpret the sentence you have entered into the serial monitor, e.g. "Turn on the led". If you press ENTER Key in you computer, the LED will be turned on, if you want to turn off the LED just write the message "Turn off the LED".

With this method we can use it in different projects such as:

  • Load activation - Turns one or more loads on or off using commands.
  • Motor Speed Control - Use Serial Monitor to send the speed at which a PWM motor should run.
  • Calibrate a sensor's constant - We can create software to change a sensor's constant to a specified value if needed.

In our example today, we are using the serial monitor to trigger a LED, but you can also use a relay module to drive a motor, for example.

To do this, we will use the D9 digital port on Arduino. We can use any digital port we want. Just change the port you want to use in the declaration or the one that is available on your Arduino.

Required hardware

  • Arduino board
  • LED - Light Emitter Diode 220 Ohm Resistor - (red, red, brown, gold)
  • Jumper wires
  • Protoboard (optional)

The circuit

The circuit is quite simple. We connect a LED in series with a 220 ohm resistor to limit the current in the LED as we learned in previous lessons, and we connect the 9-port of the Arduino UNO as shown in Figure 2 below.

Fig. 2 - Controlling LED Through Serial Monitor with Arduino - tinkercad.com

We use a protoboard to facilitate the connections, but you can also connect the wires directly to the Arduino.

The code

The Serial.readString() function reads characters from the serial buffer and moves them to a given string.

In our example, we want to do something very simple, which is to turn on and off a LED using the command from Serial Monitor.

After building the circuit, connect your Arduino board to your computer, run the Arduino software (IDE), copy the code below and paste it into your Arduino IDE.

But first let us understand the code line by line.

  • In Line 3, we declared ledPin to digital Pin 9 where we connect the LED to the digital Pin 9
  • In Line 4, we declared the DataIn String that will receive the Serial Monitor Commands
  • In Line 6we enter the void setup() function. This function is read only once when the Arduino is started.
  • In Line 7, we begin serial communication by declaring the Serial.begin() function. At 115200 bits of data per second, this is the speed at which your computer will communicate with your Arduino Serial.
  • In Line 8, we define Port 9 as the output, using the pinMode(); function;
1
2
3
4
5
6
7
8
9
// Arduino: Lesson 7 - Controlling LED Through Serial Monitor with Arduino

int ledPin = 9;                                    // LED connected to digital pin 9
String DataIn;                                    // String that will receive the commands

void setup() {                                    // This function is called once when the program starts
Serial.begin(115200);                       // Begin the Serial Monitor with bounce rate in 115200
pinMode(ledPin, OUTPUT);            // Set the digital pin as output:
}
//------------------------------------- www.elcircuits.com --------------------------------------------
  • In Line 11, we enter in the void loop() function does precisely what its name suggests, and loops consecutively.
  • In Line 12, we enter in a if conditional, for to check if the Serial Monitor is available, if yes we call the next function.
  • In Line 13, we call the Serial.readString() function to read the characters from the Serial Monitor and send them to the String DataIn.

  • In Line 15we enter the if conditional, in this case to compare if the characters are the same as written in the Serial Monitor, in our example "turn led on", if yes...
  • In Line 16, we enter the digitalWrite function, command activates ledPin to HIGH level, it means that it goes from 0V to 5V, which turn the LED On.

  • In Line 17, we enter the if conditional, that compare if the characters are the same as written in the Serial Monitor, in our example "turn led off", if yes...
  • In Line 18, we enter the digitalWrite function, command desable ledPin to LOW level, it means that it goes from 5V to 0V, which turn the LED Off.
1
...
11
12
13
14
15
16
17
18
19
20
21
// Arduino: Lesson 7 - Controlling LED Through Serial Monitor with Arduino

void loop() { // The loop function runs over and over again as long as the Arduino has power
  if (Serial.available()) {                   // Check if there is any data on the serial monitor
    DataIn = Serial.readString();       // String DataIn receives the data typed in the Serial Monitor
  }
 if (DataIn == "turn led on") {          // Check if the received String is equal to "turn led on"  
    digitalWrite(ledPin, HIGH);         // If yes, the function digitalWrite turn Led ON
  } if (DataIn == "turn led off") {     // Check if the received String is equal to "turn led off" 
    digitalWrite(ledPin, LOW);         // If yes, the function digitalWrite turn Led OFF 
  }
}
//------------------------------------- www.elcircuits.com --------------------------------------------

B
elow you can see the full code, which we can be copying and pasting into your Arduino IDE, and uploading to Arduino.

The complete code is showed in the sketch below!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Arduino: Lesson 7 - Controlling LED Through Serial Monitor with Arduino

int ledPin = 9;                                    // LED connected to digital pin 9
String DataIn;                                    // String that will receive the commands

void setup() {                                    // This function is called once when the program starts  
Serial.begin(115200);                       //Begin the Serial Monitor with bounce rate in 115200
pinMode(ledPin, OUTPUT);            // Set the digital pin as output:
}

void loop() { // The loop function runs over and over again as long as the Arduino has power
  if (Serial.available()) {                   // Check if there is any data on the serial monitor
    DataIn = Serial.readString();       // String DataIn receives the data typed in the Serial Monitor
  }
 if (DataIn == "turn led on") {          // Check if the received String is equal to "turn led on"  
    digitalWrite(ledPin, HIGH);         // If yes, the function digitalWrite turn Led ON
  } if (DataIn == "turn led off") {     // Check if the received String is equal to "turn led off" 
    digitalWrite(ledPin, LOW);         // If yes, the function digitalWrite turn Led OFF 
  }
}
//------------------------------------- www.elcircuits.com --------------------------------------------

Next Lesson

Previous Lesson

If you have any questions, suggestions or corrections, please leave them in the comments and we will answer them soon.

Subscribe to our blog!!! Click here - elcircuits.com!!!

My Best Regards!!!

Friday, October 8, 2021

4 x 50W High Power Amplifier, 14.4V - IC TDA7563A + PCB

Fig 1. - PCB 4 x 50W High Power Amplifier, 14.4V - IC TDA7563A

Para versão em Português, Clique Aqui!!!

This is a 200W High Power Amplifier Circuit, and its great trump card is that it works with a simple power source and still at 14.4V, which means we can plug in a 12V car battery, or motorbike battery, or UPS battery, etc.

Also, the circuit is very easy to build as it requires very few external components.

The TDA7563A is a quad-bridge type amplifier of BCD technology in Flexiwatt27 and Power SO36 packages designed specifically for car radio applications.

Thanks to the DMOS output stage, the TDA7563A has very low distortion, which allows for clear and powerful sound. 

Features include its superior efficiency performance resulting from the unique internal system structure, making it the device best suited to simplify thermal management in high power packages.

This device is equipped with a complete diagnostic matrix that communicates the status of each speaker via the I2C bus.

You might also be interested in:

Features

  • Multiple Power BCD Technology
  • MOSFET output power stage
  • DMOS power output
  • New high efficiency technology (SB class)
  • High output power capacity 4x28W / 4Ω @ 14.4V, 1kHz, 10% THD, maximum power 4x50W
  • Maximum output power 4x72W / 2Ω
  • Complete conduction of I2C bus:
  • Standby
  • Front/rear independent, smoothed play/mute
  • Selectable 26dB / 12dB gain (for low noise line output function)
  • Enable / disable high efficiency
  • I2C bus digital diagnostics (including DC AC load detection)
  • Total failure protection
  • DC offset detection
  • Four independent short circuit protection
  • Cutting Detector Pin with Selectable Threshold (2% / 10%)
  • Standby/mute pin
  • Linear thermal shutdown with multiple thermal warnings
  • ESD protection

In Figure 2 below, you can see the schematic of the High Efficiency Power Amplifier. We can understand and analyze the simplicity of the circuit and see that it is an easy to assemble circuit with few external components.

Fig 2 - Schematic Diagram 4 x 50W High Power Amplifier, 14.4V - IC TDA7563A

Power Supply

This amplifier is powered by a single positive and negative voltage power supply and has a supply voltage range that varies with a minimum voltage of 8V and a maximum voltage of 18V

The typical working voltage with no load on the integrated circuit is 14.4V.

The power supply must have a current of at least 5 amps to be used in mono mode, when mounted in stereo version, "two channels", the current must be doubled, and it must also be provided with a good filtering to avoid a ripples system that can cause noise in the amplifier.

The working impedance value of this amplifier to reach its total power is 4 ohms, but we can also set it to 8 ohms, but then we will not get the maximum power from the amplifier.

Components List

  • CI1 ......................... Integrated Circuit TDA7563A
  • C1, C2, C3, C4 ...... 220nF Ceramic / Polyester Capacitors
  • C5 ........................... Capacitors 1uF / 63v
  • C6 ........................... Electrolytic Capacitor 10uF / 63v
  • R1 ........................... 47K Ohm resistors
  • R2 ........................... 8K2 ohm resistor
  • R3 ........................... Resistor 4K7 ohms
  • P1 to P9 .................. KF301 solderable 2-Pin Bolt-On Connector (Optional)
  • J1............................. 3 Ways 1x3 Weldable Male Pin Bar
  • Others ..................... Heatsink for IC, wires, connectors, PCI, tin etc.

We provide the files with the PCB, the schematic, the PDF, GERBER and JPG, PNG and provide a direct link for free download and a direct link, "MEGA".

Direct Download Link

Click on the link to download the files: Layout PCB, PDF, GERBER, JPG

If you have any questions, suggestions or corrections, please leave them in the comments and we will answer them soon.

Subscribe to our blog!!! Click here - Elcircuits.com!!!

My Best Regards!!!

Sunday, October 3, 2021

What is a Relay and How it Works?

Fig 1. - What is a Relay and How it Works?

What is a relay?

A relay is an electromagnetic switch used to turn a circuit on and off by a low-power electrical signal, or when multiple circuits need to be controlled by a single signal.

We know that most high-end devices for industrial applications require relays for their effective operation.

Relays are simple switches that are electrically and mechanically operated. Relays consist of an electromagnet and a series of contacts. The switching mechanism is carried out with the help of the electromagnet.

There are also other functional principles for their operation. However, they differ depending on the application.

Why use a Relay?

A relay is mainly used where only a low power signal can be used to control a circuit. It is also used when only one signal can be used to control many circuits.

The use of relays began with the invention of the telephone. They played an important role in exchanging calls in telephone exchanges. 

They were also used in long distance telegraphy. They were used to transmit the signal coming from one source to another destination.

After the invention of computers, they were also used for logical operations and other switching operations

The most demanding applications of relays are those that require high power to be activated such as electric motors, high current switches and so on. Such relays for these applications are called contactors.

Architecture of Relay

A relay consists of only five main components. These are:

  • Electromagnetic Coil 
  • Mobile Armature
  • NC, NA, COM Switching points
  • Magnetic core

In Figure 2 below, show the actual construction of a simple relay.

Fig.2 - Basic Architecture of the 5-pole Relay

It is an electromagnetic relay with a coil of wire surrounded by an iron core. A very low reluctance path for the magnetic flux is provided for the movable armature with the articulator and also for the switch point contacts NO, NC, COM.

The movable armature is connected to the yoke, which is mechanically connected to the switching point contacts. 

These parts are secured by means of a spring. The spring is used to create an air gap in the circuit when the relay is de-energized.

How does the relay work?

The function of the relay can be better understood by explaining the diagram in Figure 3 below. 

Fig. 3 - Relay schematic diagram 

The diagram shows an internal sectional view of a relay. A control coil as shown.

As soon as current flows through the coil, the electromagnet is energized and a magnetic field is created. 

Shortly thereafter, the upper contact arm is attracted by the lower fixed arm, closing the contacts, which causes the moving blade to switch from the normally closed "NC" circuit, to normally open "NO".

Immediately after the circuit is de-energized, the contact will move in the opposite way and make the NO circuit to the NC.

Once the coil current is switched off, the moving armature is returned to its initial position by a force. This force is almost equal to half the magnetic force.

Relays are manufactured mainly for two basic applications. One is the low voltage application and the other is the high voltage application. 

For low voltage applications, more emphasis is given to reduce the noise of the whole circuit. For high voltage applications, they are primarily designed to reduce a phenomenon called Arc Flash.

Relay Base

The base for all relays is the same. Take a look at the 5-pole relay shown in Figure 4 below. There are two colors shown. The yellow color represents the control circuit and the green color represents the load circuit. 

Fig. 4 - Relay Structural Diagram

A small control coil is connected to the control circuit. A switch is connected to the load. This switch is controlled by the coil in the control circuit. Now let us look at the various steps that take place in a relay.

Relay energized (ON)

As shown in Figure 4, a magnetic field is created when current flows through the coils represented by the yellow pins. 

This magnetic field causes the Mobile Armature to switch, completing the circuit between the terminals NO and COMMON.

De-energized relay (OFF)

As soon as the current flow through the coil pins ends, the strength of the magnetic field also ends and the Mobile Armature is set to its natural state by the spring force opposing the strength of the magnetic field and returns to its initial state by closing the NC and COMMON contacts again.

Simply put, when voltage is applied to the coil's current pins, the electromagnet is activated, creating a magnetic field that closes the pins NO and COMMON, creating a closed circuit between NO and COMMON

When no voltage is applied to the coil pin, there is no electromagnetic force and therefore no magnetic field. Therefore, the switches remain in their natural closed state NC and COMMON.

Switching poles

Relays have exactly the function of a switch. Therefore, the same concept is applied. A relay is said to switch one or more poles. Each pole has contacts that can be switched in three ways. They are:

Normally open contact [NO]

The NO contact is also called the manufacturer's contact. It closes the circuit when the relay is inactive or not energized, and breaks the circuit when the relay is active or energized.

Normally Closed contact [NC]

The NC contact is also referred to as the normally closed contact. It is the opposite of the NO contact. When the relay is energized, the NC circuit is broken. When the relay is deactivated, the NC circuit is reconnected.

Changeover Contacts (CC) / Double-throw [DT]

This type of contact is used to control two types of circuits. They are used to control both a NO contact and a NC contact with a common terminal. 

Depending on the type, they are called normally closed before normally open and normally open before normally closed.

Relays can be used to control multiple circuits by a single signal. A relay connects one or more poles, any of which can be actuated by energizing the coil.

Relays are also referred to by names such as.

Single Pole Single Throw [SPST]

The SPST relay has a total of four terminals. These two terminals can be connected or disconnected. The other two terminals are needed to connect the coil.

Single Double Pole Throw [SPDT]

The SPDT relay has a total of five terminals. Two of them are the coil terminals. There is also a common terminal that can be connected to one of the other two terminals.

Double Single Pole Throw [DPST]

The DPST relay has a total of six terminals. These terminals are divided into two pairs. This allows them to act as two SPSTs controlled by a single coil. Of the six terminals, two are coil terminals.

Double Double Pole Throw [DPDT]

The DPDT relay is the largest relay. It has mainly eight relay terminals. These two rows are designed to be interchangeable with terminals. They are designed to function like two SPDT relays controlled by a single coil.

Relay Applications

A relay circuit is used to perform logic functions. They play a very important role in providing critical safety logic.

Relays are used to provide time delay functions. They are used to delay and retard the closing of contacts.

Relays are used to control high voltage circuits using low voltage signals. Similarly, they are used to control high current circuits with the help of low current signals.

They are also used as protective relays. By this function, all faults can be detected and isolated during transmission and reception.

Overload Relay Application

Overload relay is an electromechanical device used to protect motors from overload and power failures. Overload relays are installed on motors to protect them from sudden current spikes that can damage the motor. 

An overload relay operates on the principle of current over time and is different from circuit breakers and fuses where a sudden trip occurs to shut down the motor.

The most commonly used overload relay is the thermal overload relay, which uses a bimetallic strip to shut down the motor. 

This range is set to make contact with a contactor and doubles in size as the temperature rises due to excessive current flow. The contact between the range and the contactor causes the contactor to de-energize and limit the power to the motor by shutting it down.

Another type of overload motor is the electronic type, which continuously monitors the motor current, while the thermal overload relay shuts down the motor based on the temperature rise/heating of the belt.

All commercially available overload relays have different specifications, the most important of which are actual range and response time. Most of them are designed to restart automatically when the motor is restarted.

Relay selection

When choosing a particular relay, you should consider a few factors. Are they:

Protection

  • Various protection measures such as contact protection and coil protection must be considered. Contact protection helps reduce arcing in circuits with inductors. Coil protection helps reduce the overvoltage that occurs during switching.

  • Look for a standard relay with all regulatory approvals.

  • Switching Time - Order high speed switching relays if you want one.

  • Ratings - There are current and voltage ratings. Current ratings range from a few amps to about 3,000 amps. For voltage ratings, they range from 300 volts AC to 600 volts AC. There are also high voltage relays with a voltage rating of about 15,000 volts.

If you have any questions, suggestions or corrections, please leave them in the comments and we will answer them soon.

Subscribe to our blog!!! Click here - Elcircuits.com!!!

My Best Regards!!!

Friday, October 1, 2021

Arduino: Lesson 6 - How to use Analog Output to fade an LED

Fig. 1 - Arduino: Lesson 6 - How to use analog output to fade an LED

Welcome to Lesson 6 - Basic Arduino Course

In today's lesson, we will learn how to use an analog output to increase and decrease the brightness of a LED. In this example, we will use the analogWrite() function, which triggers a PWM wave on an Arduino pin.

We will use PWM to vary the brightness of a LED as an example, but nothing prevents us from also using it to drive a motor and control its speed, the concept is the same.

The analogWrite() function triggers a square wave at the specified duty cycle until the next analogWrite() call.

The frequency of the PWM signal is around 490 Hz on most Arduinos, however on Arduino Uno and some similar boards, pins 5 and 6 use a frequency of about 980 Hz.

On most Arduino boards with ATmega168 or ATmega328 chips, this function works on pins 3, 5, 6, 9, 10 and 11. On the Arduino Mega this function works on pins 2 to 13 and 44 to 46.

Hardware Required

  • Arduino Board
  • LED
  • 200 ohms resistor
  • Jumper Wires
  • Protoboard (optional)

The Circuit

The circuit is quite simple, we connect a LED in series with a 220 ohm resistor used to limit the current in the LED as we learned in the previous lessons, and we connect the PWM 9 port of the Arduino UNO as shown in Figure 2 below.
Fig. 2 - Using an analog output to fade an LED - tinkercad.com

We use a Protoboard to facilitate the connections, but you can also connect the wires directly to the Arduino.

The Code

The analogWrite() function writes an analog value to the Arduino pin. It is important to remember that this output is not a pure analog output that we can use to generate a pure sine wave, but this output is a PWM wave control.

When we execute the call to the analogWrite() function, the pin will generate a constant square wave with the specified duty cycle until the next function call.

After building the circuit, connect your Arduino board to your computer, launch Arduino Software (IDE), copy the code below and paste it into your Arduino IDE. But first let us understand the code line by line. 

  • In Line 3, we declared ledPin to digital Pin 9 where we connect the LED to the digital Pin 9
  • In Line 5we enter the void setup() function. This function is read only once when the Arduino is started.
  • In Line 6, we define Port 9 as the output, using the pinMode(); function;

01
02
03
04
05
06
07
08
//Arduino: Lesson 6 - How to use Analog Output to fade an LED

int ledPin = 9;                                // LED connected to digital pin 9

void setup() {                                // This function is called once when the program starts
pinMode(ledPin, OUTPUT);        // Set the digital pin as output:

}
  • In Line 09, we enter in the loop() function does precisely what its name suggests, and loops consecutively.
  • In Line 11, the control structure For, is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop.

  • In Line 12, we run the analogWrite() function, this function writes an analog value (PWM wave) to pin 9, in this case we are increasing the PWM value from 5 to 5, to increase the LED brightness up to the maximum value of 255.
  • In Line 13, we use the function delay(); to wait for 30 milliseconds to see the dimming effect.

1
...
09
10
11
12
13
14
15
// Arduino: Lesson 6 - How to use Analog Output to fade an LED

void loop() { // The loop function runs over and over again forever
  
  for (int fadeValue = 0; fadeValue <= 255; fadeValue += 5 { // fade in from min to max in increments of 5 points:
   analogWrite(ledPin, fadeValue);          // sets the value (range from 0 to 255)
   delay(30);                                             // wait for 30 milliseconds to see the dimming effect
  } 
//------------------------------------- www.elcircuits.com --------------------------------------------
  • In Line 16, the control structure For, is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop.
  • In Line 17, we run the analogWrite() function, this function writes an analog value (PWM wave) to pin 9, in this case, we are decreasing the PWM value from 5 to 5, to decrease the LED brightness to the minimum value of 0.
  • In Line 18, we use the function delay(); to wait for 30 milliseconds to see the dimming effect.
1
...
16
17
18
19
20
21
// Arduino: Lesson 6 - How to use Analog Output to fade an LED

for (int fadeValue = 255; fadeValue >= 0; fadeValue -=5){ //fade out from max to min in increments of 5 points
   analogWrite(ledPin, fadeValue);           // sets the value (range from 255 to 0)
   delay(30);                                              // wait for 30 milliseconds to see the dimming effect
  }
}
//------------------------------------- www.elcircuits.com --------------------------------------------
Below you can see the full code, which we can be copying and pasting into your Arduino IDE, and uploading to Arduino.

The complete code is showed in the sketch below!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Arduino: Lesson 6 - How to use Analog Output to fade an LED

int ledPin = 9;                                          // LED connected to digital pin 9

void setup() {                                           // This function is called once when the program starts
  pinMode(ledPin, OUTPUT);                 // Set the digital pin as output:

}
void loop() { // The loop function runs over and over again forever
  
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {  // fade in from min to max in increments of 5 points:
   analogWrite(ledPin, fadeValue);           // sets the value (range from 0 to 255)
   delay(30);                                              // wait for 30 milliseconds to see the dimming effect
  } 

    for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {  // fade out from max to min in increments of 5 points:
   analogWrite(ledPin, fadeValue);           // sets the value (range from 0 to 255)
   delay(30);                                              // wait for 30 milliseconds to see the dimming effect
  }
}
//------------------------------------- www.elcircuits.com --------------------------------------------

Next Lesson

Previous Lesson

If you have any questions, suggestions or corrections, please leave them in the comments and we will answer them soon.

Subscribe to our blog!!! Click here - elcircuits.com!!!

My Best Regards!!!