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

servo arduino_035532

Uploaded by

ytoussantt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

servo arduino_035532

Uploaded by

ytoussantt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//pino do semsor

const int trigger = 6


const int eco = 7;

//defimir variáveis

long duração;
float dist;

//.................................................................................
......................................................

// para servo

#include <Servo.h>

Servo servo;

void setup (){

pinMode(trigger, OUTPUT);
pinMode(eco,INPUT);
Serial.begin (9600);

void loop (){

digitalWrite (trigger,LOW);
delayMicroseconds (5);
digitalWrite (trigger, HIGH);
delayMicroseconds (10);
digitalWrite (trigger, LOW);
delayMicroseconds (10);

duração = pulseIn (eco, HIGH);

// equação da velocidade

dist = (duração * 0,034)/2;

//.........................................................

// ligar o servo
servo.attach (8);

if (dist<= 10) {
servo.write (180);
serial.print (dist);
serial.print("cm = ");
serial.println ("aberto");
delay (2000);
}else {
servo.write (0);
serial.print (dist);
serial.print("cm = ");
serial.println ("fechado");
delay (2000);
}
}

You might also like