Documente Academic
Documente Profesional
Documente Cultură
Experiment # 4
Group # 6
ECE51
Instructor
I. Data
Arduino Codes
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
IRstate=digitalRead(IRpin);
Serial.print("Infrared Sensor: ");
Serial.println(IRstate);
delay(150)
}
#include <NewPing.h>
#include <Servo.h>
#define TRIGGER_PIN 10
#define ECHO_PIN 9
#define MAX_DISTANCE 100
double dist;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
Servo myservo;
int val;
void setup() {
Serial.begin(9600);
myservo.attach(5);
}
void loop() {
dist=sonar.ping_cm();
Serial.print("ultrasonic sensor: ");
Serial.print(dist);
Serial.println("cm");
delay(750);
myservo.write(dist);
delay(5);
}
(c) (Activity)
#include <NewPing.h>
#include <Servo.h>
#define TRIGGER_PIN 10
#define ECHO_PIN 9
#define MAX_DISTANCE 100
double dist;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
Servo myservo;
int val;
void setup() {
Serial.begin(9600);
myservo.attach(6);
}
void loop() {
dist=sonar.ping_cm();
Serial.print("ultrasonic sensor: ");
Serial.print(dist);
Serial.println("cm");
delay(15);
val = map(dist, 0, 80, 0, 179);
myservo.write(val);
Serial.println(val);
delay(150);
}
II. Output
Diagram 1. Infrared Sensor
I. Conclusion
In the first part of the experiment which is infrared sensor, as you gets away with it the
distance increases, as you get closer the distance decreases. In the second part which is
ulta