Arduino IDE
A comprehensive Arduino IDE cheatsheet
1. What is Arduino?
Arduino is an open‑source microcontroller platform used to build electronics projects easily.
Main parts:
- Arduino Board (UNO, Nano, Mega, etc.)
- Arduino IDE (software)
- Sensors, actuators, wires
2. Arduino IDE Basics
Download & Install
- Official IDE supports Windows, Linux, macOS
- Write → Compile → Upload
IDE Sections
- Sketch area – code writing
- Verify (✔) – compile code
- Upload (→) – upload to board
- Serial Monitor (🔍) – view output
3. Arduino Program Structure (VERY IMPORTANT)
void setup() { // runs ONCE } void loop() { // runs AGAIN & AGAIN }
- setup() → initialization
- loop() → main logic
4. Data Types
| Type | Size | Example |
|---|---|---|
| int | 2 bytes | int a = 10; |
| float | 4 bytes | float x = 3.14; |
| char | 1 byte | char c = 'A'; |
| boolean | 1 byte | boolean flag = true; |
| String | dynamic | String name = "Arduino"; |
| long | 4 bytes | long t = 100000; |
5. Variables & Constants
int led = 13; // variable const int button = 2; // constant
6. Operators
Arithmetic
+, -,* , /, %
Relational
==, !=, >, <, >=, <=
Logical
&& || !
7. Pin Modes & Digital I/O
pinMode()
pinMode(13, OUTPUT); pinMode(2, INPUT); pinMode(2, INPUT_PULLUP);
digitalWrite()
digitalWrite(13, HIGH); digitalWrite(13, LOW);
digitalRead()
int state = digitalRead(2);
8. Analog I/O
analogRead() (0–1023)
int val = analogRead(A0);
analogWrite() (PWM: 0–255)
analogWrite(9, 128);
⚠ Works only on PWM pins (~)
9. Delay & Timing
delay()
delay(1000); // 1 second
millis() (Non‑blocking)
unsigned long t = millis();
10. Control Statements
if‑else
if (x > 10) { // code } else { // code }
switch‑case
switch(val) { case 1: break; case 2: break; }
11. Loops
for loop
for(int i=0; i<5; i++) { }
while loop
while(x < 10) { }
12. Functions (User‑Defined)
void blinkLED(int pin) { digitalWrite(pin, HIGH); delay(500); digitalWrite(pin, LOW); }
Call:
blinkLED(13);
13. Serial Communication (VERY IMPORTANT)
Begin Serial
Serial.begin(9600);
Print Data
Serial.print("Value: "); Serial.println(val);
Read Data
char c = Serial.read();
14. Common Sensors Code
LED Blink
void setup() { pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); }
Button Input
int btn = 2; void setup() { pinMode(btn, INPUT); } void loop() { int s = digitalRead(btn); }
15. Libraries
Include Library
#include <Servo.h>
Use Library
Servo s; s.attach(9); s.write(90);
16. Interrupts
attachInterrupt(digitalPinToInterrupt(2), isr, RISING); void isr() { // interrupt code }
Modes: RISING, FALLING, CHANGE
17. EEPROM (Memory)
#include <EEPROM.h> EEPROM.write(0, 100); int x = EEPROM.read(0);
18. Power & Voltage
- Digital pins → 5V / 3.3V
- Analog reference → analogReference()
- GND must be common
19. Debugging Tips
- Use Serial.println()
- Check COM port & board
- Remove RX/TX while uploading
- Read error messages carefully
20. Common Arduino Boards
| Board | Voltage |
|---|---|
| UNO | 5V |
| Nano | 5V |
| Mega | 5V |
| ESP32 | 3.3V |
21. Best Practices
✔ Use meaningful variable names
✔ Avoid long delay()
✔ Comment your code
✔ Test module‑by‑module