0% found this document useful (0 votes)
60 views

Control Activity 5

The document describes an experiment using an Arduino, ultrasonic sensor, and servo motor. The objective is to write a program to control the servo motor based on input from the ultrasonic sensor. When an object is detected within 4 cm, the servo will rotate 160 degrees, then return to 0 degrees after a delay. The materials, programming code with comments, wiring diagram, and system photo are provided. The student is to discuss and conclude the experiment.

Uploaded by

Ivan
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)
60 views

Control Activity 5

The document describes an experiment using an Arduino, ultrasonic sensor, and servo motor. The objective is to write a program to control the servo motor based on input from the ultrasonic sensor. When an object is detected within 4 cm, the servo will rotate 160 degrees, then return to 0 degrees after a delay. The materials, programming code with comments, wiring diagram, and system photo are provided. The student is to discuss and conclude the experiment.

Uploaded by

Ivan
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

Adamson University

Mechanical Engineering Department

Name: Ochava, Jocel Ivan B. Subject/Section: 57038


Instructor: Engr. Tony Doroliat Date Submitted: November 7, 2023

Experiment/Activity No. 5
Sensors and Actuators
Objective/s:
1. To manipulate an actuator output based on the acquired input from a sensor.
2. To write a program that controls the motion of a servo motor using input from an
ultrasonic sensor using Arduino IDE
3. Implement a simple application using embedded system

Materials: Arduino board, breadboard, jumper wires, HC-SR04, and micro-servo motor

Direction: Using Arduino IDE, write a program and implement a system that detects the
presence of an object at a certain threshold distance. If the object is within the threshold, the
servo rotate 160°C then rotates back to 0° after a specified time.

A. Programming
Write the code and append a comment that describes the purpose of each line of code.
#include <Servo.h> // allows Arduino Uno to control servo motor
int servoPin= 9; // set servoPin as int connected to pin 9
int serPos; // creates an integer variable “serPos”
int trigPin = 12; // set trigPin as int connected to pin 12
int echoPin = 11; // set echoPin as int connected to pin 11
float travelTime; // set travelTime as float to store decimals
float Distance; // set Distance as float to store decimals
int DT = 10; // sets delay time as 10
int buzPin = 7; // set buzpin as int connected to pin 7
Servo Servo1; // sets name of servo as “Servo1”
void setup() {
// put your setup code here, to run once:

Serial.begin(9600); // sets it to exchange data with the serial monitor at 9600 bits per second
Servo1.attach(servoPin);
pinMode(trigPin, OUTPUT); //configures trigPin as Output
pinMode(echoPin, INPUT); //configures echoPin as Input
pinMode(trigPin, OUTPUT); //configures trigpin as Output
}

void loop() {
// put your main code here, to run repeatedly:

digitalWrite(trigPin, LOW); // clears trigPin at Low state


delayMicroseconds(DT); // delay time inputted
digitalWrite(trigPin, HIGH); // sets trigPin at High state at DT microseconds
delayMicroseconds(DT); // delay time inputted
digitalWrite(trigPin, LOW); // clears trigPin at Low state
delayMicroseconds(DT); // delay time inputted
travelTime=pulseIn(echoPin, HIGH); // reads echoPin and returns soundwave travel time in
microseconds
Distance= (343./20000.)*travelTime; // sets the computation for distance
Serial.print("The distance is "); // print to serial monitor “The distance is “
Serial.print(Distance); // prints to serial monitor the value of Distance
Serial.println(" in cm"); //prints to serial monitor “ in cm”
delay(300); // adds a delay of 300ms
if (Distance <=4){ // if command where if distance is less than or equal to 4 it follows the
command
Servo1.write(serPos); // writes a value to the servo depending on serPos
}
else{ // if distance is not less than or equal to 4 it follows this command
Servo1.write(0); // writes value to the servo as 0
}
}
B. Wiring Connection (Note: this must be hand drawn)

C. System Implementation
(Paste an actual photograph of the implemented system)
D. Discussion and Conclusion

______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
____________________________________________________________________________

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy