Arduino Basics Friendly Guide
Arduino Basics Friendly Guide
// - Comment
Use this to write notes. Arduino ignores comments.
Example:
// This is a comment
int score = 90; // My score
void setup()
Runs once when Arduino turns on. Use it to set up your pins.
Example:
void setup() {
pinMode(8, OUTPUT); // Set pin 8 as output
}
void loop()
Runs forever. Put your main code here.
Example:
void loop() {
digitalWrite(8, HIGH); // Turn buzzer ON
}
pinMode(pin, mode)
Tells Arduino if pin is input or output.
Example:
pinMode(7, INPUT);
pinMode(8, OUTPUT);
digitalRead(pin)
Reads if a pin is HIGH (1) or LOW (0).
Example:
int buttonState = digitalRead(2);
analogRead(pin)
Reads sensor value from 0 to 1023.
Example:
int sensorValue = analogRead(A0);
analogWrite(pin, value)
Sends output like brightness from 0 to 255.
Example:
analogWrite(9, 100);
Variable Types
int - Whole number
float - Number with decimal
char - One letter
bool - true or false
Logic Keywords
== equal to
!= not equal
> greater than
< less than
&& AND
|| OR