This is a little art project I made. On a 29,5 x 60 x 1 cm MDF board, I sketched an eye and nailed in a bunch of nails. After taking of the paper I sketched on, I then connected the nails with yarn.
The finished art piece:
/*
HC-SR04 Ping distance sensor:
VCC to Arduino 5v
GND to Arduino GND
Echo to Arduino pin 7
Trig to Arduino pin 8
*/
#include
Servo myservoR; // create right servo object
Servo myservoL; // create left servo object
int posR = 90; // variable to store the servo position
int posL = 90;
#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin
int maximumRange = 200; // Maximum distance range
int minimumRange = 0; // Minimum distance range
long duration, distance; // Duration used to calculate distance
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
myservoR.attach(5); //attach right servo signal to pin 5
myservoL.attach(4); //attach left servo signal to pin 4
}
void loop() {
digitalWrite(trigPin, LOW); // trigger impulse
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); // listen to the echo
distance = duration/58.2; //Calculate the distance (in cm) based on the speed of sound.
if (distance >= 20){
/* Drive forward */
myservoR.write(80);
myservoL.write(105);
delay(50);
}
if (distance < 10 && distance > 5 ){
/* Turn around */
myservoR.write(110);
myservoL.write(110);
delay(250);
}
if (distance <= 5){
/* Back up */
myservoR.write(150);
myservoL.write(40);
delay(50);
}
//Delay 50ms before next reading.
delay(50);
}