Arduino Sketch

What is Arduino Sketch ?

The code that runs on Arduino is usually called “Sketch”. Getting started with Arduino programming is quite easy because the structure of the Sketches is clear. The Arduino programming language is derived from C++ programming. You only need a few lines of code for your first simple projects.

Arduino Sketch Structure

The structure of an Arduino program is divided into two parts: setup() and loop().

Arduino Sketch Structure

The setup function is executed only once when the Arduino board is started or after a reset. In this function basic settings like variable declarations, the configuration of ports, or initialization routines. Additionally, the inputs and outputs are set, as shown in the Blink example below, the led pin 13 is set as output.

Arduino blinking LED Sketch

The setup function is mandatory and must always be present, even if no declarations have to be made. In this case, the function remains empty.

The loop function is the second area of the basic structure of an Arduino program and has the task of the main program. After the setup function has been executed once, the loop function is run through – as its name implies, as an endless loop. In the loop, all further instructions and function calls are accommodated, which are needed in the normal operation for the desired application. As in the blinking example, it turns on the LED, waits one second, turns it off, waits one second, and repeats forever.

Arduino Examples

The easiest way to get started is to work through example programs and then modify and extend them for your own applications. Also, you can find a lot of Arduino sketches and even complete projects for your application on the internet. One Arduino code example is called AnalogInOutSerial shown above.

AnalogInOutSerial Arduino example

It sets the pulse width modulation (PWM) of an output pin (9) based on the analog input readings on pin (A0), after mapping from the ADC scale (0 to 1023) to the output PWM scale (0 to 255). It also prints out the results on the Serial Monitor. The circuit diagram for this code is shown below

Read More

What is Arduino ?

The Arduino is an open-source embedded development platform that consists of both hardware and software. The hardware part consists of a microcontroller chip and its operating circuit. It has analog and digital inputs and outputs that connect the Arduino to the physical world.

Arduino Uno. Source: arduino.cc

Arduino Software

The software part consists of an Integrated Development Environment (IDE), bootloader, and a huge set of libraries, an executable program that runs on the PC to create the code and upload to the Arduino, which is then executed by the hardware part. The Arduino’s programming language is based on C++ and is designed so that one can create programs without too deep programming knowledge.

Arduino Sketch

The created program is called “Sketch”. The IDE uploads the sketch via USB port from the development environment into the flash memory of the Arduino’s microcontroller. This USB connection to the hardware part must always be present during the development and testing phase. The data transfer is done as a serial data transfer. At the same time, the connection also serves as an aid for debugging. With the help of a “serial monitor”, the states of the inputs and outputs ports can be monitored. After development, the connection to the development environment can be disconnected and the Arduino can communicate with the real world independently as long as it is connected to the power.

What is Arduino Board ?

The “board” refers to the various versions of the Arduino’s printed circuit boards equipped with components. Different Arduino boards can be selected based on the application. Each board contains different microcontroller, connectors, and interfaces. One of the most popular boards is called Arduino Uno.

Power is supplied either by a separate, external power supply unit or via the connected USB interface. The USB interface can deliver a maximum of 500 mA at 5 Volt voltage. For smaller own developments this kind of power supply is usually sufficient. Besides the power supply just described, the USB interface is also used for communication with the development environment, i.e. for uploading programs (sketches) and reading/sending data via serial monitor.

Read More
error: Content is protected !!