top of page

Arduino Basics

  • 4 days ago
  • 1 min read

Example Code for LED



pinMode(LED_BUILTIN, OUTPUT);

  • Tells the Arduino that the built‑in LED pin (usually pin 13 on most boards) will be used to send signals out, not read them in.

  • “OUTPUT” means we’ll control something like turning a light on or off.


digitalWrite(LED_BUILTIN, HIGH);

  • Sends a HIGH signal (5 V) out of that pin.

  • For an LED, that means turn it ON.





Example Code for Button Press



Serial.begin(9600);

  • This line starts serial communication between the Arduino and your computer.

  • 9600 is the speed of that communication, called the baud rate — it means 9600 bits per second.

  • Once started, you can use commands like Serial.print() to show data (like the button state) in the Serial Monitor.


buttonState = digitalRead(buttonPin);

  • digitalRead() checks whether the pin (buttonPin) is getting a HIGH or LOW voltage.

  • It returns either:

    • HIGH (1) → the button is pressed (current is there), or

    • LOW (0) → the button is not pressed.





Example Code for Button LED Control



if (buttonState == HIGH);

  • It checks whether the variable buttonState equals HIGH.

  • HIGH means the pin is receiving voltage (usually 5 V), so in a button circuit, that usually means the button is pressed.

  • The == in programming means “is equal to”, not “assign.” (People often mix this up with = which means “store the value.”)



 Example Code for IR LED Control




Example Code for Servo




Example Code for IR Servo Control



Comments


bottom of page