Control Activity 5
Control Activity 5
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:
C. System Implementation
(Paste an actual photograph of the implemented system)
D. Discussion and Conclusion
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
____________________________________________________________________________