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!!!

Monday, September 20, 2021

How to Wiring the Neutrik Combined Connector

Fig. 1 - Schematic XLR / P10 Neutrik NCJ6FI-S Female Combined Plug Connection


Today we will give you a concise explanation of how to wire the Neutrik XLR/P10 NCJ6FI-S Combined Female connector.

This type of female connector supports two types of connectors, the connector XLR, known as "Plug Canon", which is used to connect microphones and mixers.

And the TRS (Tip-Ring-Sleeve. Tip-Ring-Cover) plug for stereo, and for mono, TS (Tip-Sleeve. Tip-Cover), the old and known as; Banana Plug, or P10, are the ones used in musical instruments, guitar, keyboard, bass, etc...

And in Figure 2 below, you can see the front and back of the XLR/P10 Female NCJ6FI-S Neutrik Combination Connector. Its structure is made of solid plastic and its connectors are located on the back of the plug.
Fig. 2 - Conector Neutrik NCJ6FI-S

You might also be interested in:

Arrangement of the pins on the Neutrik connector

There are 4 models for this type of Neutrik connector, differing in the number of pins. We will deal with all models, but the one we will use today is the most common one found on the market.

For this connector model, we have the pinout in Figure 3 below. There are 7 Contact Pins, each of which is shown with its initials, both for the TRS "P10" input, 3 pins, and for the XLR "Canon" input, 4 pins.
We begin by understanding the type of connection we will be making.
Fig. 3 - Schematic Diagram Neutrik XLR/P10 Connection

Connecting to the TRS connector

If you need to use the channels of Neutrik Female Plug separately, we have arranged the connections separately to make it easier to understand the application of the type of configuration you will be putting together. For connections using only the TRS input, we have provided the schematic diagram in Figure 4 below:
Fig. 4 - Schematic Diagram of Connection with P10 Input Connector

For connections using only the XLR input, the so-called "Plug Canon", you will find a schematic diagram in figure 5 below:
Fig. 5 - Schematic diagram of the connection with the XLR input connector.
Having understood these two configurations, it is easy to understand how to prepare a Female Neutrik Connector with the configuration of the two connected in parallel, that is, the Combined Neutrik Connector. 

This "Obvious" setting is the most commonly used. The connections using the XLR and TRS inputs are arranged in the schematic diagram in Figure 6 below:
Fig. 6 - Diagrama esquemático ligação Conector Combinado, Entrada XLR/P10


The connectors are basically a combination of the P10 connectors and the XLR connectors. You just need to "jump" the pins as shown in the table below:
  • 1 of the XLR with pin S of the TRS 
  • 2 of the XLR with pin T of the TRS 
  • 3 of the XLR with pin R of the TRS.
These numbers and these letters are arranged on the back of the Neutrik connector, and to make it easier for those who do not have much experience with these connectors, acronyms, etc. In Figures 7 and 8 you will find, one by one, the illustrations of the connectors to be connected to the P10 plugs, stereo and mono.

Pin arrangement Combined Neutrik with P10 TRS connector - Stereo Version:

Fig. 7 - Schematic diagram of the Combined Connector connection, P10 TRS input.

Arrangement of pins Combined Neutrik with P10 TS connector - Mono Version:

Fig. 8 - Schematic diagram of Combined Connector connection, P10 TS Mono Input

Main features of the Neutrik NCJ6FI-S connector

  • Combined XLR and TRS connector socket
  • Slim "front-end" design
  • Saves rack space by combining 2 connectors in a single housing
  • Horizontal or vertical PCB mounting or rigid wire soldering
  • Fully standardized
  • Stereo or mono version
  • Very low line capacitance, therefore also suitable for digital audio
  • Mounting: Self-tapping plastic and threaded screws of configuration 2.9 x 1.06 and tri-ondular (screw A)
Below is a table detailing the features of the NCJ6FI-S Female Connector, which can be purchased from the product manufacturer.


