0% found this document useful (0 votes)
14 views7 pages

Arduino Practical

The document outlines two experiments using Arduino UNO: the first involves programming an LED to blink at regular intervals, while the second interfaces an ultrasonic sensor with a servo motor to control its rotation based on distance measurements. Key components include the Arduino board, LED, resistor, ultrasonic sensor, and servo motor, with detailed procedures and code provided for each experiment. Learning outcomes emphasize understanding digital input/output operations and sensor interfacing with motors.

Uploaded by

sumitgautam970
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)
14 views7 pages

Arduino Practical

The document outlines two experiments using Arduino UNO: the first involves programming an LED to blink at regular intervals, while the second interfaces an ultrasonic sensor with a servo motor to control its rotation based on distance measurements. Key components include the Arduino board, LED, resistor, ultrasonic sensor, and servo motor, with detailed procedures and code provided for each experiment. Learning outcomes emphasize understanding digital input/output operations and sensor interfacing with motors.

Uploaded by

sumitgautam970
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
You are on page 1/ 7

Non-conventional & Automated Manufacturing Techniques

Experiment No. 1
Aim: To write and upload an Arduino program that makes an LED blink at regular intervals using
digital output pin of an Arduino UNO board.
Materials and Equipment’s:
• Arduino UNO board
• LED
• 220Ω Resistor
• Jumper wires
• Breadboard
• USB Cable (to connect Arduino to PC)

Theory:
The Arduino is used to control LED by sending a digital signal to a pin, which turns it on and off
in a repeating pattern to create a blinking effect. The Arduino’s digital pin is configured as an
output, which can then be set to high (5V) to illuminate the LED or low (0V) to turn it off. A
crucial component is resistor in the circuit to limit the current and prevent LED from burning out.
The entire process is managed by the Arduino’s basic program structure, consisting of setup ( )
and loop ( ) functions. Some important concepts includes:

i. Digital output: The Arduino can send digital signals (high or low) to control components
like LEDs.
ii. LEDs: An LED is a diode that emits light when a forward voltage is applied across its P-
N junction. Forward voltage is defined as the amount of voltage required to allow current
to flow across a diode.
iii. Resistor: LEDs require a specific current to operate. A resistor is used to regulate this
current and protect LED from excessive voltage.
iv. Arduino’s Functions:
setup ( ): This function runs once when the Arduino starts and used to set a digital pin as
an output.
loop ( ): This function runs repeatedly, controlling the LED’s behavior.
digitalWrite ( ): This command sends a high or low signal to a specified pin.
delay ( ): This function pauses the program for a specified number of milliseconds,
controlling the blinking speed.

Procedure: The following steps are desired:

1. Connect the Arduino to your computer via USB


2. Insert the LED into a breadboard, ensuring the longer legs (anode, positive) is in one row
and the shorter leg (cathode, negative) is in another.
3. Place the resistor so one end is connected to the same breadboard row as the LEDs anode.
4. Connect a jumper wire from the other end of the resistor to Arduino digital pin 13.
5. Connect a jumper wire from the LEDs cathode to the Arduino’s GND (ground) pin.
6. Select the correct Arduino board and COM port in the Arduino IDE.
7. Upload the code to the Arduino board.
8. The LED connected to pin 13 will now blink on and off every second.

Program code:

// C++ code
//
int ledPin=13;// definition digital 13 pin to control LED
void setup ( )
{
pinMode(ledPin, OUTPUT);
}

void loop ( )
{
digitalWrite (ledPin, HIGH);// Turn LED on
delay (100); // Wait for 100 millisecond(s)
digitalWrite (ledPin, LOW);// Turn LED off
delay (100); // Wait for 100 millisecond(s)
}

Fig.1. LED blinking circuit setup using Arduino Uno


Observations: LED blinks for a duration of 100 milliseconds indicating successful digital input
and output interfacing using Arduino.
Results:
The Arduino program was successfully uploaded and complied to make the LED blink at regular
intervals using the digital output pin of the Arduino Uno board.

Learning Outcomes:
• Understand digital input (button) and output (LED) operations.
• Use internal pull-up resistors in Arduino
• Develop logic to control external devices based on input signals.

Precautions:
• Ensure the correct polarity of the LED
• Verify the resistor values before connection
• Avoid short circuits while wiring on the breadboard
Experiment No. 2
Aim: To interface an ultrasonic sensor (HC-SR04) with a servo motor using Arduino UNO and
program the system to rotate the servo based on the measured distance to an object.
Materials and Equipment’s:
• Arduino UNO board
• Servo Motor
• Ultrasonic Sensor (HC-SR04)
• Jumper wires
• Breadboard
• USB Cable (to connect Arduino to PC)

