Der Proto-Dog freut sich wenn er dich sieht!
Dafür braucht ihr einen Arduino o. ä. einen Servo Motor, Ultraschallsensor und für die Gestaltung Pappe, Schere und ggf. Leim.
Code Beispiel:
</pre> #include <Wire.h> #include <Servo.h> Servo myservo; int pos = 0; //Sensor int trigPin = 7 ; // TRIG int echoPin = 6 ; // ECHO float duration_us, distance_cm; void setup() { // Serial.begin(9600); myservo.attach(9); pinMode(trigPin, OUTPUT); // Config trigger pin to output mode pinMode(echoPin, INPUT); // Config echo pin to input mode } void loop() { // Generate 10-microsecond pulse to TRIG pin digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); delayMicroseconds(10); // Measure duration of pulse from ECHO pin duration_us = pulseIn(echoPin, HIGH); // Calculate the distance distance_cm = 0.017 * duration_us; // Calculate the distance //Serial.println(distance_cm1); //Wenn Ultrasonic ein Hinderniss unterhalb von 15 cm erkennt, dann das.... if (distance_cm < 15) { for (pos = 0; pos <= 40; pos += 5) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for (pos = 40; pos >= 0; pos -= 5) { // goes from 180 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } } } <pre>