Product
TitleNCJ6FI-S
Connection typeDoble XLR / P10
Genrefemale
Electrical Characteristics 
Resistance of Contacts < 10 mΩ (XLR)
Resistance of Contacts < 20 mΩ (Plug)
Dielectric Capacity 1,5 kVdc
Insulation Resistance > 10 GΩ (initial)
Rated current per contact 7,5 A (XLR)
Rated current per contact 7,5 A (Plug)
Rated Voltage < 50 V
Mechanical Characteristics
Insertion Force≤ 25 N
Withdrawal force≤ 25 N
Lifetime> 1000 Placement/Removal Cycles
Panel Thicknessmax. 7 mm 0.27"
Wire SizeS/T
Assembly DirectionBack Part
Material
Contact Plating0.2 µm Ao ligation on 2 µm Knot
ContactsBronze (CuSn6)
InsertionPolyamide (PA 6.6 30% GR)
Locking ElementIron Ck67
Environmental
Temperature Range-30 °C to +80 °C

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, September 19, 2021

Arduino: Lesson 5 - Reading Potentiometer and Showing Values On Serial Monitor

Fig. 1 - Arduino Lesson 5 - Reading Potentiometer and Showing Values On Serial Monitor

Welcome to Lesson 5 - Basic Arduino Course

Today we are going to learn how to read a Potentiometer end showing the Values on Serial Monitor.
In this example, we will use a potentiometer, however, this same concept is used for most analog sensors. 

What will differentiate will be the type of calculation used, with reference to each sensor.

We will use the analogRead() function, to read A0 PIN, in Arduino we have 6 Analog Ports, which goes from A0 to A5, so we can make readings from up to 6 sensors simultaneously without having to use external hardware.

Hardware Required

  • Arduino Board
  • A 10K Potentiometer
  • Wires
  • Protoboard (optional)

The Circuit

The potentiometer works like a voltage divider. When you turn the shaft of the potentiometer, you change the resistance on either side of the center pin (or wiper) of the potentiometer. 

This changes the relative resistances between the center pin and the two outer pins, so you get a different voltage at the analog input. 

When the shaft is fully rotated in one direction, there is no resistance between the center pin and the pin connected to ground.
The middle pin varies from 0Kohms to 10Kohms, which is the value of the potentiometer we will use.

This resistance is sensed by the voltages at the ends of the potentiometer, causing the center pin to vary between 0V and 5V

And the voltage variation that comes from the Center Pin of the potentiometer goes to the A0 Analog Port.

In Figure 2, you can see the schematic of the potentiometer and the Arduino. We use a breadboard to make the connections easier, but you can also connect the wires directly from the A0 terminal in the middle of the potentiometer, connecting the outer pin to 5V positive and the outer pin to the negative GND of the Arduino.

Fig. 2 - Reading Potentiometer and Showing Values On Serial Monitor - tinkercad.com

The Code

The analogRead() function converts the input voltage range, 0 to 5 volts, to a digital value between 0 and 1023. This is done by a circuit within the microcontroller called analog-to-digital converter, or ADC.

Then, if the voltage at the center pin is 0 volts, analogRead() returns 0. When the shaft is turned all the way the other way, there is no resistance between the middle pin and the pin connected to 5 volts

If the voltage on the middle pin is then 5 voltsanalogRead() returns 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the voltage applied to the pin.

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 variable sensorPin which is set to Analog Pin A0 where we receive the value of the connected potentiometer. 
  • In Line 4, we create a variable senorPin that stores the value of the sensor that we also use for the potentiometer.

01
02
03
04
05
// Arduino: Lesson 5 -  Reading Potentiometer and Showing Values On Serial Monitor

int sensorPin = A0           // Read the Analogic Pin A0 Values  into a variable
int sensorValue = 0;          // Variable to store the value coming from the sensor "Potentiometer"

  • In Line 6, we 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 9600 bits of data per second, this is the speed at which your computer will communicate with your Arduino Serial.
01
...
06
07
08
09
// Arduino: Lesson 5 -  Reading Potentiometer and Showing Values On Serial Monitor

