Sie sind auf Seite 1von 6

De La Salle University-Dasmarinas

College of Engineering Architecture and Technology

Electronics Engineering Department

Fundamentals of Robotics Laboratory

Experiment # 4

Sensor(Potentiometer) with Serial Communications

Group # 6

ECE51

GOMEZ, John Jewel F.

DOP: March 16,2018

DOS: March 23, 2018

Engr. Roselito E. Tolentino

Instructor
I. Data

 Arduino Codes

(a) Infrared Sensor


int IRstate=1;
int IRpin=A1;

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)
}

(b) Ultrasonic Sensor

#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

Diagram 2. Ultrasonic Sensor


Diagram 3. Activity

Figure 1. Configuration and setup (Infrared Sensor)


Figure 2. Configuration and setup (Ultrasonic 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

Das könnte Ihnen auch gefallen