Baghel
Institute
Baghel
Institute
Baghel
Institute
DOAP
DOAP
DOAP
Diploma In Office Automation & Publishing
DURATION 1 YEAR
Eligibility 10th / 12th
SEMESTER - 1
-
Computer Concept & Fundamentals
-
Operating System
-
MS-Office (MS-Word, MS- Excel, MS-PowerPoint, MS-Access)
-
HTML & Front Page
-
Lab-I
SEMESTER - 2
-
Basics of Financial Accounting
-
Computerized Accounting Through Tally
-
D.T.P. (Page Maker, Corel Draw, Photoshop)
-
Computer Network & Internet
-
Lab-II
Diploma In Office Automation & Publishing
DURATION 1 YEAR
Eligibility 10th / 12th
SEMESTER - 1
-
Computer Concept & Fundamentals
-
Operating System
-
MS-Office (MS-Word, MS- Excel, MS-PowerPoint, MS-Access)
-
HTML & Front Page
-
Lab-I
SEMESTER - 2
-
Basics of Financial Accounting
-
Computerized Accounting Through Tally
-
D.T.P. (Page Maker, Corel Draw, Photoshop)
-
Computer Network & Internet
-
Lab-II
Diploma In Office Automation & Publishing
DURATION 1 YEAR
Eligibility 10th / 12th
SEMESTER - 1
-
Computer Concept & Fundamentals
-
Operating System
-
MS-Office (MS-Word, MS- Excel, MS-PowerPoint, MS-Access)
-
HTML & Front Page
-
Lab-I
SEMESTER - 2
-
Basics of Financial Accounting
-
Computerized Accounting Through Tally
-
D.T.P. (Page Maker, Corel Draw, Photoshop)
-
Computer Network & Internet
-
Lab-II
Chapter 4: Introduction to Arduino
4.1 Introduction to Arduino
• What is Arduino?
• Arduino is an open-source (खुले स्रोत) computer hardware and software platform.
• Created in 2005 by Italian engineers David Cuartielles and Massimo Banzi.
• Designed to help students learn programming and electronics for real-world applications.
• Arduino Modules:
• Arduino modules are prototyping (प्रोटोटाइपिंग) platforms based on microcontrollers.
• Boards are available in pre-assembled (पहले से तैयार) packages or as DIY kits (स्वयं बनाएं किट).
• Components of Arduino:
• Hardware (हार्डवेयर): Includes the physical board, sensors, and shields.
• Shields (शील्ड): Add-ons to extend functionality, such as Wi-Fi, motor control, camera, etc.
• Software (सॉफ़्टवेयर): Programs written using Arduino IDE in C or C++.
• Purpose of Arduino:
• Helps design, develop, and test complex electronic products and prototypes (नमूने).
• Simplifies learning for students in programming and real-world applications.
• Advantages of Arduino:
1. Open-source: Easy for users to modify and share.
2. Beginner-friendly: Pre-coded examples and libraries available.
3. Large Community: Offers help with debugging (डिबगिंग) and learning.
4. Cross-platform (क्रॉस-प्लेटफ़ॉर्म): Compatible with Windows, macOS, and Linux.
5. Affordable (किफायती): Multiple low-cost boards available.
6. Includes essential components like regulators, microcontrollers, and communication interfaces.
• Disadvantages of Arduino:
1. Tasks like scheduling and database storage require extra effort.
2. Limited processing power (प्रसंस्करण शक्ति) and memory for complex tasks.
MCQs for Section 4.1
1. Who created Arduino?
A. Steve Jobs and Bill Gates
B. David Cuartielles and Massimo Banzi
C. Dennis Ritchie and Ken Thompson
D. Elon Musk and Jeff Bezos
Answer: B. David Cuartielles and Massimo Banzi
2. What is the programming language used in Arduino IDE?
A. Python
B. C or C++
C. Java
D. Assembly
Answer: B. C or C++
3. Which of the following is NOT an advantage of Arduino?
A. Easy for beginners
B. Open-source platform
C. High processing power for advanced tasks
D. Cross-platform compatibility
Answer: C. High processing power for advanced tasks
4.2 Types of Arduino Boards
• Overview:
• Arduino boards are based on microcontrollers (माइक्रोकंट्रोलर).
• Designed for simple repetitive tasks like reading sensors, turning on LEDs, or driving robots.
• Popular Arduino Boards:
• Arduino Uno: Best for beginners, based on ATmega328 microcontroller.
• Arduino Mega: Offers more pins for complex tasks.
• Arduino Leonardo: Includes built-in USB communication features.
• Arduino Micro: A compact version suitable for tight spaces.
4.2.1 Arduino Uno
• Overview:
• Uno (उनो): Means “one” in Italian.
• Based on ATmega328 microcontroller, using 8-bit RISC architecture.
• Features:
1. Operating Voltage (ऑपरेटिंग वोल्टेज): 5V, supports external power up to 12V.
2. Digital Pins (डिजिटल पिन): 14 (used for input/output tasks).
3. Analog Pins (एनालॉग पिन): 6 (labeled A0 to A5).
4. Clock Speed (क्लॉक गति): 16 MHz.
5. Flash Memory (फ्लैश मेमोरी): 32 KB for storing code.
6. SRAM: 2 KB (used for temporary storage).
7. Power Supply Options: USB, AC-to-DC adapter, or battery.
• Additional Components:
• GND Pins (ग्राउंड पिन): Stabilize voltage (वोल्टेज स्थिर करते हैं).
• Voltage Regulator (वोल्टेज नियामक): Protects board from over-voltage.
• USB Interface (यूएसबी इंटरफेस): Enables program uploads using Arduino IDE.
Example:
Arduino Uno can control an LED light based on temperature sensor data.
MCQs for Section 4.2
1. What is the microcontroller used in Arduino Uno?
A. ATmega2560
B. ATmega328
C. ATmega128
D. ATmega32
Answer: B. ATmega328
2. What is the operating voltage of Arduino Uno?
A. 3.3V
B. 5V
C. 9V
D. 12V
Answer: B. 5V
3. Which Arduino board is compact and suitable for tight spaces?
A. Arduino Mega
B. Arduino Leonardo
C. Arduino Micro
D. Arduino Uno
Answer: C. Arduino Micro
4. What is the clock speed of Arduino Uno?
A. 8 MHz
B. 16 MHz
C. 32 MHz
D. 64 MHz
Answer: B. 16 MHz
5. Which of the following is a disadvantage of Arduino?
A. Easy to use for beginners
B. Affordable and open-source
C. Limited processing power
D. Wide variety of boards
Answer: C. Limited processing power
Input and Output (I/O) Pins of Arduino
The pins on an Arduino board are the connection points where wires are connected to build circuits. Each pin is labeled and has specific functions, making it easier to construct and program circuits.
1. Digital and Analog Pins
• Digital Pins:
• Total: 14 pins (numbered 0–13), including special pins TX (1) and RX (0).
• Functionality:
• Can be configured as input (to read signals) or output (to send signals).
• Controlled by functions like:
• pinMode(): Set a pin as input or output.
• digitalWrite(): Write a HIGH or LOW signal to the pin.
• digitalRead(): Read the HIGH or LOW state of a pin.
• Operate at 5V.
• Example:
• Detecting a button press (input).
• Turning an LED ON or OFF (output).
• Analog Pins:
• Total: 6 pins (labeled A0–A5).
• Functionality:
• Read signals from analog sensors (e.g., temperature sensors).
• Convert analog signals into digital values using a 10-bit Analog-to-Digital Converter (ADC).
• Example:
• Reading the temperature and converting it to a digital value.
2. Special Types of Pins
2.1 GND (Ground) Pins:
• These are used to ground a circuit.
• Multiple GND pins are available, and any of them can be used to complete the circuit.
2.2 Serial Pins:
• Pins 0 (RX) and 1 (TX) are used for serial communication.
• RX (Receive): Receives data.
• TX (Transmit): Sends data.
• These pins are connected to the USB port for communication with a computer.
• Indicated by TX and RX LEDs, which blink during data transfer.
2.3 PWM (Pulse-Width Modulation) Pins:
• Pins 3, 5, 6, 9, 10, and 11, marked with a tilde (~), are PWM-enabled.
• Functionality:
• Simulate analog output by varying signal intensity (e.g., fading an LED).
• Use the analogWrite() function for PWM output.
• PWM signal is a square wave with varying HIGH and LOW durations.
2.4 SPI (Serial Peripheral Interface) Pins:
• Pins 10, 11, 12, and 13 are used for SPI communication.
• SPI enables fast communication between devices using four wires:
• SS (Slave Select): Activates the target device.
• MOSI (Master Output/Slave Input): Sends data from master to slave.
• MISO (Master Input/Slave Output): Sends data from slave to master.
• SCK (Serial Clock): Synchronizes the communication.
• Supports full duplex communication, allowing simultaneous data transmission and reception.
2.5 TWI (Two-Wire Interface) Pins:
• Pins A4 (SDA) and A5 (SCL) enable I²C communication using the Wire library.
• SDA (Serial Data): Transfers data.
• SCL (Serial Clock): Provides synchronization.
2.6 Built-in LED Pin:
• A built-in LED is connected to Pin 13.
• Behavior:
• LED turns ON when Pin 13 is set to HIGH.
• LED turns OFF when Pin 13 is set to LOW.
• Automatically lights up when the Arduino is powered.
2.7 AREF (Analog Reference) Pin:
• Sets an external reference voltage for analog pins.
• Can range between 0V to 5V.
• Configured using the analogReference() function to adjust the upper limit for analog readings.
2.8 Reset Pin:
• Resets the microcontroller when pulled LOW.
• Used to restart the program running on the Arduino.
3. Summary of Pin Types on Arduino Uno
Pin Type Count Purpose
Digital Pins 14 Input/output (e.g., control LEDs or read button presses)
Analog Pins 6 Read analog signals from sensors (e.g., temperature)
GND (Ground) Pins Multiple Complete the circuit and stabilize voltages
PWM Pins 6 Simulate analog outputs (e.g., dimming LEDs)
Serial Pins (RX/TX) 2 Communicate with computers or other devices
SPI Pins 4 High-speed device-to-device communication
TWI Pins 2 I²C communication using the Wire library
AREF Pin 1 Set an external reference voltage for analog readings
Reset Pin 1 Reset the Arduino microcontroller
MCQs for Input and Output Pins
1. How many digital pins are there on Arduino Uno?
A. 6
B. 12
C. 14
D. 16
Answer: C. 14
2. Which pins are used for PWM on Arduino Uno?
A. 2, 3, 4, 5
B. 3, 5, 6, 9, 10, 11
C. A0, A1, A2
D. 10, 11, 12, 13
Answer: B. 3, 5, 6, 9, 10, 11
3. What is the purpose of the Reset pin on Arduino Uno?
A. Set pins HIGH
B. Turn the board OFF
C. Restart the microcontroller
D. Transmit data
Answer: C. Restart the microcontroller
4. Which pins are used for SPI communication?
A. A4 and A5
B. 10, 11, 12, 13
C. 0 and 1
D. 3, 5, 6
Answer: B. 10, 11, 12, 13
5. Which function sets a digital pin as input or output?
A. digitalWrite()
B. pinMode()
C. analogRead()
D. reset()
Answer: B. pinMode()
4.2.2 Arduino Leonardo
• Microcontroller: ATmega32u4.
• Key Feature: First Arduino board with a built-in USB interface.
• Advantages:
• Eliminates the need for an external USB-to-serial adapter.
• Can function as a keyboard, mouse, or other USB device.
• Best For: Entry-level projects requiring USB communication.
4.2.3 Arduino 101
• Microcontroller: 32-bit Intel Curie.
• Features:
• Bluetooth LE (Low Energy): For wireless communication.
• 6-axis accelerometer and gyroscope: Ideal for motion-detection projects.
• Best For: Projects involving wireless communication and motion sensing.
4.2.4 Arduino Esplora
• Microcontroller: ATmega32u4 (same as Leonardo).
• Key Feature: Pre-loaded with integrated sensors and actuators.
• Built-in Functions:
• Sensors: Light, temperature, joystick, microphone, etc.
• Actuators: Buzzer and RGB LEDs.
• Can emulate a mouse or keyboard.
• Best For: Interactive projects and sensor-based applications.
4.2.5 Arduino Mini/Mini Lite
• Microcontroller: ATmega168.
• Features:
• Size: Smallest Arduino board without pre-soldered connectors.
• Pins: 8 analog pins, 14 digital pins.
• Best For: Compact projects requiring minimal space.
4.2.6 Arduino Micro
• Microcontroller: ATmega32u4.
• Features:
• Built-in USB interface for direct connection to computers.
• Compact and breadboard-compatible.
• Best For: Interactive and compact computing projects.
4.2.7 Arduino Nano
• Microcontroller: ATmega328.
• Features:
• Breadboard-compatible with USB to serial communication onboard.
• Pins: 8 analog pins, 14 digital pins.
• Variants: Arduino Nano Lite (no downward-facing pin headers).
• Best For: Small-scale projects and breadboard prototyping.
4.2.8 Arduino Mega
• Microcontroller: ATmega2560.
• Features:
• Large number of digital (54) and analog (16) pins.
• USB connection, power jack, and reset button.
• Best For: Large-scale projects requiring multiple input/output connections.
4.2.9 Arduino Zero
• Microcontroller: ATSAMD21G18.
• Features:
• Provides 32-bit capabilities.
• Operates at 3.3V (maximum voltage tolerance for I/O pins is 3.3V).
• Best For: Advanced applications requiring 32-bit processing.
4.2.10 Arduino M0 Pro
• Microcontroller: ATSAMD21G18.
• Key Feature: Equipped with Atmel Embedded Debugger (EDBG) for on-board debugging.
• Best For: Professional-level debugging and programming.
4.2.11 Arduino Yun
• Microcontroller: ATmega32U4 with an additional Linux-based processor.
• Key Feature: Combines Linux OS with Arduino functionality.
• Best For: IoT (Internet of Things) applications.
4.2.12 Arduino Industrial 101
• Microcontroller: ATmega32u4.
• Features:
• Designed for industrial-grade applications.
• Multiple communication facilities (computer, other Arduino boards, or microcontrollers).
• Best For: Evaluation boards and industrial setups.
4.2.13 Arduino Tian
• Microcontroller: Combines a 32-bit microcontroller with a Linux-based computer.
• Best For: High-performance IoT applications.
4.2.14 LilyPad Arduino USB
• Microcontroller: ATmega32u4.
• Features:
• Built-in USB communication.
• Designed for e-textiles and wearable technology.
• Best For: Fashion-tech projects involving conductive threads.
4.2.15 LilyPad Arduino Main Board
• Microcontroller: ATmega168V or ATmega328V.
• Features:
• Large connection pads for sewing into fabric.
• Supports input, output, power, and sensor modules.
• Best For: Wearable and e-textile applications.
4.2.16 Arduino Clones
• What are Clones?
• Low-cost alternatives to official Arduino boards.
• Compatible with Arduino software and hardware.
• Examples: Freeduino.
• Use Case: Budget-friendly projects.
4.2.17 How to Power Arduino Uno
1. USB Power:
• Connect the board to a PC using a USB cable.
• Used for both programming and powering the board.
• Compatible with standalone 5V USB power supplies.
2. External Power Supply:
• Use an AC-to-DC adapter or battery.
• Voltage range: 7–12V (recommended), maximum 20V.
3. Power Jack:
• Connect an external power source directly via the power jack.
4. Vin Pin:
• Provides input voltage to the board when not powered via USB.
MCQs for Arduino Boards
1. Which Arduino board has built-in USB communication?
A. Arduino Mega
B. Arduino Leonardo
C. Arduino Yun
D. Arduino Mini
Answer: B. Arduino Leonardo
2. Which microcontroller is used in Arduino Nano?
A. ATmega32u4
B. ATmega328
C. ATSAMD21G18
D. ATmega2560
Answer: B. ATmega328
3. What is a unique feature of the Arduino Yun?
A. Built-in Bluetooth LE
B. Combines Linux OS with Arduino
C. Uses ATmega328 microcontroller
D. Smallest board in the Arduino family
Answer: B. Combines Linux OS with Arduino
4. Which Arduino board is specifically designed for wearable projects?
A. Arduino Nano
B. Arduino Esplora
C. LilyPad Arduino USB
D. Arduino Mega
Answer: C. LilyPad Arduino USB
5. Which microcontroller is used in Arduino Zero?
A. ATmega32u4
B. ATSAMD21G18
C. ATmega2560
D. ATmega328
Answer: B. ATSAMD21G18
1. Blinking an LED
Task: Write a program to blink the built-in LED on the Arduino board with a delay of 2 seconds.
Solution:
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED pin as an output
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED on
delay(2000); // Wait for 2 seconds
digitalWrite(LED_BUILTIN, LOW); // Turn the LED off
delay(2000); // Wait for 2 seconds
}
Explanation:
• pinMode(LED_BUILTIN, OUTPUT); sets the built-in LED pin as an output.
• In the loop(), the LED is turned on and off with a 2-second delay between each state, creating a blinking effect.
2. LED Control with Push Button
Task: Interface an LED with a push button. The LED should turn on when the button is pressed and turn off when released.
Solution:
const int buttonPin = 2; // Pin connected to the button
const int ledPin = 13; // Pin connected to the LED
void setup() {
pinMode(buttonPin, INPUT); // Set button pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
}
void loop() {
int buttonState = digitalRead(buttonPin); // Read the state of the button
if (buttonState == HIGH) { // If button is pressed
digitalWrite(ledPin, HIGH); // Turn LED on
} else {
digitalWrite(ledPin, LOW); // Turn LED off
}
}
Explanation:
• digitalRead(buttonPin); reads the button’s state.
• If the button is pressed (HIGH), the LED turns on; otherwise, it turns off.
3. Fading an LED
Task: Write a program to fade an LED in and out using PWM.
Solution:
const int ledPin = 9; // Pin connected to the LED
void setup() {
pinMode(ledPin, OUTPUT); // Set LED pin as output
}
void loop() {
for (int brightness = 0; brightness <= 255; brightness++) { // Increase brightness
analogWrite(ledPin, brightness);
delay(10);
}
for (int brightness = 255; brightness >= 0; brightness--) { // Decrease brightness
analogWrite(ledPin, brightness);
delay(10);
}
}
Explanation:
• analogWrite(ledPin, brightness); sets the LED brightness using PWM.
• The loops gradually increase and then decrease the brightness, creating a fading effect.
4. Temperature Monitoring with LM35 Sensor
Task: Interface an LM35 temperature sensor with Arduino and display the temperature on the serial monitor.
Solution:
const int sensorPin = A0; // Pin connected to the sensor
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int sensorValue = analogRead(sensorPin); // Read the analog value
float voltage = sensorValue * (5.0 / 1023.0); // Convert to voltage
float temperatureC = voltage * 100.0; // Convert to temperature in Celsius
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");
delay(1000); // Wait for 1 second
}
Explanation:
• analogRead(sensorPin); reads the sensor’s analog value.
• The value is converted to voltage and then to temperature in Celsius.
• The temperature is displayed on the serial monitor.
5. Motion Detection with PIR Sensor
Task: Interface a Passive Infrared (PIR) sensor with Arduino to detect motion and light up an LED when motion is detected.
Solution:
const int pirPin = 2; // Pin connected to PIR sensor output
const int ledPin = 13; // Pin connected to LED
void setup() {
pinMode(pirPin, INPUT); // Set PIR pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int motionState = digitalRead(pirPin); // Read PIR sensor state
if (motionState == HIGH) { // If motion is detected
digitalWrite(ledPin, HIGH); // Turn LED on
Serial.println("Motion Detected");
} else {
digitalWrite(ledPin, LOW); // Turn LED off
Serial.println("No Motion");
}
delay(500); // Wait for half a second
}
Explanation:
• digitalRead(pirPin); checks for motion detection.
• If motion is detected (HIGH), the LED turns on and a message is printed to the serial monitor; otherwise, the LED remains off.
6. Light-Dependent LED Control
Task: Use a Light Dependent Resistor (LDR) to control an LED. The LED should turn on in darkness and off in light.
Solution:
const int ldrPin = A0; // Pin connected to LDR
const int ledPin = 13; // Pin connected to LED
int threshold = 500; // Threshold value for light intensity
void setup() {
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int ldrValue = analogRead(ldrPin); // Read LDR value
Serial.print("LDR Value: ");
Serial.println(ldrValue);
if (ldrValue < threshold) { // If it's dark
digitalWrite(ledPin, HIGH); // Turn LED on
} else {
digitalWrite(ledPin, LOW); // Turn LED off
}
delay(500); // Wait for half a second
}
Explanation:
• analogRead(ldrPin); reads the light intensity.