Theory:
Arduino Uno controls a servo motor using an ultrasonic sensor by measuring the distance to an
object using ultrasonic waves and then using that distance data to determine the servo's angle. The
Arduino sends a pulse to the ultrasonic sensor's trigger pin to emit a sound pulse and measures the
time for the echo to return to the echo pin to calculate the distance. This distance is then mapped
to a specific angle for the servo motor. Important components includes:

1. Ultrasonic Sensor (HC-SR04):


Transmitter & Receiver: The sensor has two transducers: one for sending ultrasonic pulses
and one for receiving the reflected echo.
Trigger Pulse: The Arduino sends a brief 5V trigger pulse to the sensor's trigger pin.
Sound Emission: The sensor then sends out a burst of ultrasonic waves.
Echo Detection: When these waves hit an object and bounce back, the sensor's receiver detects
the echo.

2. Distance Calculation:
The Arduino receives the timing information from the echo pin. Using the formula Distance =
(Time * Speed of Sound) / 2, the Arduino calculates the distance to the object. The time is
divided by two because the sound travels to the object and back to the sensor.

3. Servo Motor Control:


Input to Output Mapping: The calculated distance is then used to determine the servo motor's
desired angle.

Procedure: The following steps are desired:

1) Connect the 5V pin of the Arduino board to the bottom row of the breadboard.
2) Connect the GND pin to the top row of the breadboard.
3) Connect the VCC pin of the sensor to the positive terminal of the breadboard.
4) Connect the GND pin to the negative terminal of the breadboard.
5) Connect the TRIG to pin 9 of the Arduino.
6) Connect the ECHO pin to pin 10 of the Arduino.
7) Connect the positive terminal of servo motor to the positive terminal of breadboard.
8) Connect the ground terminal of servo motor to the negative terminal of the breadboard.
9) Connect the signal terminal to pin 6 of the Arduino board.

Program code:

#include <Servo.h>

// Define pins for the ultrasonic sensor


const int trigPin = 9; // Trigger pin connected to Arduino pin 9
const int echoPin = 10; // Echo pin connected to Arduino pin 10

// Define the pin for the SG90 servo motor


const int servoPin = 6; // Servo signal pin connected to Arduino pin 8

// Create a Servo object


Servo myServo;

void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);

// Set ultrasonic sensor pins as input/output


pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

// Attach the servo motor to its pin


myServo.attach(servoPin);

// Set initial position of the servo


myServo.write(90); // Start at 90 degrees (center)
}

void loop() {
// Clear the trigPin by setting it LOW for a moment
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

// Set the trigPin HIGH for 10 microseconds to send a pulse


digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Measure the duration of the echo pulse


long duration = pulseIn(echoPin, HIGH);

// Calculate the distance in centimeters


// Speed of sound in air is approximately 343 meters/second or 0.0343 cm/microsecond
// Distance = (duration * speed of sound) / 2 (because sound travels to object and back)
int distanceCm = duration * 0.0343 / 2;

// Print the distance to the Serial Monitor


Serial.print("Distance: ");
Serial.print(distanceCm);
Serial.println(" cm");

// Control the servo based on distance


if (distanceCm < 20) {
// If object is very close, move servo to 0 degrees
myServo.write(0);
} else if (distanceCm >= 20 && distanceCm < 50) {
// If object is moderately close, move servo to 45 degrees
myServo.write(45);
} else if (distanceCm >= 50 && distanceCm < 100) {
// If object is further away, move servo to 90 degrees
myServo.write(90);
} else {
// If object is far, move servo to 180 degrees
myServo.write(180);
}

// Add a small delay for stable readings and servo movement


delay(100);
}
Fig.1. Ultrasonic sensor interface with a servo motor using Arduino UNO
Observations:
• The ultrasonic sensor measures the distance of the object in front of it.
• The servo motor rotates to a specific angle proportional to the measured distance

Results:
The ultrasonic sensor (HC-SR04) was successfully interfaced with a servo motor using Arduino
UNO, and the servo motor rotated according to the measured distance of the object.

Learning Outcomes:
• Understanding working of ultrasonic sensor interfacing with servo motor using Arduino.
• Develop logic to control rotation of servo motor according to distance measured by
ultrasonic sensor.

Precautions:
• Ensure that ultrasonic sensor is connected correctly
• Do not exceed the servo motor’s rotation limit
• Keep the sensor aligned perpendicular to the object surface for accurate readings
• Do not touch moving servo parts while testing

You might also like