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

Arduino UNO 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)
8 views4 pages

Arduino UNO 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
You are on page 1/ 4

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() {
Serial.begin(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;

Serial.println(distance);
delay(500);
}

IR Sensor

int irSensor = 2;

void setup() {
pinMode(irSensor, INPUT);
Serial.begin(9600);
}

void loop() {
int val = digitalRead(irSensor);
Serial.println(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() {
Serial.begin(9600);
Arduino UNO - Applied Electromechanics Lab Guide

void loop() {
int ldrVal = analogRead(ldrPin);
Serial.println(ldrVal);
delay(500);
}

16x2 LCD

#include <LiquidCrystal.h>

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

void setup() {
lcd.begin(16, 2);
lcd.print("Hello World");
}

void loop() {
lcd.setCursor(0, 1);
lcd.print(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() {
myservo.attach(9);
}

void loop() {
myservo.write(0);
delay(1000);
myservo.write(90);
delay(1000);
myservo.write(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);
}

You might also like