Programming for the Arduino: a beginner's tutorial
The Arduino is one of the most famous developer platforms on the market. You can find out how to program and use it correctly here.
Arduino: This hardware is required for programming
Arduinos are like sand by the sea. Accordingly, the selection is large. If you are not yet familiar with the matter, we have a few tips for you.
- The Arduino Uno is very suitable for beginners, as it provides both six analog pins and 14 digital pins, which means that you can already connect many electronic components to them. You also have the advantage that you can (usually) replace the microcontroller without buying a new board. It is also easy to program with the board and then soldered into a circuit.
- Another good entry-level board is the Arduino Mega 2560. Although the chip is permanently installed, the board offers significantly more pins than the Uno, but is also correspondingly more expensive.
- Since the Arduino platform is "Open Source", there are also many cheap alternatives to the "real" Arduinos.
- Conveniently, you can find some Arduino kits on the Internet that already come with a whole range of electronic components, which can save you money.
- If you don't buy a kit, you can get the parts individually. As a beginner, you should first buy a few LEDs, resistors, buttons, potentiometers and a servo to try out a lot. You also need jumper cables and a breadboard to connect the components together.
Install Arduino IDE
Before you can really have fun with your Arduino, you must first install the Arduino IDE.
- During the installation under Windows you will be asked several times whether you want to install the Arduino drivers. Be sure to click "Install" here, otherwise you will not be able to use the Arduino with the PC later.
Arduino: control LED
We show you how to control an LED with the Arduino.
- To do this, first connect the pin labeled "GND" to the short side of the LED using a jumper cable.
- Connect the other side of the LED with a suitable resistor.
- Also connect the resistor to pin 13.
- Start the Arduino IDE and connect the Arduino to the PC with a USB cable.
- Click on the "Tools" tab and select your board, its specifications and the port.
- In "void setup ()" you must first add a command that defines pin 13 as an output. This is easily done with the command "pinMode (13, OUTPUT);" (without quotes).
- In the "void loop ()" you can now add commands that should be executed again and again. First, the command "digitalWrite (13, HIGH);" the pin is set to HIGH, which means that a voltage of 3.3 volts is applied to it.
- Now add the command "delay (1000);" so that the program then waits for a second.
- Now you can use the command "digitalWrite (13, LOW);" add so that the program turns off the LED again. Then insert the delay command again.
- Finally, upload the program to the Arduino. Now you have a flashing LED!
Use buttons on the Arduino
To use a button on the Arduino, insert it into the area of the groove of the breadboard.
- Connect the connector at the bottom left to the 5V pin and the connector at the bottom right via a 10 kiloohm or higher resistor to the ground.
- The connector is also connected to pin 3 in the top right corner.
- In the setup method you first define this button as input: "pinMode (3, INPUT);"
- With the command "digitalRead (3);" you can now read out the digital state of the pin. This is either HIGH or LOW. Simply use an if statement to query.
Arduino: control servo
Since controlling the servo is somewhat more complex, we have summarized this for you in a separate article.
In the next article you will learn how to write your own programs in Java.