Ultrasonic Sensor Curtain Detector

Use the ultrasonic sensor and Arduino to sense if the curtain is pulled, remind me to pull the curtain before going to bed.

VIDEO LINK :https://youtu.be/OYDR5qQF-Ys

  • 1 X Arduino Leonardo
  • 1 X ultrasonic sensor
  • 3 X led light
  • 1 X power-bank
  • 1 X Electronics breadboard
  • 1 X USB Cable
  • Hook-up wires
  • 1 X Box that is at least 20cm*12cm*7cm
  • 1 X 21cm*17cm paper

Step 1: Building the Circuit

Step 2: Code

int ardublockUltrasonicSensorCodeAutoGeneratedReturnCM(int trigPin, int echoPin){

long duration;

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT); digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(20);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

duration = duration / 59;

if ((duration < 2) || (duration > 300)) return false;

return duration;

}

void setup() { pinMode( 11 , OUTPUT);

pinMode( 12 , OUTPUT);

pinMode( 13 , OUTPUT);

digitalWrite( 6 , LOW );

digitalWrite( 11 , HIGH );

digitalWrite( 12 , HIGH );

digitalWrite( 13 , HIGH );

}

void loop() { if (( ( 10.0 ) > ( ardublockUltrasonicSensorCodeAutoGeneratedReturnCM( 6 , 7 ) ) )) { digitalWrite( 12 , LOW ); // you can change the number depends on the distance to the curtain

digitalWrite( 13 , LOW );

digitalWrite( 11 , LOW ); }

else {

digitalWrite( 11 , HIGH );

digitalWrite( 12 , HIGH );

digitalWrite( 13 , HIGH ); } }

Step 3: Making a Case

Cut a 5*2 cm hole in front of the box

Cut a 6*3 cm hole above the box

Put in the Arduino and Power-bank

The sensor need to be align to the hole in front and the LEDs need to be align to the hole above the box

Roll the paper and put it in the hole above the box

Share

    Recommendations

    • Growing Beyond Earth Maker Contest

      Growing Beyond Earth Maker Contest
    • Classroom Science Contest

      Classroom Science Contest
    • 1 Hour Challenge

      1 Hour Challenge

    Discussions