Functions in Arduino Programming

Predefined Arduino functions

Before we get into programming, lets get hold of list of predefined functions in Arduino programming

SNo Functions Arguments Description
1 pinMode(pin,OUPUT); Pin: one of the digital pins of Arduino
OUTPUT/INPUT:Setting chosen pin as input/output
To set the digital pins either as input or output
2 Serial.begin(baudrate); Baud rate: speed at which data is transmitted via serial pins. Commonly used: 9600 Initializes Serial communcation in Arduino
3 analogRead(analogpin); Analog pins: A0 to A5 Reads the analog data from analog pin. Read data will be between 0 to 1023
4 analogWrite(pin, value); pins: 3,5,6,9,10,11 one of these PWM pins in UNO can be used
value:between 0 to 255
Send out the analog voltage value between 0V to 5V on the specified pin. please note that pin should be a PWM pin
5 digitalWrite(pin, value); pins: Should be one of the digital pins
value:Boolean value either 0 or 1(0V or 5V)
Send out the analog voltage value between 0V to 5V on the specified pin. please note that pin should be a PWM pin
6 digitalRead(pin); pins: Should be one of the digital pins
Reads digital value HIGH or LOW from the specified digital pin
7 delay(time); time in milliseconds Creates time delay, period of no action
8 delay(time); time in milliseconds Creates time delay, period of no action
9 Serial.print(content); content: Content from the serial monitor to be printed Prints out the content on the serial monitor consecutively.
10 Serial.println(content); content: Content from the serial monitor to be printed Prints out the content on the serial monitor in a new line each time.
11 Serial.read(); Returns serial data received via Arduino serial pins

There are a lot more predefined Arduino functions, what we have seen above are the most common ones. If we come across any important functions we will update you here.

Writing your own Arduino functions

cod screen shot

Syntax to write a function in Arduino is same as the syntax for C programming.
int:Represents the return type of the function here it is of type int so the function should return integer at the end. if the function doesn't return anything we have to use void.

myMultiplyFunction(): Is the name of the function, you can call your function anything you want.

(int x, int y): Represents the arguments this function takes. your function can take any arguments as per the necessity

{ Represents the beginning of the function

function body goes here

return result

function returns the result, resut should be of type int here since this function is of type integer.

} Represents end of the function.