This specific code runs for ultrasonic sensor and gives high alert if there is motion beyond 20cm. Additionally if we use RFID tag ultrasonic sensor stops functioning and gives authorized access to make motion.

Dependencies:   MFRC522

Committer:
VPKD1669
Date:
Mon Dec 16 17:44:49 2019 +0000
Revision:
0:c7eacabfa681
This includes for the module RFID as well as ultrasonic sensor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
VPKD1669 0:c7eacabfa681 1 /* Copyright (c) 2013 Prabhu Desai
VPKD1669 0:c7eacabfa681 2 * pdtechworld@gmail.com
VPKD1669 0:c7eacabfa681 3 *
VPKD1669 0:c7eacabfa681 4 *
VPKD1669 0:c7eacabfa681 5 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
VPKD1669 0:c7eacabfa681 6 * and associated documentation files (the "Software"), to deal in the Software without restriction,
VPKD1669 0:c7eacabfa681 7 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
VPKD1669 0:c7eacabfa681 8 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
VPKD1669 0:c7eacabfa681 9 * furnished to do so, subject to the following conditions:
VPKD1669 0:c7eacabfa681 10 *
VPKD1669 0:c7eacabfa681 11 * The above copyright notice and this permission notice shall be included in all copies or
VPKD1669 0:c7eacabfa681 12 * substantial portions of the Software.
VPKD1669 0:c7eacabfa681 13 *
VPKD1669 0:c7eacabfa681 14 * For more details on the sensor :
VPKD1669 0:c7eacabfa681 15 * http://www.elecfreaks.com/store/hcsr04-ultrasonic-sensor-distance-measuring-module-p-91.html?zenid=pgm8pgnvaodbe36dibq5s1soi3
VPKD1669 0:c7eacabfa681 16 *
VPKD1669 0:c7eacabfa681 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
VPKD1669 0:c7eacabfa681 18 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
VPKD1669 0:c7eacabfa681 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
VPKD1669 0:c7eacabfa681 20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
VPKD1669 0:c7eacabfa681 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
VPKD1669 0:c7eacabfa681 22 */
VPKD1669 0:c7eacabfa681 23
VPKD1669 0:c7eacabfa681 24 #include "mbed.h"
VPKD1669 0:c7eacabfa681 25 #ifndef MBED_HCSR04_H
VPKD1669 0:c7eacabfa681 26 #define MBED_HCSR04_H
VPKD1669 0:c7eacabfa681 27
VPKD1669 0:c7eacabfa681 28
VPKD1669 0:c7eacabfa681 29 /** HCSR04 Class(es)
VPKD1669 0:c7eacabfa681 30 */
VPKD1669 0:c7eacabfa681 31
VPKD1669 0:c7eacabfa681 32 class HCSR04
VPKD1669 0:c7eacabfa681 33 {
VPKD1669 0:c7eacabfa681 34 public:
VPKD1669 0:c7eacabfa681 35 /** Create a HCSR04 object connected to the specified pin
VPKD1669 0:c7eacabfa681 36 * @param pin i/o pin to connect to
VPKD1669 0:c7eacabfa681 37 */
VPKD1669 0:c7eacabfa681 38 HCSR04(PinName TrigPin,PinName EchoPin);
VPKD1669 0:c7eacabfa681 39 ~HCSR04();
VPKD1669 0:c7eacabfa681 40
VPKD1669 0:c7eacabfa681 41 /** Return the distance from obstacle in cm
VPKD1669 0:c7eacabfa681 42 * @param distance in cms and returns -1, in case of failure
VPKD1669 0:c7eacabfa681 43 */
VPKD1669 0:c7eacabfa681 44 unsigned int get_dist_cm(void);
VPKD1669 0:c7eacabfa681 45 /** Return the pulse duration equal to sonic waves travelling to obstacle and back to receiver.
VPKD1669 0:c7eacabfa681 46 * @param pulse duration in microseconds.
VPKD1669 0:c7eacabfa681 47 */
VPKD1669 0:c7eacabfa681 48 unsigned int get_pulse_us(void);
VPKD1669 0:c7eacabfa681 49 /** Generates the trigger pulse of 10us on the trigger PIN.
VPKD1669 0:c7eacabfa681 50 */
VPKD1669 0:c7eacabfa681 51 void start(void );
VPKD1669 0:c7eacabfa681 52 void isr_rise(void);
VPKD1669 0:c7eacabfa681 53 void isr_fall(void);
VPKD1669 0:c7eacabfa681 54 void fall (void (*fptr)(void));
VPKD1669 0:c7eacabfa681 55 void rise (void (*fptr)(void));
VPKD1669 0:c7eacabfa681 56
VPKD1669 0:c7eacabfa681 57
VPKD1669 0:c7eacabfa681 58
VPKD1669 0:c7eacabfa681 59 private:
VPKD1669 0:c7eacabfa681 60
VPKD1669 0:c7eacabfa681 61 Timer pulsetime;
VPKD1669 0:c7eacabfa681 62 DigitalOut trigger;
VPKD1669 0:c7eacabfa681 63 InterruptIn echo;
VPKD1669 0:c7eacabfa681 64 unsigned int pulsedur;
VPKD1669 0:c7eacabfa681 65 unsigned int distance;
VPKD1669 0:c7eacabfa681 66 };
VPKD1669 0:c7eacabfa681 67
VPKD1669 0:c7eacabfa681 68 #endif