0% found this document useful (0 votes)
6 views4 pages

Arduino UNO Electromechanics Lab Guide

The document provides a lab guide for using various components with the Arduino UNO, including LEDs, buzzers, ultrasonic sensors, IR sensors, push buttons, LDRs, LCDs, 7-segment displays, servo motors, and DC motors. Each section includes example code for setup and loop functions to demonstrate how to control these components. The guide serves as a practical resource for applied electromechanics experiments using Arduino.

Uploaded by

kassaatharva7
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)
6 views4 pages

Arduino UNO Electromechanics Lab Guide

The document provides a lab guide for using various components with the Arduino UNO, including LEDs, buzzers, ultrasonic sensors, IR sensors, push buttons, LDRs, LCDs, 7-segment displays, servo motors, and DC motors. Each section includes example code for setup and loop functions to demonstrate how to control these components. The guide serves as a practical resource for applied electromechanics experiments using Arduino.

Uploaded by

kassaatharva7
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

Arduino UNO - Applied Electromechanics Lab Guide

LED

int led = 13;

void setup() {
pinMode(led, OUTPUT);
}

void loop() {
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}

Buzzer

int buzzer = 8;

void setup() {
pinMode(buzzer, OUTPUT);
}

void loop() {
digitalWrite(buzzer, HIGH);
delay(500);
digitalWrite(buzzer, LOW);
delay(500);
}

Ultrasonic Sensor (HC-SR04)

int trigPin = 9;
int echoPin = 10;
long duration;
int distance;

void setup() {
[Link](9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
Arduino UNO - Applied Electromechanics Lab Guide

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);


distance = duration * 0.034 / 2;

[Link](distance);
delay(500);
}

IR Sensor

int irSensor = 2;

void setup() {
pinMode(irSensor, INPUT);
[Link](9600);
}

void loop() {
int val = digitalRead(irSensor);
[Link](val);
delay(200);
}

Push Button

int button = 7;
int led = 13;

void setup() {
pinMode(button, INPUT);
pinMode(led, OUTPUT);
}

void loop() {
if (digitalRead(button) == HIGH) {
digitalWrite(led, HIGH);
} else {
digitalWrite(led, LOW);
}
}

LDR

int ldrPin = A0;

void setup() {
[Link](9600);
Arduino UNO - Applied Electromechanics Lab Guide

void loop() {
int ldrVal = analogRead(ldrPin);
[Link](ldrVal);
delay(500);
}

16x2 LCD

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
[Link](16, 2);
[Link]("Hello World");
}

void loop() {
[Link](0, 1);
[Link](millis() / 1000);
}

7-Segment Display

int seg[] = {2,3,4,5,6,7,8};

int num[10][7] = {
{1,1,1,1,1,1,0}, // 0
{0,1,1,0,0,0,0}, // 1
};

void setup() {
for (int i = 0; i < 7; i++) {
pinMode(seg[i], OUTPUT);
}
}

void loop() {
for (int i = 0; i < 7; i++) {
digitalWrite(seg[i], num[0][i]);
}
}

Servo Motor

#include <Servo.h>
Arduino UNO - Applied Electromechanics Lab Guide

Servo myservo;

void setup() {
[Link](9);
}

void loop() {
[Link](0);
delay(1000);
[Link](90);
delay(1000);
[Link](180);
delay(1000);
}

DC Motor

int motorPin = 9;

void setup() {
pinMode(motorPin, OUTPUT);
}

void loop() {
digitalWrite(motorPin, HIGH);
delay(2000);
digitalWrite(motorPin, LOW);
delay(2000);
}

Common questions

Powered by AI

Analog reading from an LDR on the Arduino UNO involves measuring varying voltage levels using the 'analogRead()' function, which provides a range of values that represent different light intensity levels . This allows for more nuanced data capturing and is useful in applications requiring gradient light measurements, such as ambient light monitoring. In contrast, digital reading from an IR sensor uses the 'digitalRead()' function, providing binary output (high or low), which is ideal for simple object detection applications . Digital readings offer simplicity and faster processing, whereas analog readings provide detailed, continuous data for more complex analyses.

