Papelero

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

#include <Servo.

h>

int inches = 0;

int cm = 0;

long readUltrasonicDistance(int
triggerPin, int echoPin)

pinMode(triggerPin, OUTPUT);
// Clear the trigger

digitalWrite(triggerPin, LOW);

delayMicroseconds(2);

// Sets the trigger pin to HIGH


state for 10 microseconds

digitalWrite(triggerPin, HIGH);

delayMicroseconds(10);

digitalWrite(triggerPin, LOW);

pinMode(echoPin, INPUT);

// Reads the echo pin, and


returns the sound wave travel
time in microseconds

return pulseIn(echoPin, HIGH);

Servo servo_6;

void setup()

servo_6.attach(6, 500, 2500);

void loop()

if (0.01723 *
readUltrasonicDistance(13, 12)
<= 50) {

servo_6.write(70);

} else {

delay(900); // Wait for 900


millisecond(s)

servo_6.write(0);

You might also like