0% found this document useful (0 votes)
19 views3 pages

Arduino Programming Guide

Programmin Guide for Arduinio IDE

Uploaded by

Krishna Gondkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Arduino Programming Guide

Programmin Guide for Arduinio IDE

Uploaded by

Krishna Gondkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Arduino Programming in Arduino IDE

Introduction to Arduino Programming in Arduino IDE


Arduino programming uses a simplified version of C/C++ designed to run on
microcontrollers.
It is done using the Arduino IDE, which allows users to write, compile, and upload code
directly to the microcontroller (like ESP32 or Arduino Uno).

Basic Code Structure in Arduino Sketch


Every Arduino sketch (program) has two main functions:

1. void setup()
- Executes once when the board starts or resets.
- Used for: Pin initialization, starting serial communication, connecting to Wi-Fi (for ESP32).

Example:

void setup() {
pinMode(2, OUTPUT); // Set pin 2 as output
Serial.begin(9600); // Start serial monitor
}

2. void loop()
- Runs continuously after setup() finishes.
- Used to read sensors, control actuators, and implement repeated logic.

Example:

void loop() {
digitalWrite(2, HIGH); // Turn LED ON
delay(1000); // Wait 1 second
digitalWrite(2, LOW); // Turn LED OFF
delay(1000); // Wait 1 second
}

Essential Built-in Functions


Function Description Example
pinMode(pin, mode) Set pin as INPUT or pinMode(2, OUTPUT);
OUTPUT
digitalWrite(pin, value) Set pin HIGH (3.3V) or LOW digitalWrite(2, HIGH);
(0V)
digitalRead(pin) Read HIGH/LOW from input int state = digitalRead(4);
pin
analogRead(pin) Read analog voltage (0– int val = analogRead(34);
4095 on ESP32)
analogWrite(pin, value) Output PWM (0–255) analogWrite(2, 150);
delay(ms) Pause program in delay(1000);
milliseconds

Important Notes on ESP32 Pins


- Digital Pins: D0 to D39 (some reserved)
- Analog Pins: A0 to A13 (e.g., GPIO 34, 35, 32...)
- PWM Output: Many GPIOs support PWM using analogWrite()
- Serial Communication: Use Serial.begin(baud_rate) to communicate with PC

Beginner Project – Blink an LED


Objective: Make an LED connected to pin 2 blink every second.

Circuit: Connect LED to pin 2 through 220Ω resistor.

Code:

void setup() {
pinMode(2, OUTPUT); // Set GPIO 2 as output
}

void loop() {
digitalWrite(2, HIGH); // LED ON
delay(1000); // Wait 1 second
digitalWrite(2, LOW); // LED OFF
delay(1000); // Wait 1 second
}

Outcome: The LED will blink on and off every second — a simple way to understand setup()
and loop() flow.

How to Upload Code using Arduino IDE


- Open Arduino IDE

- Select the correct board: Tools > Board > ESP32 Dev Module

- Select the right COM Port: Tools > Port > COMx

- Write or paste code


- Click the Upload Button (→)

- Wait for 'Done uploading' — Your board is now running the code!

Best Practices for Beginners


- Start simple: Use blink, button press, or analog read examples.

- Use comments (//) in code to document logic.

- Use serial monitor: Serial.println() helps debug.

- Test regularly: Upload and test in small increments.

- Avoid delay() in complex logic: Use millis() for non-blocking delays.

Next Steps in Arduino Programming


- Try controlling sensors (e.g., temperature, motion).

- Read values from analog inputs.

- Use PWM to dim LEDs or control motor speed.

- Learn to connect Wi-Fi (for ESP32).

- Upload sensor data to cloud platforms like ThingSpeak or Blynk.

Summary
- Arduino code always includes setup() and loop().
- Core functions: pinMode(), digitalWrite(), analogRead(), etc.
- Start with LED blink to understand flow.
- Use Arduino IDE to compile and upload code easily.
- Master these basics before advancing to IoT and wireless projects.

You might also like