Arduino Level 2
Arduino Level 2
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.
•
•
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
// 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() {
void loop() {
[Link](); // Clear the display to remove any previous text
[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)
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); }
• 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]
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.
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:
// 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);
}