0% found this document useful (0 votes)
40 views1 page

Touchless Toilet Flush 1

Uploaded by

Deepanshi Bansal
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)
40 views1 page

Touchless Toilet Flush 1

Uploaded by

Deepanshi Bansal
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/ 1

#include <Servo.

h>
Servo myservo;
int trig = 7;
int echo = 8;
int servo = 9;

long duration, distance;


long a[3];

void setup()
{
myservo.attach(servo);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
myservo.write(0); // servo position 0 degree
delay(1000);
myservo.detach();
}

void measure()
{
digitalWrite(trig, LOW);
delayMicroseconds(6);
digitalWrite(trig, HIGH);
delayMicroseconds(15);
digitalWrite(trig, LOW);
pinMode(echo, INPUT);
duration = pulseIn(echo, HIGH);
distance = (duration/2) / 29.1;
}
void loop()
{
for (int i=0;i<=2;i++) {
measure();
a[i]=distance;
delay(50);
}
distance=(a[0]+a[1]+a[2])/3;

if ( distance<70 ) // change this value to increase or decrease detection range.


{

myservo.attach(servo);
delay(1);
myservo.write(90); //servo position 90 degree
delay(2000);
myservo.write(0); //servo position 0 defree
delay(1000);
myservo.detach();
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy