What is Arduino UNO?
Arduino UNO is an open-source development board with easy-to-use hardware and software. It is extremely popular among the DIY community, which means that over the years it has generated a number of copies and improved versions, such as the ability to connect to WiFi using the ESP8266 module. Its greatest advantage is its versatility. The ATmega328P microcontroller used offers a decent number of pins and good performance. The latest version of the board is Arduino UNO R3, but it hasn't changed much from previous versions.
How to connect something to Arduino UNO?
The standard Arduino UNO has several sets of female Dupont connectors. When you look at the board from the USB-B port, you can divide the pins into two sets on the left and two on the right. We refer to those on the left as digital or I/O pins. They can send or receive two values, 0V and 5V, which represent one and zero. Some of these pins have a PWM or pulse width modulation function. They can send 5V pulses in regular succession, and the width of the positive pulse can be adjusted. Hence the name. This is useful for applications where you need to regulate the energy of something but must maintain the same voltage. For example, controlling the brightness of an LED or the speed of a motor. The same principle is used to control model servo motors.
On the other side of the board, the more distant set, are the ADC pins. These are capable of converting an analog signal, i.e., a continuous signal in the range of 0-5V, into a signal that a digital microcontroller can work with. However, this does not mean that they cannot also function as digital pins.
The closer set of pins on the left side cannot be programmed, but they are all the more important. These are pins for powering sensors and other devices that you want to connect to the board, a pin for powering the board (more on this in the category How to power the Arduino UNO?), GND pins, which serve as the imaginary negative terminal of the battery, and finally the RST pin and reference pin. When the RST pin is connected to the GND pin, the board resets, and the reference pin is used to set the maximum voltage of the ADC pins. And that concludes the layout of the board's pins. The last thing I will mention are the buses. The Arduino UNO is capable of communicating over three buses: UART, I2C, and SPI.
.jpg)
Pin layout and signals on them
How to program the Arduino UNO?
Programming the Arduino UNO is very simple. A USB-B connector and the Arduino IDE development environment are used for this. Simply connect the Arduino UNO to your computer using a USB-B cable and open the Arduino IDE. In the Tools tab, select Arduino UNO from the list of boards, and then select the port that the Arduino UNO was set to when connected to the computer. Most likely, it will say Arduino UNO right next to it. You can read more details in our article Getting Started with Arduino.
The language used for programming in Arduino IDE is called WIRING. It is extremely similar to C++, so if you know how to program in C++, programming Arduino will not be a problem for you. Here is a sample of some basic instructions; you can find the complete list on the Arduino Wiring Reference page: DigitalWrite changes the voltage on the selected pin according to the selected parameter, either to 5V (HIGH) or 0V (LOW). DigitalRead returns 1 or 0 depending on whether 5V or 0V is applied to the selected pin. AnalogWrite is intended for PWM pins, and the function parameter determines the length of the positive pulse. AnalogRead is used to read the current voltage on the ADC pin. It should be noted that the value returned by the function is not the actual voltage value, but a digital value resulting from the conversion of analog voltage to digital. To obtain the voltage value, it is then necessary to perform a conversion. This will be mentioned later.
How to power the Arduino UNO?
There are several ways to power the Arduino. Probably the easiest way is to power it in the same way as you program it – using a USB-B connector. However, you can also use a power bank or a power adapter with a USB connector. The disadvantage of this method is, of course, the need for a USB-B cable, which few people have in excess.
The second option is to use a standard power connector, which is usually capable of supplying much more power, and power sources with this connector are relatively common in households. To find out if the power supply you found at home can be used, you need to check its output voltage and current somewhere on the power supply. Usually, this information is labeled OUTPUT on the power supply. If the output voltage is between 6-12V and the current is 1A or more, then this power supply can be used. If not, another one must be used.
The last method is to power the board using the Vin pin. This method is most suitable if you want to use Arduino UNO with a battery or use a 5V power supply from another module. Simply connect the positive pole to the Vin pin and the negative pole to any GND pin on the board.
A simple project to try it all out in practice.
What will you need?
- Arduino UNO board, here are a few options
- Original Arduino UNO, which is more expensive than its clones, but of higher quality. Functionally, the clones are mostly the same.
- An identical copy of Arduino UNO with the same converter and microcontroller case.
- A copy of Arduino UNO with a different USB converter. For this, you need to download and install a different driver (instructions). It also has a microcontroller in an SMD case and a set of additional pins that can be soldered to it if you need additional cables or Dupont connectors for one pin. This is the cheapest option.
- Arduino UNO combined with the ESP8266 WiFi module, which is more complicated to program but will keep you entertained for much longer. It also uses a CH340 USB converter like the previous option. Furthermore, it does not use a USB-B connector, but the much more common microUSB.
Funduino Learning Shield
USB-A, USB-B connector
What are we going to do?
We will create a program to control LEDs using a built-in trimmer and buttons. It will work by changing the intensity of the LED light depending on how the trimmer on the board is turned. It's like a manually controlled dimmer.
First, insert the Funduino shield into the Arduino UNO board and connect the board to your computer. Open Arduino IDE on your computer and select the correct board and port in the tools. Then you need to look at the Funduino shield reference, where you will learn that the trimmer is connected to pin A0 of the Arduino board and the input buttons are connected to pins A1 and A2. These pins will function as inputs, so set them to INPUT using the pinMode function. There are four LEDs on the shield, but only three have the PWM function we need. We have chosen pin 11 for this example. However, pins 10 and 13 should also work. Whichever pin you choose, set it as an output.
First, let's look at the part of the code where we will read the voltage from the trimmer and use it to set the LED input. Create a new variable and name it, for example, val. The variable will be of type int (integer). Val will be equal to the value read from the trimmer, i.e., val = analogRead(A0);. This will give you values between 0-1023. However, the digitalWrite function only accepts values in the range 0-255. You must therefore convert the value from A0. The function for the PWM buzzer will then look like this: analogWrite (3, val*(255./1023.));.
Finally, we will turn the buzzer on and off using the IF function. This is a function that executes the code that follows it in curly brackets when its parameter is true. This function, supplemented with the ELSE section, can execute the code even if the function condition is false.
Create a new variable called ON, which will be of type boolean. This type of variable can only have two values – True or False. Set the variable to False when creating it. If button A1 is pressed, this variable will change to True, and if button A2 is pressed, it will change back to False. Finally, we will put our previous code into the body of the IF function, whose parameter is the ON variable, and that is the first section for executing the code when the condition is true. If the condition is not true, we will put the line digitalWrite(3,LOW); into the ELSE section. And that's it, all you have to do is upload this code and try it out.
