Lesson 6, Topic 3
In Progress

6.3 Explanation of different syntax used in Arduino Programming?

Lesson Progress
0% Complete

1. Sketch:

The Arduino program is called a sketch. It contains the instructions to be performed by the different boards, which are written in Embedded C.


Comments are the lines that are used to notify the programmer of that particular code snippet. These lines don’t run with code, they are just to explain the particular line used in coding.There are two types of comment

1)  Single line Comment: – single line comment is written using ‘//’, and do not need a termination.

2) Multi-line Comment: -multi-line comments are start with ‘/*’ and end with ‘*/’.

3.Semicolon :

A semicolon is a most important syntactic rule, it is putted at the end of every statement  ‘;’.If we don’t use or forget putting semicolon, an error statement shows.

4. Curly braces :

Curly braces or brackets are an important part of C and C++ programming languages. An open curly brace { must be followed by a closing curly brace }. It is said to be balanced.

5. Setup: void setup() :

This is a declaration for a function called “setup”. This exact line is required in every Arduino sketch. It will only run once when the Arduino is powered or tends to reset.

6. Loop: void loop() { } :

This is where the bulk of your Arduino sketch is executed.The program starts directly after the opening curly bracket ({), runs until it sees the closing curly bracket (}), and jumps back up to the first line in loop() and starts all over.The loop() function will run over-and-over-and-over until the Arduino is reset.

7. Pin mode :

It is used to configure the specified pin to behave as an input or as an output, the pin mode is written in setup function so, it’s run once while the program executes.

Syntax: – pinMode (LED, OUTPUT);

8. Digital write

Digital Write is used to provide the Digital value (HIGH as 5V or LOW as 0V), for those pins which are configured as an OUTPUT with pinMode ().

Syntax: – dgitalWrite (pin, value);

9. Digital Read:

Digital Read is use to read the value (Either HIGH or LOW), for specified digital pin.

  Syntax: – digitalRead (pin);

10. Analog write:

AnalogWrite() function is used for varying the brightness of LED or drive the various speed of motor. It writes an analog value (PWM wave) to a pin.

Syntax: – analogWrite (pin, value);

11. Analog read:

Arduino Board contain a multichannel, 10-bit analog to digital converter.so it can map the input voltage into integer value between ‘0’ unit as zero voltage and 1023 unit as the maximum five voltage, it can be calculated as (5volt / 1024 = 0.0049 volts ‘4.9 mV’).

Syntax: – analogread (pin);