The Motion Detector can be used to make a simple alarm system by slightly modifying the VernierLibDemoMotionDetector sketch. This code turns on line 13 when the Motion Detector reads a distance less than 100 centimeters.
/* VernierMotionDetectorThreshhold (v 2014.09) Takes data from a Vernier Motion Detector connected to BTD 1 connector. This sketch measures the time taken for the ultrasound to return (in microseconds) and then calculates the corresponding distance (based on the speed of ultrasound in air) and displays the distance (in cm) on the Serial Monitor. Here is how the Vernier Motion Detector works: - when pin 2 on BTD is pulled high the ultrasound pulse is triggered - the program then starts timing but then delays 0.9 ms *(blanking time, 0.9 seconds is the time it takes ultrasound to travel 15 cm twice (round trip)) - the program then monitors pin 1 on the BTD, waiting for it to go high. This happens when an echo is detected. As written, the reading will be displayed roughly every quarter of a second. Change the delay at the end of the loop to change the rate. This version turns on an LED connected to pin 13 if the distance is less than one meter. See www.vernier.com/arduino for more information. */ const int TriggerPin = 3; //trigger pin const int EchoPin = 2;// echo pin const int LedPin = 13;// LED pin void setup() { // initialize the Ping pin as an output: pinMode(TriggerPin, OUTPUT); pinMode(EchoPin, INPUT); //this is the pin that goes high when an echo is received pinMode(LedPin, OUTPUT); //used for the LED // initialize serial communication at 9600 bits per second: Serial.begin(9600); Serial.println("Vernier Format 2"); Serial.println("Motion Detector Readings taken using Ardunio"); Serial.println("Data Set"); Serial.print("Time for Echo");//long name Serial.print("\t"); //tab character Serial.println ("Distance"); //long name Serial.print("delta t");//short name Serial.print("\t"); //tab character Serial.println ("D"); //short name Serial.print("seconds");//units Serial.print("\t"); // tab character Serial.println ("meters"); //units } void loop() { long time;// clock reading in microseconds long Duration; // time it take echo to return const float SpeedOfSound = 340; //in m/s float Distance;// in centimeters int val = 0;digitalWrite(LedPin, LOW); digitalWrite(TriggerPin, LOW); delayMicroseconds(4000); digitalWrite(TriggerPin, HIGH); // start the ultrasound pulse time = micros(); //note time delayMicroseconds(900); //delay during the blanking time do { val =digitalRead(EchoPin); // if no echo, repeat loop and wait } while (val == LOW) ; Duration =micros() - time; /* The speed of sound is 340 m/s. The ultrasound travels out and back, so to find the distance of the object we take half of the distance traveled.*/ Distance= Duration *SpeedOfSound/2/10000 ;// note convert to cm Serial.print(Duration);// print the time it took until the echo Serial.print("\t"); // tab character Serial.println(Distance); if (Distance < 100) { // if distance< 1 meter digitalWrite(LedPin, HIGH); Serial.print(" *******"); } delay(250); //delay a quarter of a second }
Cookie | Type | Duration | Description |
---|---|---|---|
Chatra | third party | 1 week | Used for chat widget |
CloudFlare (__cfduid) | persistent | 1 month | Used by CloudFlare service for rate limiting |
Cookie Consent: Necessary | session | 12 hours | Used to preserve cookie consent answer for necessary cookies |
Cookie Consent: Non-Necessary | persistant | 1 year | Used to preserve cookie consent answer for non-necessary cookies |
Cookie Consent: Viewed Cookie Policy | persistent | 1 year | Used to remember if user viewed the cookie policy |
Google Analytics (_ga) | persistent | 2 years | Used to distinguish users for Google Analytics |
Google Analytics (_gat) | persistent | 1 minute | Used to throttle request rate of Google Analytics |
Google Analytics (_gid) | persistent | 24 hours | Used to distinguish users for Google Analytics |
PHP Session | session | session | Used to store API results for better performance |
WooCommerce: Cart | temporary | session | Helps WooCommerce determine when cart contents/data changes. |
WooCommerce: Items in Cart | session | session | Helps WooCommerce determine when cart contents/data changes. |
WooCommerce: Session | persistent | 2 days | Helps WooCommerce by creating an unique code for each customer so that it knows where to find the cart data in the database for each customer. |
WordPress: Login Session | persistent, session | Session or 2 weeks (if user clicks remember me) | Used by WordPress to indicate that a user is signed into the website |
WordPress: Secured Account Details | persistent, session | Session or 2 weeks if user chose to remember login | Used by WordPress to securely store account details |
WordPress: Test Cookie | session | Session | Used by WordPress to check if the browser accepts cookies |
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies.