0% found this document useful (0 votes)
27 views41 pages

Arduino Level 2

The document discusses fundamental concepts in electronics and programming, including input/output definitions, digital and analog signals, and common Arduino functions. It outlines a hands-on project for building a home automation system using an Arduino and IR remote, emphasizing skills in reading IR signals and programming conditional responses. Additionally, it introduces the use of libraries in Arduino programming to simplify hardware access.

Uploaded by

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

Arduino Level 2

The document discusses fundamental concepts in electronics and programming, including input/output definitions, digital and analog signals, and common Arduino functions. It outlines a hands-on project for building a home automation system using an Arduino and IR remote, emphasizing skills in reading IR signals and programming conditional responses. Additionally, it introduces the use of libraries in Arduino programming to simplify hardware access.

Uploaded by

inevertry5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

BY: JUNDHEL MAYOR

Input - Information or signals that are received by a system are referred to as input.

Output - The term "output" describes the data or signals produced by a system
and transmitted to the outside world.
Digital – The information is recorded using a finite number of different states,
commonly two: high and low, or 1 and 0.

Analog - The information included in continuous analog signals or data varies within
a range of values.
Read – describes the process of obtaining data from a source, such as a network
connection, user input, sensor, or file.

Write – It is referred to as this to save or output data to a destination, such as a file, a


display, a network connection, or a database.
Pulse width modulation (PWM) is a method that is frequently used in electronics
and microcontroller programming, including Arduino. It enables you to quickly switch
the power on and off at a set frequency in order to produce analog-like outputs.
You can alter the component's average voltage or brightness by changing the width
of the pulse's on-time (duty cycle).
Commonly used functions in
programming Arduino Uno board

Function Purpose Syntax Returns / Effect


Set pin as input or pinMode(variable, Sets mode: INPUT,
pinMode() output mode); OUTPUT
Write HIGH or LOW to digitalWrite(variable, Sets pin voltage to 0V
digitalWrite() digital output pin HIGH); or 5V
Read HIGH or LOW from int val =
digitalRead() digital input pin digitalRead(varaible);
Returns HIGH or LOW

Read analog voltage (0– int val =


analogRead() 5V) as integer analogRead(variable);
Returns 0–1023

Output PWM signal analogWrite(variable, Sets PWM: value 0–


analogWrite() (simulate analog output) value); 255



[Link]
[Link]
[Link]
[Link]
[Link]
[Link]

// Include the IRremote library void loop() {


#include <IRremote.h> // Check if an IR signal has been
received
// Define which Arduino pin is connected to the signal
pin of the IR receiver if ([Link]())
const int RECV_PIN = 11; {
// Print the received IR code in
// Create an IRrecv object to receive signals hexadecimal format
IRrecv irrecv(RECV_PIN); [Link]("IR Code Received:
0x");
// Structure to store the decoded results
decode_results results; [Link]([Link]
[Link], HEX);
void setup() {
// Start the serial monitor for debugging at 9600 baud // Resume receiving the next
[Link](9600); signal
[Link]();
// Initialize the IR receiver }
[Link](RECV_PIN); // For IRremote v3.0 and }
above
}
[Link]
[Link]
[Link]

#include <IRremote.h> void loop() {


// Check if an IR signal has been received
// Define pin for IR receiver if ([Link]()) {
// Print the raw hex value of the received code
signal line
unsigned long code = [Link];
const int RECV_PIN = 11;
// Check for specific codes (replace these with your own codes)
// Create an IRrecv object and if (code == 0xBA45FF00) { // Example: "CH-" button
result container [Link]("CH- Pressed");
IRrecv irrecv(RECV_PIN); }
decode_results results; else if (code == 0xB946FF00) { // Example: "CH" button
[Link]("CH Pressed");
void setup() { }
else if (code == 0xB847FF00) { // Example: "CH+" button
// Initialize serial monitor for [Link]("CH+ Pressed");
debugging }
[Link](9600);
// Begin receiving IR signals // Resume to receive the next signal
[Link](RECV_PIN); [Link]();
} }
}
[Link]
[Link]
[Link]

#include <IRremote.h> void loop() {


// Check if an IR signal has
// Define the pin where your IR receiver signal been received
pin is connected
const int RECV_PIN = 11;
if ([Link](&results)) {
// Create an instance of the IRrecv class // Print the raw hexadecimal
IRrecv irrecv(RECV_PIN); value of the IR code
[Link]("IR Code
// Create a container to store the received IR Received: 0x");
code [Link]([Link],
decode_results results; HEX);

void setup() { // Resume listening for the


[Link](9600); // Start the serial
next code
monitor
[Link]();
[Link](); // Start the IR receiver
} }
[Link]
[Link]
[Link]

In this hands-on project, participants will build a simple home


automation system using an Arduino, IR remote, LEDs, and a
buzzer. By programming the Arduino to respond to different
buttons on the IR remote, participants will control three
• Arduino Uno (or compatible
individual LEDs and a buzzer. The project helps participants
board)
understand how to use IR signals, decode remote control
• IR receiver module
commands, and use conditional programming to perform specific • IR remote control
actions based on user input. • LEDs (any color)
This activity develops skills in: • 220-ohm resistors (for
• Reading IR remote signals LEDs)
• Programming conditional responses • Buzzer (active or passive)
• Digital output control with LEDs and buzzers • Breadboard
• Circuit design and debugging • Jumper wires
• USB cable for Arduino
• I2C
// Include the LiquidCrystal_I2C library to use the I2C LCD display
#include <LiquidCrystal_I2C.h>

// Initialize the LCD object with the I2C address (0x27), screen width (16 columns), and height (2 rows)
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);

void setup() {

[Link](); // Turn on the backlight of the LCD display


[Link](); // Initialize the LCD display

void loop() {
[Link](); // Clear the display to remove any previous text

delay(1000); // Wait for 1 second (1000 milliseconds)

[Link](2, 0); // Set the cursor to the top-left corner of the LCD (row 0, column 0)

[Link](“Arduino 2"); // Print “Arduino 2" on the first line of the LCD

[Link](2, 1); // Set the cursor to the beginning of the second row (row 1, column 0)

[Link](“Training"); // Print “Training" on the second line of the LCD

delay(1000); // Wait for 1 second before repeating


}
It allows you to call functions that are already written, library contains
all of the raw code to access the hardware, all we need to do is initialize
it and call the functions. A library does all the heavy lifting so you can
use your modules quickly and easily.
[Link]
[Link]
[Link]

Smart Emergency Alert System Using


Arduino
In a busy hospital, every second counts—especially
during an emergency. Imagine a patient suddenly
struggling to breathe or a nurse needing urgent backup in
an isolated ward. In well-equipped hospitals, emergency
alert systems are installed to call for immediate help. But • Arduino Uno (or compatible
in many small clinics, rural hospitals, or crowded board)
• LEDs (any color)
emergency rooms, there may be no such system in • 220-ohm resistors (for
place—or it may not work fast enough. LEDs)
• Buzzer (active or passive)
Now think of this: What if someone’s life depended on • Breadboard
just the push of a button? • Jumper wires
• USB cable for Arduino
• I2C
[Link]
[Link]
[Link]

Wiring
• LM35: Vcc to 5V
• GND to GND,
• Vout to A0
// Define the analog pin where the TMP36 // Convert the voltage to temperature in Celsius
sensor is connected // TMP36
int sensorPin = A0; float temperatureC = (voltage - 0.5) * 100.0;
// LM35
void setup() { float temperatureC = voltage * 100.0;
// Start serial communication at 9600
bits per second // Print the temperature to the Serial Monitor
[Link](9600); [Link]("Temp: ");
} [Link](temperatureC);
[Link](" C");
void loop() {
// Read the analog value from the sensor // Wait 1 second before taking another reading
(0–1023) delay(1000);
int sensorValue = analogRead(sensorPin); }

// Convert the analog value to voltage


(assuming 5V reference)
float voltage = sensorValue * 5.0 / 1023.0;
COMPONENTS
[Link]
[Link]
[Link]

• Arduino Uno – 1
• LM35 temperature
sensor – 1
• I2C LCD (16x2) – 1
• LED – 1
• 220Ω resistor – 1
(for the LED)
• Breadboard – 1
• Jumper wires – 8
to 10
• USB cable – 1 (to
upload code)
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]

int LDR = A0; //LDR connected to analog pin A0


int ldrValue = 0; // Variable to store LDR value

void setup() {
[Link](9600); // Initialize serial
communication
pinMode(LDR, INPUT); // Set LDR pin as input
}
void
loop() {
ldrValue = analogRead(LDR); // Read LDR value
from analog pin
[Link]("LDR Value: "); // Print label
[Link](ldrValue); // Print value
delay(500); // Delay for readability
}
The LDR acts as a light sensor, detecting the
[Link]
[Link]
[Link] intensity of light in the environment. When the
surrounding light falls below a certain threshold
(e.g., it becomes dark), the Arduino turns on the
LED. Conversely, when the light is sufficient, the LED
turns off. This basic automation can be applied in
night lights, smart lighting systems, and energy-
saving applications.

int LDR= A0; // LDR connected to analog pin A0


int ldrValue = 0; // Variable to store LDR value
int led=3;

void setup()
{
[Link](9600); // Initialize serial comm
pinMode(LDR, INPUT); // Set LDR pin as input
pinMode(led,OUTPUT);
}
Ultrasonic Sensor
Wiring the HC-SR04 Ultrasonic Sensor to
Arduino:

VCC → 5V pin on Arduino (Provides power to


the sensor)

GND → GND pin on Arduino (Ground)

Trigger (TRIG) → Pin 9 on Arduino (You can


choose another digital pin if needed)

Echo (ECHO) → Pin 10 on Arduino (You can


choose another digital pin if needed)
// Define pin numbers for the ultrasonic void loop() {
sensor // Clear the trigPin by setting it LOW
digitalWrite(trigPin, LOW);
const int trigPin = 9; // Trigger pin delayMicroseconds(2);
const int echoPin = 10; // Echo pin
// Send a 10-microsecond pulse to trigger the ultrasonic
// Define variable to store the duration and sensor
distance digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
long duration; digitalWrite(trigPin, LOW);
int distance;
// Read the pulse duration from the echoPin
void setup() { duration = pulseIn(echoPin, HIGH);
// Start serial communication
// Calculate the distance (in centimeters)
[Link](9600); distance = duration * 0.0344 / 2;

// Set the trigPin as an OUTPUT // Display the distance on the Serial Monitor
pinMode(trigPin, OUTPUT); [Link]("Distance: ");
[Link](distance);
[Link](" cm");
// Set the echoPin as an INPUT
pinMode(echoPin, INPUT); // Wait for a short period before taking the next measurement
} delay(500);
}

You might also like