arduino commands
arduino commands

Introduction

Arduino programming is one of the easiest ways for students and beginners to start learning electronics and embedded systems.

This Arduino commands list includes the 50 most important Arduino functions used in programming, electronics projects, and sensor applications. This list works as a quick reference and cheat sheet for students learning Arduino programming.

#CommandDescription
1pinMode()Configure pin as INPUT or OUTPUT
2digitalWrite()Set digital pin HIGH or LOW
3digitalRead()Read digital pin state
4analogWrite()Write PWM value to pin
5analogRead()Read analog sensor value
6delay()Pause program execution
7millis()Time since program started
8micros()Time in microseconds
9Serial.begin()Start serial communication
10Serial.print()Print data to serial monitor
11Serial.println()Print line to serial monitor
12Serial.read()Read serial data
13Serial.available()Check serial buffer
14random()Generate random numbers
15map()Convert value ranges
16constrain()Limit value within range
17abs()Absolute value
18sq()Square a number
19sqrt()Square root
20pow()Power calculation
21sin()Sine function
22cos()Cosine function
23tan()Tangent function
24HIGHDigital HIGH constant
25LOWDigital LOW constant
26INPUTPin input mode
27OUTPUTPin output mode
28INPUT_PULLUPEnable internal pull-up resistor
29attachInterrupt()Attach interrupt
30detachInterrupt()Detach interrupt
31noTone()Stop tone generation
32tone()Generate tone
33tone(pin,freq,duration)Tone with duration
34shiftOut()Send serial data
35shiftIn()Receive serial data
36bitRead()Read bit value
37bitWrite()Write bit value
38bitSet()Set bit to 1
39bitClear()Set bit to 0
40word()Create 16-bit number
41lowByte()Get lower byte
42highByte()Get higher byte
43isAlpha()Check if letter
44isDigit()Check if number
45delayMicroseconds()Delay in microseconds
46detach()Detach servo
47EEPROM.write()Write EEPROM value
48EEPROM.read()Read EEPROM value
49pulseIn()Measure pulse duration
50interrupts()Enable interrupts

Table of Contents

  1. Basic Pin Control Commands
  2. Timing Functions
  3. Serial Communication
  4. Math Functions
  5. Digital Logic Constants
  6. Interrupt Functions
  7. Sound Functions
  8. Bit Manipulation
  9. Data Handling
  10. Character Functions
  11. Timing in Microseconds
  12. EEPROM Memory
  13. Pulse Measurement
  14. Interrupt Control

1️⃣ Basic Pin Control Commands

1. pinMode(pin, mode)

Configures a pin as an input or output.

Example:

pinMode(13, OUTPUT);

2. digitalWrite(pin, value)

Turns a digital pin ON or OFF.

digitalWrite(13, HIGH);

3. digitalRead(pin)

Reads the state of a digital pin.

int state = digitalRead(2);

4. analogWrite(pin, value)

Writes a PWM value (0–255).

analogWrite(9, 128);

5. analogRead(pin)

Reads an analog value (0–1023).

int sensor = analogRead(A0);

2️⃣ Timing Functions

6. delay(ms)

Pauses the program for milliseconds.

delay(1000);

7. millis()

Returns the number of milliseconds since the program started.

long time = millis();

8. micros()

Returns the time in microseconds.

long time = micros();

3️⃣ Serial Communication

9. Serial.begin(speed)

Initializes serial communication.

Serial.begin(9600);

10. Serial.print(value)

Prints data to the serial monitor.

Serial.print("Hello World");

11. Serial.println(value)

Prints with a new line.

Serial.println(123);

12. Serial.read()

Reads data from the serial port.

char data = Serial.read();

13. Serial.available()

Returns available bytes in the serial buffer.

if (Serial.available() > 0) { }

4️⃣ Math Functions

14. random(min,max)

Generates a random number.

int num = random(1,100);

15. map(value,inMin,inMax,outMin,outMax)

Maps a value from one range to another.

int newValue = map(sensor,0,1023,0,255);

16. constrain(value,min,max)

Limits a value to a range.

value = constrain(value,10,100);

17. abs(value)

Returns absolute value.

int a = abs(-5);

18. sq(value)

Returns square of a number.

int x = sq(4);

19. sqrt(value)

Returns square root.

float r = sqrt(25.0);

20. pow(base,exponent)

Calculates power.

float result = pow(2,3);

21. sin(angle)

Calculates sine.

float s = sin(PI/2);

22. cos(angle)

Calculates cosine.

float c = cos(PI);

23. tan(angle)

Calculates tangent.

float t = tan(PI/4);

5️⃣ Digital Logic Constants

24. HIGH

Represents logical HIGH.

digitalWrite(13,HIGH);

25. LOW

Represents logical LOW.

digitalWrite(13,LOW);

26. INPUT

Defines pin as input.


27. OUTPUT

Defines pin as output.


28. INPUT_PULLUP

Activates internal pull-up resistor.


6️⃣ Interrupt Functions

29. attachInterrupt()

Attaches an interrupt to a pin.

attachInterrupt(digitalPinToInterrupt(2), myFunction, RISING);

30. detachInterrupt()

Disables interrupt.


7️⃣ Sound Functions

31. noTone(pin)

Stops tone generation.


32. tone(pin,frequency)

Generates a square wave.


33. tone(pin,frequency,duration)

Tone with duration.


8️⃣ Bit Manipulation

36. bitRead(value,bit)

Reads a bit.


37. bitWrite(value,bit,state)

Writes a bit.


38. bitSet(value,bit)

Sets bit to 1.


39. bitClear(value,bit)

Clears bit.


9️⃣ Data Handling

40. word(value)

Converts number to 16-bit word.


41. lowByte(value)

Gets low byte.


42. highByte(value)

Gets high byte.


🔟 Character Functions

43. isAlpha(character)

Checks if character is a letter.


44. isDigit(character)

Checks if character is a number.


11️⃣ Microsecond Timing

45. delayMicroseconds(us)

Pauses program in microseconds.


12️⃣ Memory Functions

47. EEPROM.write(address,value)

Writes value to EEPROM.


48. EEPROM.read(address)

Reads value from EEPROM.


13️⃣ Pulse Measurement

49. pulseIn(pin,state)

Measures pulse duration.


14️⃣ Interrupt Control

50. interrupts()

Enables interrupts.

Conclusion

Learning these 50 Arduino commands and functions will help students understand how Arduino programs interact with hardware, sensors, and electronic devices.

This list works as a quick reference for beginners and a useful cheat sheet for Arduino programming.

Related Arduino Tutorials