The use of a push button with an LED on the Arduino UNO illustrates fundamental principles of input and output by demonstrating how a digital input can control a digital output. The input state of the button is read using 'digitalRead()', and based on whether the button is pressed (high state) or not (low state), the LED is turned on or off using 'digitalWrite()' . This setup exemplifies basic microcontroller operations where input signals (from sensors or user actions) directly influence the output hardware, showcasing the core concept of input-processing-output in embedded systems.

The 'delay()' function in Arduino programs pauses execution for a specified number of milliseconds, controlling the timing of operations, such as LED blinking at regular intervals . 'delayMicroseconds()', on the other hand, provides finer control, pausing for microsecond durations, essential for tasks requiring precise timing, like ultrasonic distance measurement . Despite their utility in establishing a time-controlled flow, they are blocking functions, meaning no further code execution can occur during their active period. This can hinder the performance of programs requiring multitasking or concurrent operations, necessitating alternative approaches for complex applications.

Using a 7-segment display with Arduino UNO offers the advantage of visually displaying numeric data in a compact form, which is intuitive for users . It provides a straightforward solution for applications like digital clocks or counters. However, challenges include the need for appropriate pin mapping and control logic, which can become complex when displaying multiple digits without additional circuitry like multiplexers. The manual wiring for each segment can be cumbersome, and coding becomes more involved to handle each digit's segments accurately. Therefore, while it simplifies numerical representation, it requires careful planning and execution.

The Arduino UNO manages timing for both LED and buzzer operations using the 'delay()' function, which pauses the program for a specified number of milliseconds. For the LED, it turns the LED on and off with a delay of 1000 milliseconds each, creating a one-second on/off cycle . Similarly, the buzzer is activated with a delay of 500 milliseconds, producing a sound pattern with half a second of buzzing followed by half a second of silence . The use of 'delay()' is significant because it creates synchronous operations but also blocks further code execution, which can be limiting for multitasking or more complex functions.

The ultrasonic sensor HC-SR04 operates by emitting ultrasonic waves via its trigger pin, which then reflect off objects and return to the sensor. The Arduino measures the time interval using the 'pulseIn()' function, calculating the distance using the speed of sound formula . The use of this sensor is effective for distance measurement due to its non-contact method and capability to measure distances up to several meters. However, it requires precise timing and environmental awareness, as it may not work accurately in noisy settings or with soft surfaces. The coding implementations are relatively straightforward, but successful operation relies heavily on accurately setting pin modes and handling sound wave delay calculations.

Integrating libraries like LiquidCrystal and Servo facilitates complex operations in Arduino UNO projects by providing pre-written functions to handle intricate tasks efficiently, reducing development time and complexity. For instance, the LiquidCrystal library manages the hardware interactions required to display characters on an LCD, allowing users to focus on message content rather than low-level hardware communication . Similarly, the Servo library simplifies servo motor control, allowing for angle-based positioning without manually generating pulse-width modulated signals . These libraries abstract complex tasks, making advanced functionalities accessible even to beginners.

The 'pinMode()' function is crucial in Arduino projects as it configures the specified pin to behave either as an input or output, enabling effective hardware interfacing . For instance, it is used to set pins connected to LEDs, buttons, or motors, ensuring correct signal direction. The 'digitalWrite()' function follows, allowing the program to send high or low signals to the configured pin, directly impacting hardware behavior, such as turning an LED on or off . Together, these functions establish foundational control over digital I/O, facilitating precise interaction with external components and forming the basis of embedded system programming in Arduino projects.

Constructing a project using a 16x2 LCD with Arduino UNO can enhance learning and skill development in several ways. It introduces users to library integration (LiquidCrystal library), essential for handling complex peripherals . It also improves understanding of data communication (via pins), character mapping, and real-time data display. These projects develop problem-solving skills as students troubleshoot wiring or code issues. Moreover, they learn to display dynamic content, such as timing information, fostering an understanding of real-time data processing and manipulation. Such projects provide a practical foundation for creating more sophisticated interactive systems.

The Arduino code for operating a servo motor and a DC motor illustrates different control strategies. The servo motor uses the Servo library, where the 'myservo.attach()' function links a pin to the servo object, and 'myservo.write()' sets the servo to specific angles . This allows precise control over the servo's position. Conversely, the DC motor is controlled by setting the motor pin as an output and using 'digitalWrite()' to turn it on or off, lacking intermediate control . The servo motor's control structure provides finer, angle-based positioning, whereas the DC motor uses simple switching, suitable for basic on-off operation.

You might also like