UNIT – 3: Programming with Arduino Uno
UNIT – 3: Programming with Arduino Uno
1. Arduino UNO Board Block Diagram
-
Key components:
-
ATmega328P Microcontroller
-
Power Supply (USB/adapter)
-
Digital I/O Pins (0–13)
-
Analog Input Pins (A0–A5)
-
Reset button
-
USB port (programming)
-
2. Sketch Structure
3. Data Types & Built-in Constants
-
int, float, char, boolean
-
Constants: HIGH, LOW, INPUT, OUTPUT, true, false
4. Operators
-
Arithmetic (+, -, *, /, %)
-
Comparison (==, !=, >, <, >=, <=)
-
Logical/Boolean (&&, ||, !)
-
Bitwise (&, |, ^, ~, <<, >>)
-
Compound (+=, -=, *=, /=)
5. Control Statements and Loops
-
if, else if, else
-
for loop, while loop, do-while loop
-
switch-case
6. Functions
-
User Defined: custom functions created by programmer.
-
Library Functions:
-
I/O Functions:
digitalWrite(),digitalRead(),analogRead(),analogWrite() -
Char Functions:
isAlpha(),isDigit() -
Math Functions:
abs(),pow(),sqrt(),random()
-
Short Questions – UNIT 3
-
What is the purpose of setup() in Arduino?
👉 To initialize variables, pin modes, and libraries (runs once). -
Which Arduino function is used to read analog input?
👉analogRead() -
What is the data type for storing decimal values?
👉 float
MCQs – UNIT 3
-
Arduino Uno is based on:
a) ATmega8
b) ATmega16
c) ATmega328P ✅
d) ATmega32 -
Which loop runs continuously in Arduino?
a) setup()
b) loop() ✅
c) while()
d) for() -
Function to generate random number:
a) rand()
b) random() ✅
c) randint()
d) getRandom()
UNIT – 3: Programming with Arduino Uno
1. Draw and explain the block diagram of Arduino Uno board.
Answer:
The Arduino Uno has an ATmega328P microcontroller, digital I/O pins (0–13), analog input pins (A0–A5), power supply, USB interface, oscillator, and reset button. It acts as the central brain of IoT projects.
2. Explain the structure of an Arduino sketch.
Answer:
Every Arduino program has two main functions:
-
setup(): Runs once, used for initialization.
-
loop(): Runs continuously, executes the main logic.
3. Describe Arduino data types with examples.
Answer:
-
int (integer numbers)
-
float (decimal numbers)
-
char (characters)
-
boolean (true/false)
Example:int x=10; float y=5.5;.
4. Explain built-in constants in Arduino with examples.
Answer:
-
HIGH, LOW (digital signals)
-
INPUT, OUTPUT (pin mode)
-
true, false (boolean constants)
5. Explain Arithmetic operators in Arduino with example code.
Answer:
Operators: + - * / %.
Example: int z = x + y;.
6. Differentiate between comparison and logical operators in Arduino.
Answer:
-
Comparison (==, !=, >, <) compares two values.
-
Logical (&&, ||, !) combine conditions.
7. Explain bitwise operators with example.
Answer:
Bitwise operators (&, |, ^, <<, >>) perform operations at the binary level.
Example: 5 & 3 = 1.
8. Explain compound operators with example code.
Answer:
Operators like +=, -=, *=, /= update values.
Example: x += 5; // same as x=x+5;.
9. Explain the usage of control statements in Arduino with example.
Answer:
Control statements: if, else if, switch-case.
Example:
10. Differentiate between while and for loops in Arduino.
Answer:
-
for loop runs for a fixed number of times.
-
while loop runs until condition becomes false.
11. Explain the importance of functions in Arduino programming.
Answer:
Functions allow code reusability and modular programming. Example: void blinkLED() { digitalWrite(LED, HIGH); delay(1000); }.
12. Differentiate between user-defined functions and library functions in Arduino.
Answer:
-
User-defined: Written by the programmer.
-
Library functions: Predefined (e.g.,
digitalRead(),pow()).
13. Explain I/O functions in Arduino with examples.
Answer:
-
digitalWrite(pin, HIGH)→ Turns ON output. -
digitalRead(pin)→ Reads digital input. -
analogRead(pin)→ Reads analog value. -
analogWrite(pin, value)→ PWM output.
14. Explain char functions with example.
Answer:
Functions like isAlpha(), isDigit() help check character properties.
Example: if(isDigit(ch)) { ... }.
15. Explain math functions in Arduino with examples.
Answer:
-
abs(x),pow(x,y),sqrt(x),random(min,max).
These functions perform mathematical calculations in IoT projects.
Comments
Post a Comment