Arduino Practical File (1)
Arduino Practical File (1)
ON
JOURNAL
IN THE COURSE
Arduino
SUBMITTED BY
Name: Priyanshu Kanaujiya
SEMESTER III
UNDER THE GUIDANCE OF
Asst. Prof. Dr. Janhavi Raut
ACADEMIC YEAR
2024 - 2025
CERTIFICATE
● Description: LEDs are semiconductor devices that emit light when an electric current
passes through them.
● Use: Commonly used as indicators in circuits to show the status of a system, such as
power on, error states, etc.
5. Resistor
● Description: A resistor is a passive electrical component that limits the flow of electric
current in a circuit.
● Use: Essential for controlling current, protecting components like LEDs from damage
due to excessive current.
6. Jumper Wires
● Description: Jumper wires are short, insulated wires used to connect components on a
breadboard or to establish connections between the breadboard and the Arduino.
● Use: Used for making temporary connections during prototyping.
7. Temperature Sensor
● Description: A device that measures temperature and converts it into a signal that can
be read by the microcontroller.
● Example: The LM35 is a common temperature sensor that provides an analog output
proportional to the temperature.
● Use: Used in projects where temperature monitoring or control is necessary.
8. Gas Sensor
● Description: A gas sensor detects the presence of gases in an area and provides an
output that can be used to trigger an alarm or log data.
● Example: The MQ series (like MQ-2, MQ-7) sensors are commonly used to detect
gases like methane, carbon monoxide, etc.
● Use: Essential in safety and environmental monitoring projects.
9. Ultrasonic Sensor
● Description: An IR sensor detects infrared light reflected from objects and can be used
to measure distance or detect objects.
● Use: Common in remote control systems, proximity detection, and line-following robots.
● Description: A moisture sensor measures the water content in the soil or another
substance.
● Use: Often used in automated irrigation systems to maintain optimal soil moisture levels.
12. Buzzer
● Description: A buzzer is an audio signaling device that converts electrical signals into
sound.
● Use: Used to provide audio feedback, alerts, or alarms in various embedded projects.
● Description: A servo motor is a rotary actuator that allows precise control of angular
position, typically using feedback control.
● Use: Commonly used in robotics, automation systems, and any project requiring precise
movement control.
Practical 2
1.Single LED:
Code :
Output :
Multiple LED :
Code :
int LED=8;
int led=2;
int Led=13;
int LEd=12;
int LeD=7;
void setup()
{
pinMode( LED, OUTPUT);
pinMode( led, OUTPUT);
pinMode( 13, OUTPUT);
pinMode( 12, OUTPUT);
pinMode( 7, OUTPUT);
void loop()
{
digitalWrite( LED, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
Output :
Practical 3
Code :
int LED = 13;
int BUZZ = 3;
const int gas = 0;
int MQ2pin = A0;
void setup() {
pinMode(LED,OUTPUT);
pinMode(BUZZ,OUTPUT);
}
void loop() {
float sensorValue,MQ2pin;
sensorValue = analogRead(MQ2pin);
if(sensorValue >= 270){
digitalWrite(LED,HIGH);
digitalWrite(BUZZ,HIGH);
}
else{
digitalWrite(LED,LOW);
digitalWrite(BUZZ,LOW);
}
delay(500);
}
float getsensorValue(int pin){
return (analogRead(pin));
}
Output :
Practical 4
Create an Arduino project for reading a temperature sensor and
displaying the temperature on an LCD. The buzzer gives an alert
if the temperature exceeds 80°C.
Code :
#include <Adafruit_LiquidCrystal.h> // Include the Adafruit library for
LCD
int sensorPin = 0; // Analog pin for temperature sensor
const int buzzer = 9; // Buzzer connected to digital pin 9
Adafruit_LiquidCrystal lcd_1(0); // Create an LCD object with I2C
address 0
void setup()
{
lcd_1.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
pinMode(buzzer, OUTPUT); // Set pin 9 as an output for the buzzer
}
void loop()
{
lcd_1.clear(); // Clear the LCD display
int reading = analogRead(sensorPin); // Read the analog value from
the sensor
float voltage = reading * 5.0 / 1024.0; // Convert the reading to a
voltage
float temperatureC = (voltage - 0.5) * 100; // Convert the voltage to
Celsius
lcd_1.setCursor(0, 1); // Set the cursor to the second row
lcd_1.print(temperatureC); // Display the temperature on the LCD
lcd_1.println(" degrees C "); // Add "degrees C" to the display
delay(1000); // Wait for 1 second
if(temperatureC > 30) // If the temperature exceeds 30 degrees
Celsius
{
tone(buzzer, 1000); // Sound the buzzer at 1KHz
delay(1000); // Keep the buzzer on for 1 second
noTone(buzzer); // Turn off the buzzer
delay(1000); // Wait for 1 second
}
}
Output :
Practical 5
Create an Arduino project for an ultrasonic Sensor to measure
the distance to an object.
Code :
int trigPin = 10; // Define pin 10 for the trigger pin of the ultrasonic
sensor
int echoPin = 9; // Define pin 9 for the echo pin of the ultrasonic
sensor
long time; // Variable to store the time it takes for the echo to
return
float distance; // Variable to store the calculated distance
void setup() {
pinMode(trigPin, OUTPUT); // Set the trigger pin as an output
pinMode(echoPin, INPUT); // Set the echo pin as an input
Serial.begin(9600); // Initialize serial communication at 9600 baud
rate
}
void loop() {
// Ensure the trigger pin is low before sending a pulse
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
Code :
int pir_pin = 12; // Define pin 12 for the PIR sensor
int buzzer_pin = 2; // Define pin 2 for the buzzer
void setup()
{
pinMode(pir_pin, INPUT); // Set the PIR sensor pin as an input
pinMode(buzzer_pin, OUTPUT); // Set the buzzer pin as an output
}
void loop()
{
int motion = 0; // Initialize a variable to store the motion status
motion = digitalRead(pir_pin); // Read the PIR sensor status
if (motion == HIGH) { // If motion is detected
digitalWrite(buzzer_pin, HIGH); // Turn on the buzzer
}
else
{ // If no motion is detected
digitalWrite(buzzer_pin, LOW); // Turn off the buzzer
}
delay(15);
}
Output :
Practical 7
Create an Arduino program to detect motion using PIR
sensor and then perform specific action when motion is
detected using a servo motor.
Code :
#include <Servo.h> // Include the Servo library
Output :
Practical 8
Create an Arduino program with a moisture sensor to
measure the amount of moisture (water content) present
in the soil and supply the water required using a DC
motor.
Code :
const int motor = 13; // Motor connected to digital pin 13
const int Led = 12; // LED connected to digital pin 12
int percentValue = 0; // Variable to store percentage value (not used in
the current code)
void setup() {
pinMode(motor, OUTPUT); // Set pin 13 as an output for the motor
pinMode(Led, OUTPUT); // Set pin 12 as an output for the LED
delay(2000); // Wait for 2 seconds
}
void loop() {
int value = analogRead(A0); // Read the analog value from pin A0
float Moisture = value * 500.0 / 1023.0; // Convert the reading to a
moisture level
Output :
Practical 9
Create an Arduino project to use of IR Sensor (Infrared Sensor).
Code :
const int irSensor=2; //define pin where sensor's out pin is connected
int LED = 13;
int led = 8;
int BUZZ = 7;
void setup() {
Serial.begin(9600); // set the baud rate for serial communication
pinMode(irSensor,INPUT); //set sensor pin as input to receive data
from the pin
pinMode(13, OUTPUT);
pinMode(8, OUTPUT);
pinMode(BUZZ,OUTPUT);
void loop() {
Output :
Practical 10
Create an Arduino project to use of Force Sensor.
Code :
#define fsrpin A0
#define led1 2
#define led2 3
#define led3 4
#define led4 5
#define led5 6
#define led6 7
int fsrreading;
void setup() {
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
}
void loop() {
fsrreading = analogRead(fsrpin);
Serial.println(fsrreading);
if (fsrreading > 200) {
digitalWrite(led1, HIGH);
}
else digitalWrite(led1, LOW);
if (fsrreading > 450) {
digitalWrite(led2, HIGH);
}
else digitalWrite(led2, LOW);
if (fsrreading > 550) {
digitalWrite(led3, HIGH);
}
else digitalWrite(led3, LOW);
if (fsrreading > 650) {
digitalWrite(led4, HIGH);
}
else digitalWrite(led4, LOW);
if (fsrreading > 800) {
digitalWrite(led5, HIGH);
}
else digitalWrite(led5, LOW);