Showing posts with label Learning. Show all posts
Showing posts with label Learning. Show all posts

Monday, August 30, 2021

Arduino: Lesson 3 - Blinking an LED with delay() function

Fig. 1 - Arduino: Lesson 3 - Blinking an LED with delay()

Welcome to Lesson 3 - Basic Arduino Course

Today we are going to learn how to make our first algorithm, let's learn how to use the blink() function, this function makes your Arduino blink an LED, every time determined in the programming.

Hardware Required

  • Arduino Board
  • LED - optional "You can use the onboard LED"
  • 220 ohm resistor - optional "You can use the onboard resistor"

The Circuit

You can use as an example the built-in LED that most Arduino boards have. This LED is connected to a digital pin 13, however, this number may vary from board type to board type. 

This constant is LED_BUILTIN and allows you to control the built-in LED easily, and the correspondence of this constant is digital pin 13.

However, you can to lit an external LED with this sketch, you  only need to build the circuit showing in Figure 2 below, you can connect one external LED in serie with the resistor to the digital PIN 6

Connect the positive leg of the LED (the positive leg, is the anode) to the other end of the resistor. Connect the negative leg of the LED (the negative leg,  is the cathode) to the GND

Fig. 2 - Arduino Blink LED with delay function - tinkercad.com

Resistor calculation

We need to use a resistor in series with the LED to limit the current in the LED. The value of this resistor depends on the LED we will use.

Considering that we will use an external green LED, let us analyze this situation by following the steps below:

  • The power supply comes from a digital pin on the Arduino (Vdc = 5v). 
  • The LED needs a current of 20mA to be powered. 
  • And a supply voltage of 2.5V.

You can see the voltage requirements of LED in the table in Figure 3 below, which contains the average voltage of most standard color LEDs.

Fig. 3 - Typical Led Voltage Range

Knowing that the LED power supply is 2.5V and 20mA (0.02A), following the table in Figure 3, let's put the data already obtained in the formula in Figure 4 below, and calculate:

Fig. 4 - Formula to calculate the resistance for the power supply of LED

Formula: 

R = (Vps - Vled) / Iled

R = (5 - 2,5)/(0.02)

R = 125

As we can see, the result of the calculation made resulted in a resistance of 125Ω. As 20mA is on average the threshold value of the LED, R = 125Ω will also be its threshold resistance so as not to damage the LED.

The resistor value in series with the LED can be a different value, it can be one of 150 ohms, or more, such as 220 ohms, 330 ohms; the LED will also light up with higher values but with less intensity.

The Code

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

  • First, in void setup() structure, digital pin 6 is initialized as output pin, as shown in line 4 below 
1
2
3
4
5
// Arduino: Lesson 3 - Blinking an LED with delay()

void setup() {                      // This function is called once when the program starts pinMode(6, OUTPUT); // initialize digital pin 6 as an output.
}
  • In the void loop() structure, in line 8, the digitalWrite function, command activates port 6 to HIGH level, it means that it goes from 0V to 5V, which makes the LED receive the voltage and lit up. 
  • In the line 9, the delay() instruction indicates that we will have 1000 milliseconds or 1 second to wait, and then enters the next step which is to turn the LED off.
1
...
7
8
9
10
// Arduino: Lesson 3 - Blinking an LED with delay()

void loop() { // The loop structure runs over and over again forever digitalWrite(6, HIGH); // initialize digital pin 6 as an output.
delay(1000);           // Wait for 1 second
...

  • In the line 12, the digitalWrite function, command activates port 6 to LOW level, it means that it goes from 5V to 0V, Then turn the LED off.
  • In the line 13, the delay() instruction indicates that we will have 1000 milliseconds or 1 second to wait, and then enters the next step which is to turn the LED off.
1
...
7
...
12
13
// Arduino: Lesson 3 - Blinking an LED with delay()

void loop() { // The loop structure runs over and over again forever
digitalWrite(6, LOW); // initialize digital pin 6 as an output.
delay(1000);           // Wait for 1 second
...

This brings the LED pin back to 0 volts, and turns the LED off. Enough time should pass between powering on and powering off, that's long enough to see the LED blink. 

Therefore, the delay() function tell the Arduino board to do nothing for 1000 milliseconds or 1 second. When you use the delay() function, nothing else happens for that amount of time. 

The complete code is showed in the sketch below.

1
2
3
4
5
6
7
8
9
10
11
12
// Arduino: Lesson 3 - Blinking an LED with delay()

void setup() {                     // This function is called once when the program starts pinMode(6, OUTPUT); // initialize digital pin 6 as an output.
}

void loop() { // The loop function runs over and over again forever
digitalWrite(6, HIGH); // Turn the LED ON (HIGH voltage level)
delay(1000);           // Wait for 1 second
digitalWrite(6, LOW); // Turn the LED OFF (LOW voltage level)
delay(1000);                 // Wait for 1 second
}
//------------------------------------- www.elcircuits.com --------------------------------------------

We can also use the same code, adding a name to pin 6 of the code above, simply assigning an integer to pin 6.

1
2
3
4
// Arduino: Lesson 3 - Blinking an LED with delay()

int ledPin =  6;      // the number of the LED pin

In this way, you will use pin 6 identification as ledPin, as we can see in the complete code below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Arduino: Lesson 3 - Blinking an LED with delay()

int ledPin 6;      // The number of the LED pin

void
setup() {                              // This function is called once when the program starts pinMode(ledPin, OUTPUT);
// initialize digital pin 6 "ledPin" as an output.
}

void loop() { // The loop function runs over and over again forever
digitalWrite(ledPin, HIGH); // Turn the LED ON (HIGH voltage level)
delay(1000);           // Wait for 1 second
digitalWrite(ledPin, LOW); // Turn the LED OFF (LOW voltage level)
delay(1000);                           // Wait for 1 second
}
//------------------------------------- www.elcircuits.com --------------------------------------------

This second code will work the same way, however when we have many "Pins" ports in a larger project, and we need to change the pin to another port, in this second code, you simply change line 3 of the code, which assigns port 6, the integer ledPin to another port you need.

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

Sunday, August 22, 2021

Arduino: Lesson 2 - How to Install Arduino Software (IDE) on Windows - Step by Step!


Fig. 1 - Arduino: Lesson 2 - How to Install Arduino Software (IDE) on Windows - Step by Step!

Welcome to Lesson 2 - Basic Arduino Course

Today we are going to explain how to install Arduino Software (IDE) on Windows machines step by step. Let's get started!

STEP 1: First, download the latest version of the software here.
First of all, let's download the Arduino IDE from the official website arduino.cc, it's recommended to  get the latest version from the clicking on Download Page

Fig. 2 - How to Install Arduino IDE - Download Page

You can choose between the Installer (.exe) and the Zip packages how showing in Figure 2. We suggest you use the first one that installs directly everything you need to use the Arduino Software (IDE), including the drivers. 
Note: With the Zip package you need to install the drivers manually. The Zip file is also useful if you want to create a portable installation.

STEP 2: When the download has been completed, open the installer file and proceed with the installation, allow the driver installation process when you get a warning from the operating system and accept the License Agreement, how to showing in Figure 3 below.

Fig. 3 - How to Install Arduino IDE - Agreement Page

STEP 3: Select the folder where you want to install Arduino IDE, how to showing in Figure 4 below.

Fig. 4 - How to Install Arduino IDE - Folder location Select Page

STEP 4Choose the components to install and select all the components including the board drivers, how showing in Figure 5.
 
Fig. 5 - How to Install Arduino IDE - Check components Page

STEP 5: In some cases, we may get a “Windows Security” windows, how to showing in Figure 6 below, to install devices software, simply click on button “Install“, and wait until the installation completes.

Fig. 6 - How to Install Arduino IDE - Security Device Page

STEP 6: The process will extract and install all the required files to execute properly the Arduino Software (IDE). When finished, click in "Close" button, and the installation is finished.

Fig. 7 - How to Install Arduino IDE - Installation Page

That's it, you've just successfully installed the Arduino IDE Software on your computer!

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, July 9, 2021

How to Read Ceramic and Polyester Capacitors Correctly

Fig. 1 - Various capacitors - how to read correctly


Due to many manufacturers and various norms and standards established nowadays, many acronyms are implemented in electronic components and use a wide variety of codes to describe their characteristics, which makes them difficult to read, there is an intrinsic coding to indicate the capacitors values, and manufacturers use different methods.

Sometimes generating a bit of confusion, some indications such as; tolerance and also the working supply voltage often aren't clearly written on them.

Will explain how to read the capacitors, identifying: microfarads (μF), nanofarards (nF), picofarads (pF), tolerance, voltage, and so on.

For values ​​equal greater than 1000nF (eg with aluminum or tantalum electrolytics), they mostly write the value on the body followed by the abbreviation for microfarad (μF).

For values ​​less than 1μF (1 microfarad), the issue is not so clear.
Generally, an encoding consisting of a three-digit number followed by a letter is used.

Before the most skeptics and purists come to question this Post, let us clarify that the correct abbreviation for microfarad is the Greek symbol; micro (μ). Which is a prefix of the International System of Units denoting a factor of 10−6 (one millionth).

Confirmed in 1960, the prefix comes from the Greek; μικρός (transliterated: mikros), meaning small. Followed by the capital letter F.

Usually when we're doing component descriptions, we don't always have the Greek symbols available on our keyboard, so to prevent this symbol from being wrongly transcribed, we substitute it for the lowercase letter "u", although we mustn't forget that we're always talking about the letter. "μ" (micro).

We have other cases, examples of this type, it is the symbol Ω (ohm) that is sometimes replaced by the letter "R" or, in some other cases nothing is written.

As mentioned at the beginning, with the exception of electrolytic capacitors that generally far exceed the value of 1 microfarad, the universe of capacitors used in electronics consists of capacitors with values ​​ranging from a few pF or picofarad (ceramic or disk capacitors look like lentils) to those close to 1 microfarad or 1μF (multi-layer polyester).

Before continuing, it is worth remembering "for whoever forgot" the subject of submultiples.

Submultiples

A pF (picofarad) is the smallest submultiple that exists to "practically" indicate capacity. I say practical because there are still smaller submultiples, SI Prefixes (International System of Units)

(deci, centi, milli, micro, nano, pico, femto, atto, zepto and yocto), but they are not used in electronics. 1 picofarad is 1,000,000 (1 million) times less than 1 microfarad (μF).

Halfway between picofarad and microfarad there is another sub-multiple called nanofarad widely used and it is 1000 times larger than 1 picofarad and 1000 times smaller than 1 microfarad.

Typical Capacitor Values

For capacitors facing between 1pF to 1μF (almost all capacitors except for electrolytic), reference values ​​are indicated with a three-digit number followed by a letter.

The first two digits indicate the starting number, while the third digit represents the number of zeros that must be added to the starting number to get the ending value. 

The result obtained is necessary to consider it in picofarad.

Examples of encodings

Let's use it as an example; 4 types of captions written on the capacitors, as shown in Figure 3 below.

In the capacitor in Figure 2, we can see in the description only a set of three numbers "104", which representing the capacitance in Picofarad reading.

Figure 2 - Capacitor with only capacitance captions



104 - Which is its capacitance in pF, and without any further information.





The capacitor in Figure 3, we can see in the description the set of 3 numbers "400" which representing the working voltage, followed by the letter "V", which is the working voltage indication, and the set of three numbers below "104", which represents the reading in Picofarad.

Figure 3 - Capacitor with voltage and
capacitance value captions


400V - Which is the working voltage.

104 - What is its value in pF






The capacitor in Figure 4, we can see in the description the set of 3 numbers "104", which represents the reading in Picofarad, followed by the letter "J", representing Tolerance, and the set of three numbers "250" represent the working voltage followed by the letter "V", which is the working voltage indication.

Figure 4 - Capacitor with capacitance, tolerance,
voltage captions 


104 - What is your capacitance in pF

J - It's the tolerance

250V - Is the working voltage.





The capacitor in Figure 5, we can see that in the description it starts with a number and a letter "2A" which represents the value of the maximum working voltage, then the set of 3 numbers "104", which represents the reading in Picofarad, followed by the letter "J" representing Tolerance.

Figure 5 - Capacitor with maximum voltage,
capacitance, tolerance 


2A - Which is the value of your maximum voltage

104 - What is your capacitance in pF

J - It's your tolerance





Let's Practice:

Let's say you have a capacitor with the nomenclature written "472", just as we take resistor readings, the third capacitor digit is also the multiplier, which means it would be: 47 + 2 zeros, which means 4700 pF (picofarad).

So if we exceed 1000 picofarad, we can use Sub-multiples, "like we do with meters/kilometers". As already clarified above that:

1μF = 1000nF
1nF = 1000pF

So, we can say that our 4700pF capacitor is 4.7nF.

In this case, it is not convenient to use the micro unit because the value would not be easy to read (0.0047μF).

With larger values, such as used capacitor filters number 104, that is, 10 + 4 = 100,000 pF or also 100nF, it is common for manufacturers to use the nomenclatures written on the capacitor body 0.1μF or .1μf (point one μF) .

Practical reading of the Polyester Capacitor

100nF Capacitor, tolerance of  ± 5% and maximum working voltage of 100V, Figure 5 above.

In this capacitor we have 6 alphanumeric digits, 2A104J.

  • The first two initial 2A digits refer to Maximum Voltage, we can use the complete EIA table codes that indicate the maximum capacitors work voltages in direct voltage (DC).

EIA Table of Code Indicators of Working Voltages of a Capacitor

0G = 4VDC0L = 5.5VDC0J = 6.3VDC
1A = 10VDC1C = 16VDC1E = 25VDC
1H = 50VDC1J = 63VDC1K = 80VDC
2A = 100VDC2Q = 110VDC2B = 125VDC
2C = 160VDC2Z = 180VDC2D = 200VDC
2P = 220VDC2E = 250VDC2F = 315VDC
2V = 350VDC2G = 400VDC2W = 450VDC
2H = 500VDC2J = 630VDC3A = 1000VDC

  • The next three digits refer to its capacitance, in the case as already exemplified 104 = 10 + 4 zeros, which is equal to 100,000pF = 100nF.

  • The last digit is the Letter "J", right after the three digits, determines the tolerance of the component.

    It is interesting to note the fact that some letters correspond to "asymmetric tolerances", such as "P", that is, the component may have a capacity greater than indicated, but not less.

    This type of tolerance is used with "filter" capacitors, where a value possibly higher than indicated does not minimize circuit operation, as we can see in the EIA table below.

EIA Table of Code Working Tolerance Indicators of a Capacitor

  • B = ± 0.10pF
  • C = ± 0.25pF
  • D = ± 0.5pF
  • E = ± 0.5%
  • F = ± 1%
  • G = ± 2%
  • H = ± 3%
  • J = ± 5%
  • K = ± 10%
  • M = ± 20%
  • N = ± 30%
  • P = ± +100%, - 0%
  • Z = ± +80%, - 20%
In the vast majority of cases, it may be useful to know the exact maximum voltage the capacitor can withstand without bursting or damaging its internal properties.

As we know, a capacitor is made up of a series of metal plates insulated from each other. This insulating material is very subtle, especially in the case of high-value capacitors. 

On the other hand, if the voltage is too high, there is a risk that an electrical arc will pass through the electrical insulation between the plates, breaking it and shorting the capacitor.

For this reason, the insulating material used is designed to work up to a certain maximum voltage level, so let's look at these capacitor voltages.

Dimensions of a Voltage-Based Capacitor

Often the maximum working voltage can be found clearly written, especially on capacitors designed to work with high voltages, other times the voltage value is not directly indicated.

It often happens with capacitors used in low voltage circuits. These capacitors support voltages between 50V and 100V, well above the typical working voltages of 5V, 12V, 18V, 24V, 48V.

A super important tip when designing or analyzing a circuit and not knowing for sure the capacitor working voltage, is to take into account the size, which in this case "size is important", as we cannot work with the structure of a capacitor. 

A high voltage and small size, of course there are exceptions, tantalum capacitors are altogether quite small compared to their capacitance, but as I said, "compared to their capacitance, not their voltage".

Last but not least, there is a numeric encoding used by some manufacturers which consists of a number followed by a letter. In the table of tolerances we can see the maximum working voltages.

As with everything related to technology, nothing is absolute and therefore a component manufacturer always appears, which uses systems to indicate values ​​different from those we describe. In any case, in general terms, this article's description fits very well (sometimes with slight variations) to most commercial capacitors nowadays.

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, May 24, 2021

Arduino: Lesson 1 - What is Arduino?

Fig. 1 - Arduino: Lesson 1 - What is Arduino?


Arduino is an open source electronic prototyping platform or board used for the development of IoT control and automation projects in Digital / Analog Electronics.

Originally started as a research project by Massimo Banzi, David Cuartielles, Tom Igoe, Gianluca Martino and David Mellis at the Ivrea Interaction Design Institute in the early 2000s, it is based on the Processing project, a language for learning to code within the context of the visual arts developed by Casey Reas and Ben Fry, as well as a thesis project by Hernando Barragan on the spinning board. 

Source: Arduino.cc

It consists of a programmable physical circuit board (Microcontroller) and software, or IDE (Integrated Development Environment), used to write and Upload Computer Code to the physical board, and was designed to make Electronics more accessible to Designers, Engineers, Technicians, Enthusiasts and people interested in creating interactive objects or environments.

The first Arduino board was launched in 2005 to help design students, who had no previous experience in electronics or microcontroller programming, to create working prototypes connecting the physical world to the digital world.

Since then, it has become the most popular electronic prototyping tool used by engineers and even large corporations.

An Arduino board can be purchased pre-assembled or, because the hardware design is Open Source, it can be built manually, however, users can adapt the boards according to their needs, as well as update or develop their own versions.

The Arduino platform has become quite popular with people who are starting out with electronics and for a very good reason.

Unlike most previous programmable circuit boards, the Arduino doesn't need separate hardware (called a Programmer, USB Serial Converter, FTDI) to load a new code on the board, you can simply use a USB cable.

In addition, the Arduino IDE uses a simplified version of C ++, making it easy to learn the program. Finally, the Arduino provides a standard form factor that divides the microcontroller functions into a more affordable package.
Fig. 2 - Arduino Uno Board Specification

The Arduino Uno is one of the most popular boards in the Arduino family and a great option for beginners.

Believe it or not, 10 lines of code are all you need to blink the On-board LED on your Arduino

What he does?

Arduino's Hardware and Software was designed for Engineers, technicians, designers, artists, enthusiasts, amateurs, hackers and anyone interested in creating interactive objects or environments.

The Arduino can interact with Buttons, LEDs, Motors, Speakers, GPS Units, Cameras, the Internet and even your Smartphone or TV.

This flexibility combined with the fact that the Arduino software is Open Source, that is, free, the hardware cards are very cheap and both the software and the hardware are easy to learn, leading to a large community of users who contributed code and launched instructions for a huge variety of Arduino-based Projects.

We can use Arduino for just about everything, from robots, heating blanket with temperature limit, machines to count bills, robot arms, etc. The Arduino can be used as the brain behind almost any electronics project.

The Arduino Family

There are different types of Arduino board, each with different capacities. In addition, some of the open source hardware means that others can modify and produce Arduino board derivatives that provide even more form and functionality factors.

If you are not sure which one is right for your project. Here are some options that are suitable for someone new to the Arduino's world:

Arduino Uno (R3)

Arduino Uno is a great option for your first Arduino. It has everything you need to get started and use it for your projects. Here you will find the technical specifications for the Arduino UNO R3:
  • Microcontroller: ATmega328P
  • Digital I/O Pins: 14
  • Analog input pins: 6
  • PWM pins: 6
  • Communication
    • UART
    • I2C
    • SPI
A USB connection, a power connector, a reset button and much more. It contains everything needed to support the microcontroller; Simply connect it to a computer with a USB cable or connect it to a DC power supply or battery to get started.

Sensors

With some simple code, the Arduino can control and interact with a wide variety of sensors - things that can measure light, temperature, degree of flexion, pressure, proximity, acceleration, carbon monoxide, radioactivity, humidity, barometric pressure, voltage, current, among so many others.

Shields

In addition, there are these things called Shields, basically they are pre-assembled circuit boards that fit on top of your Arduino and provide additional features - controlling engines, connecting to the Internet, providing cell phones or other wireless communication, controlling an LCD display and more.

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