fbpx

How To Use An Arduino – Beginners Guide (2022)

DIY electronics

The Arduino UNO is one of the most popular microcontrollers in the world and for good reason. 

The Arduino structure and platform is simple enough for beginners to learn and powerful enough for experts to create cool robotics projects. 

 
If you are interested in building an Arduino RC car, how to build your own Arduino robot kit or even just how to make robots at home, we’ll provide you with the fundamentals that you will need to know to do it.

Currently, you may have thoughts like “what is Arduino C++”, are analog signals continuous”, how to use an Arduino” and “what is a PWM signal”. 

Don’t worry, in this article, we will guide you through all the essentials that beginners tend to overlook to help you become an Arduino master in no time. 

What is DC and AC Power?

You have probably seen the terms AC and DC before, but might not know what they actually mean. DC stands for Direct Current and AC stands for Alternating Current.
Direct Current, as its name suggests, travels directly in only one direction and is capable of providing constant voltage.
The image below shows the voltage plotted against time for DC power. Notice how it forms a straight line and does not change over time. This is the type of power that comes from batteries, and it is used in most of our day-to-day electronics, such as phones and laptops.

DC power diagram

Unlike Direct Current, Alternating Current changes back and forth between two values, just like how day alternates with night. 
From the image below, we can see that voltage is alternating between a high positive position and a negative position of equal value. 
AC power alternates between these values in a sine wave. This is the type of power that gets carried through power lines and into the power outlets in our homes.

What is a Signal?

Signals are another important topic to know when using the Arduino structure. Signals are a way of transmitting and receiving information. Signals are what allow electronic devices to communicate with each other. 

In the following sections, we will cover analog signals vs. digital signals. We will point out what they each are and how they differ from each other. We will also discuss how to use each of these signals on an Arduino. Lastly, we will discuss the nature of PWM signals, and how they can be used with Arduino.

Digital Signals

What is a Digital Signal?

You can imagine a digital signal like a light switch. Similar to a light switch, a digital signal has two states, ON or OFF. 
In the ON state, the voltage of the signal is equal to the supply voltage. The supply voltage for the Arduino UNO is 5 volts, so if the digital signal is in the ON state, it will have a value of 5 volts. Other terms you will often see instead of ON include HIGH or 1, which all mean the exact same thing.
For the OFF state, the voltage is GND (ground) or 0 volts. Sometimes people may call the OFF state LOW or 0.

The image below shows the light-switch-like behavior of a digital signal. When the signal is ON (or 1), it has a value of 5V. When the signal is off (or 0), it has a value of 0V. Notice that there are no values in between, the digital signal can only be 5V or 0V.

Arduino digitalWrite() and Other Functions

The Arduino UNO has fourteen digital input-output (I/O) pins. These pins are labeled zero to thirteen and can be seen highlighted in the red box in the image below.

 

A digital output is a signal that starts from the Arduino and goes to another device. You would use the function digitalWrite() in your code to tell the Arduino UNO to send information to another system. 
On the other hand, a digital input is a signal coming from another device and going to the Arduino UNO. You need to use the digitalRead() function to read this incoming information from other devices. Some of these digital I/O have special functions. For instance, pin 13 is connected to an on-board LED.

What is Digital Communication?

An important application of digital signals is digital communication. Digital communication allows digital devices, such as the Arduino or our computer, to communicate with each other by following a digital communication protocolYou can think of a communication protocol like a language

Both devices need to be speaking the same “language” in order to communicate with each other. 

 
Some common protocols you might hear about include UART (which is how your computer talks with your Arduino via a USB cable), I2C and SPI

Analog Signals

What is an Analog Signal?

Another type of signal that we use everyday is the analog signal. Define in your mind a dimmable light switch, similar to our light switch analogy for digital signals A dimmable light switch can be completely on or off like a digital switch, but it can also be turned to half brightness, or any value between fully on or fully off. Likewise, an analog signal can be 0 volts, 5 volts, or any value in between, like 2.5 volts, 4.3 volts, or 0.001 volts.

Are Analog Signals Continuous?

Yes, analog signals are continuous as opposed to digital signals which are discrete. This is one of the key differences between analog signals vs. digital signals

What continuous means is that for every point in time, the analog signal has a real value. 


You can see this in the following image below: the analog signal
moves continuously from one value to another over timeThere are no “jumps” from one value to another like you saw in the digital signals example.

How do we use an Analog Signal?

The Arduino UNO has six analog inputs labeled A0 to A5 located at the bottom right corner of the Arduino UNO. These pins are highlighted in the red box in the following image.

Since the Arduino UNO is a digital device, incoming analog signals need to be fed through a device called an analog-to-digital converter (ADC).  The ADC converts an analog signal to a digital signal that the microcontroller can understand
The analogRead() function that is built into the Arduino IDE can be used to read values from the specified analog pin. The Arduino UNO does not have any native analog output. In order to have an analog output, there needs to be a device on board called a digital-to-analog converter (DAC)which is just the opposite of an ADC. Since the Arduino UNO does not have a DAC, a PWM signal is often used to simulate an analog signal.

PWM Signals

What is a PWM Signal?

PWM stands for Pulse Width Modulation, and it is often used to imitate analog signals by using digital signalsThe name “Pulse width modulation” is just a fancy term for “changing the width of the pulse in this pattern.” The image below shows an example of a PWM signal. You can probably see that the width of the pulse is changing (or modulating) over time. 

Arduino PWM analog signal diagram
There are two characteristics used to describe PWM:
    • Frequency
    • Duty cycle
Frequency is the number of times that a pulse pattern happens per second. It is measured in Hertz, which is just 1 over seconds. Mathematically, frequency is the inverse of period, and period is the time it takes for one cycle of this pattern to occur, as shown in the figure below. if you have a frequency of 10Hz, you would have this pulse pattern happening 10 times per second. 

The other characteristic of a PWM signal is duty cycle. Duty cycle is the width of the pulse, which is measured in percentage. Duty cycle is basically the amount of space the pulse takes up within the entire period. 

In the image below, you can see the first pulse is 25% of the period, so it’s a 25% duty cycle. 


In the second period, the pulse is taking up 50% of the period, meaning that it has a 50% duty cycle.

pwm signal- arduino analog signal

How Exactly is a PWM Signal Used to Simulate an Analog Signal?

The example below will help answer this question. In the example below, “Low” means 0 volts or ground, and “High” means 5 volts. The orange line that is between the high and low signal is our average voltage. We can see that the frequency (i.e. the time between the rising edges) is constant. However, from the changing widths of the pulses, you can see that the duty cycle (percentage of time that each pulse is high) is changing.
As the width of the pulses change, we can see that the average voltage over time is going between ground and 5 volts. The larger the duty cycle, the larger the average voltage.

pwm simulating on analog signal

The varying average voltage in the graph demonstrates one important characteristic of analog signals: the signal can be any value between ON (high) and OFF (low) voltagesThis is exactly what we mean by a PWM signal simulating an analog signal.

Using PWM with Arduino analogWrite()

A PWM signal is a type of digital signal, so we still use the same digital pins located on the top of the Arduino. As shown in the image below, here’s a tilde (~) beside certain digital pins: pins 3, 5, 6, 9, 10, and 11. This is to denote that these pins are capable of generating a PWM signal.

pwm pins arduino

The Arduino makes it very easy to generate PWM signals. Use the Arduino analogWrite() function to create an analog output using one of the PWM pins.

The PWM generation from the Arduino does have some limitations that you should be aware of. 


One limitation is that the
frequency is fixed for the PWM pins. For pins 5 and 6, the frequency is fixed to 980 Hz, meaning there are 980 pulses per second. All other PWM pins are fixed at a 490 Hz frequency, which generate 490 pulses per second. 

Conclusion

You have now learned the most relevant concepts that are key to robotics amateurs and professionals in 2022. These skills will help you get started with the ultimate robotics projects, including: 

    • The key differences between analog signals and digital signals

    • How to leverage PWM and duty cycle for Arduino

    • The basics of AC and DC power

These are the key fundamentals that tech employers and colleges wish you knew. With these fundamentals, you’ll be able to complete robotics projects, including those needing digital communication, reading data from sensors, and of course, getting your robots to move!

Join our Tech Tribe Community and be the first to learn important global tech news and improve your skills in engineering/robotics/3D printing, and more. Continue to quickly learn all the knowledge you need for DIY electronics or your college program with our Learning Hub.  

Share this post with your friends

Share on facebook
Share on twitter
Share on linkedin

1 thought on “How To Use An Arduino – Beginners Guide (2022)”

  1. Pingback: How does a Stepper Motor Work? - Beginners Guide 2022

Leave a Comment

Your email address will not be published.