int Trig = 8; int Echo = 9; int Duration; float Distance; int PhotoTakeDistance = 10; //[cm] void setup() { Serial.begin(9600); pinMode(Trig,OUTPUT); pinMode(Echo,INPUT); } void loop() { digitalWrite(Trig,LOW); delayMicroseconds(1); digitalWrite(Trig,HIGH); delayMicroseconds(11); digitalWrite(Trig,LOW); Duration = pulseIn(Echo,HIGH); if (Duration>0) { Distance = Duration/2; Distance = Distance*340*100/1000000; // ultrasonic speed is 340m/s = 34000cm/s = 0.034cm/us Serial.print(Distance); Serial.println(" cm"); // //photo will be taken // if(Distance < PhotoTakeDistance){ Serial.println("Photo Taken"); delay(1000); } } delay(500); }
![]() |
Specifications
Input Voltage: 5V Pixel: 300,000 Resolution: 640*480, 320*240, 160*120 Uart Baud Rate: 9600~115200 Communication: RS485 and RS232 Photo JPEG compression, high, medium and low grades Optional AGC Auto Exposure Event Control Automatic White Balance Control Focus adjustable |