On facebook we posted a cool project:
https://www.facebook.com/AZDelivery.de/videos/421956858229574/
We will show you how you can recreate the electronics or sensor here.
What do we need:
Microcontroller, compatible with Arduino UNO R3
Ultrasonic Sensor HC-SR04
Plug-in bridges
Servo motor
Ultrasonic sensor at Arduino

Software for the Arduino
Long distance1 = 0; Long distance2 = 0; Long Time=0; Int Number = 15; Int Values[16]; Void Setup() { #define Trigger 3 Arduino Pin 3 to HC-SR04 Trig #define Echo 2 Arduino Pin 2 to HC-SR04 Echo Serial.Begin(115200); Serial Baud rate pinMode(LED_BUILTIN, Output); } Void Loop() { for (Int Ⅰ=0; Ⅰ <= Number-1; Ⅰ++){ Time=0; noInterrupts(); Disabling Interrupts digitalWrite(Trigger, Low); delayMicroseconds(3); digitalWrite(Trigger, High); Trigger Pulse 10 us delayMicroseconds(20); digitalWrite(Trigger, Low); Time = pulseIn(Echo, High); Measure Echo Time Interrupts(); Activating Interrupts Values[Ⅰ] = Time; delay (1); } distance1 = 0; for (Int Ⅰ=0; Ⅰ <= Number -1; Ⅰ++){ distance1 = distance1 + Values[Ⅰ]; } distance2 = distance1 / Number; Serial.println(distance2); If (distance2 > 9550){ digitalWrite(LED_BUILTIN, High); Serial.println("open"); Delay(3000); digitalWrite(LED_BUILTIN, Low); Delay(1000); } }
Now our Arduino with the ultrasonic sensor detects at least once as we approach and displays this with the built-in LED.
In the next step, we control a servo motor to open the trash.
Now we are extending our wiring with a servo motor.
and adjust the software:
#include <Servo.H> Servo servo1; Long distance1 = 0; Long distance2 = 0; Long Time=0; Int Number = 15; Int Values[16]; Int To = 5; Int On = 95; Void Setup() { #define Trigger 3 Arduino Pin 3 to HC-SR04 Trig #define Echo 2 Arduino Pin 2 to HC-SR04 Echo Serial.Begin(115200); Serial Baud rate pinMode(LED_BUILTIN, Output); servo1.Attach(8); servo1.Write(To); } Void Loop() { for (Int Ⅰ=0; Ⅰ <= Number-1; Ⅰ++){ Time=0; noInterrupts(); Disabling Interrupts digitalWrite(Trigger, Low); delayMicroseconds(3); digitalWrite(Trigger, High); Trigger Pulse 10 us delayMicroseconds(20); digitalWrite(Trigger, Low); Time = pulseIn(Echo, High); Measure Echo Time Interrupts(); Activating Interrupts Values[Ⅰ] = Time; delay (1); } distance1 = 0; for (Int Ⅰ=0; Ⅰ <= Number -1; Ⅰ++){ distance1 = distance1 + Values[Ⅰ]; } distance2 = distance1 / Number; Serial.println(distance2); If (distance2 > 9550){ digitalWrite(LED_BUILTIN, High); Serial.println("open"); servo1.Write(On); Delay(3000); digitalWrite(LED_BUILTIN, Low); servo1.Write(To); Delay(1000); } }
You can now use the sensor and servo motor for various controls.
As can be seen in the Facebook video, an iris could be opened.
We wish you a lot of fun with the proximity sensor and are looking forward to your purposes.
3 comments
Hartmut Zipper
Habe ich in mein Rasenroborter am Schleifenempfänger eingebaut. Jetzt stop er vor Hindernissen bei 10 cm. Bei mir Aldi Easy Mover ist es Pin 6 am Schleifenempfänger. Bei High Stop zurück (Pip,Pip,Pip) zurück drehen und weiter mähen.
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(LED, HIGH); // zum Schalten mit Vorwiderstand 100 Ohm oder Testen
Serial.println(“open”);
delay(300);
Serial.println(“LED”);
digitalWrite(LED, LOW);
digitalWrite(LED_BUILTIN, LOW);
delay(5000);
Rudolf Reiber
Guten Tag,
bei mir tat der erste Sketch erst zuverlässig nach dem Einfügen von:
pinMode(echo, INPUT);
pinMode(trigger, OUTPUT);
in der SetUp-Routine.
T.Geffe
Hallo,
ein schoenes Projekt aber wo bekommt man den so einen Papierkorb zu kaufen?
Gruss Toralf