Difference between data type int and long on Arduino I was learning to program for a void obstacle robot but when I looked at the code I saw two data types long and int.

Int are datatypes that holds  -2,147,483,648 to 2,147,483,647.
Long are also datatypes that holds -2,147,483,648 to 2,147,483,647.

Int and long are like same but I came up with the code where two types of datatype is used as seen below:

int trigPin = 2;
int echoPin = 4;
long duration, cm, inches;


But how can you know when to use which datatype? I searched a lot in the web but I didn't understand so can someone explain this to me please.
On the Arduino (AVR models) an int is 16 bits, not 32 bits. Thus it goes from -32768 to +32767.

That is different from long which is 32 bits.