void setup() {                      // This function is called once when the program starts
Serial.begin(9600);  // Begin the Serial Monitor with bounce rate in 115200
}

  • After setting the initializations, in Line 10 we will enter the void loop() function.

  • In Line 11, we use the variable sensorValue to store the resistance value, which is between 0 and 10K (read by the Arduino as a value between 0 and 1023) and controlled by the potentiometer.

  • In Line 13, we use the command Serial.println(), it is print out the value controlled by the potentiometer, this value will read with value between 0 and 1023 in your Serial Monitor.

  • In Line 14, we run the delay() function, for greater system stability.

1
...
10
11
12
13
14
15
16
17
// Arduino: Lesson 5 -  Reading Potentiometer and Showing Values On Serial Monitor

void loop() { // The loop function runs over and over again forever
sensorValue = analogRead (sensorPin);      // Read the input on analog pin A0

 Serial.println(sensorValue);                       // Print out the value you read
   delay(1);                                                   // delay in between reads for stability
}

//------------------------------------- www.elcircuits.com --------------------------------------------
Now you can copy the code and upload it to your Arduino. After that, if you open your Serial Monitor in Arduino Software (IDE) (by clicking on the icon that looks like a lens on the right side of the green top bar or using the keyboard shortcut Ctrl+Shift+M), you should see a steady stream of numbers in the range 0-1023 that correlate with the position of the pot. When you turn your potentiometer, these numbers respond almost instantly.

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
// Arduino: Lesson 5 -  Reading Potentiometer and Showing Values On Serial Monitor

int sensorPin = A0       // Read the Analogic Pin A0 Values  into a variable
int sensorValue = 0;       // Variable to store the value coming from the sensor "Potentiometer"

void setup() {                     // This function is called once when the program starts
Serial.begin(9600); // Start serial connection
}
 
void loop() { // The loop function runs over and over again forever
sensorValue = analogRead (sensorPin);      // Read the input on analog pin A0
 
   Serial.println(sensorValue);                     // Print out the value you read
   delay(1);                                                   // delay in between reads for stability
}
//------------------------------------- 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!!!

Tuesday, September 7, 2021

Simple 12V battery charger with automatic charging indicator + PCB

PCB - Simple 12V battery charger with automatic charging indicator

Para versão em Português, click aqui!

This is a Smart Battery Charger, with fully automatic 12V battery charge indicator. It is an extremely simple charger that anyone with little experience can assemble.

The input voltage depends on the power supply you are using, 110Vac or 220Vac. The charging time depends on the power supply you are using and the type of battery you are charging.

To calculate the closest charging time, we can do a simple and objective quick calculation that does not take into account the variations of the resistance factors of the battery, the variations of the charger, the chemical depreciation factor of the battery and so on.

You may be interested in: 

The calculation is quite simple. Let us take an example: you have a UPS 12 volt battery with 7 amps, your power supply is 3 amps

So we know that the battery charge is "more or less" 7 Amps Hour, which means that to fully charge the battery, 7 constant amps are required. Since the power supply is 3 amps, we need to divide 7 amps by 3 amps of power supply.

To charge a battery without damaging it usually requires a current of 10% and a maximum of 20% of its current. For example:

If our battery is 7 amps, the most we need is a 1.4 amp charger, and normal charging consumption is 700 milliamps. This 10% is normally used in devices that are directly connected to the power, such as alarm systems, backup devices and others.

Let's do the calculations using the formula

  • B = battery
  • PS = power supply
  • C = current

C = B / PS

C = 7/3 C = 2.33

Meaning:

Charge "C" lasts 2:33 hours

Two hours and thirty-three minutes to charge

If your PS is different, no problem, look at its supply current and put in the formula to see the approximate result.

Figure 2 shows the complete electrical schematic of the small circuit.

Fig. 2 - Electronic Schematic Simple 12V Automatic Battery Charger

It is important that the power supply delivers 20% more than the battery voltage, e.g. if your battery is 12 V, the power supply must be 14,4 V. You can vary a little, e.g. 13.2 V, "which is 10% of the battery voltage", but you cannot use a 12 V power supply to charge a 12 V battery as there will be no potential difference.

Here is how to use the charger:

When all the assembly is done, carefully check for wrong parts, reverse polarity diodes and shorts in the terminals after checking everything.

Connect the positive terminal of the power supply to the input of the +Vcc circuit and the negative terminal of the power supply to the ground circuit of the charger. 

With the potentiometer or trimpot you can regulate the output voltage of the charger, for example you have a 12V battery, normally 12V batteries UPS are charged at 13.2V at 14.4 volts.

Then use a multimeter on the DC volt scale, "it depends on the multimeter", on the output of the charger and set the voltage to the most desired, ie the maximum voltage for it to fire and the green LED will light up.

You can now use your new charger, insert the battery and let it charge until the charger reaches the voltage you set, "limit voltage", it will trigger the relay and turn on the green LED, indicating that the battery has been charged.

A good tip: If you have a spare 12v buzzer, or if you really want to add an audible indicator to your circuit, you can connect these buzzers, which you can easily find in electronics stores and are cheap, to the output where the green LED is lit, which is the full charge indicator, and you can turn on the positive buzzer on the relay output and the negative buzzer directly on the output.

Material List:

  • Q1..................... General purpose NPN transistor, C1815, BC548 etc.
  • D1, D2, D3 ...... Diodes 1N4001.
  • R1 ..................... Resistor 1/8W 10K (Brown, Black, Orange)
  • R2 ..................... Resistor 1/8W 100 Ohms (Brown, Black, Brown)
  • R3 ..................... Resistor 1/8W 1K2 (Brown, Red, Red)
  • VR1 ................. 10K Trimmpot or Potentiometer
  • P1, P2 ............... KF301 2 Pin 5.08mm Pitch Plug-in Screw Terminal Block Connector 
  • RL1 ................... Relay 12V 10A, 5 pins
  • LED1, LED2 .... 3mm LEDs, one Red and one Green
  • Others ............... Printed circuit board, soldering iron, tin, wire, etc.
We offer for download the necessary materials for those who want to assemble with PCI - Printed Circuit Board, the files in PNG, PDF and GERBER files for those who want to send for printing.

Download:


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!!!

Monday, September 6, 2021

1W Amplifier for Stereo Headphone using TDA2822 IC + PCB

Fig. 3 - PCB - 1W Amplifier for Stereo Headphone with IC TDA2822M

Simple headphone amplifier with few external components that is easy and inexpensive to assemble. This IC is designed for amplifying portable devices such as CD players, portable radios, small speakers, etc.

First of all, we will use it to amplify the audio signal for headphones, that is, we will build a headphone amplifier, whether to listen to music from a mobile phone, connect instruments to study, such as electric guitar, bass guitar, ukulele, guitar, or any other audio signal that needs to be amplified. 

You might also be interested in:

The main component is the TDA2822, a monolithic integrated circuit in an 8-pin lead  Mini-dip package. It is intended for use as a dual audio power amplifier in portable audios.

FEATURES

  • Dual Low-voltage power amplifier 
  • Supply voltage down to 1.8V 
  • Low crossover distortion                                
  • Low quiescent current z Bridge or stereo configuration
The maximum input voltage of this IC is 15V DC, so do not apply more than 15V to the IC. The circuit volume can be adjusted using a 47K doble potentiometer is used in the circuit.

The schematic diagram circuit of the 1W audio Amplifier for Stereo Headphone with IC TDA2822M  is shown in Figure 2 below.

Fig. 2 - 1W Amplifier for Stereo Headphone with IC TDA2822M

Material List

  • IC1 .................. Integrated Circuits TDA2822M
  • R1, R2 ............ 1/4W / 4.7Ω Resistor 
  • C1, C2 ............ 1uF - 25V Electrolytic capacitor 
  • C3, C4, C5 ..... 100uF - 25V Electrolytic Capacitor 
  • C6, C7 ............ 0.1uF Polyester capacitor
  • J1, J2 .............. 3.5mm Audio Female Jack Connector 
  • VR1 ................ 47KΩ  Double Potentiometer
  • P1 ................... Connector 2 screw terminal 5mm 2 Pins
  • Others ............ Wires, Solders, pcb, etc.

We offer for download the necessary materials for those who want to assemble with PCI - Printed Circuit Board, the files in PNG, PDF and GERBER files for those who want to send for printing.

Download:


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!!!