![]() ![]() PinMode(echoPin, INPUT) // Echo pin set to input PinMode(trigPin, OUTPUT) // Trigger pin set to output A one time routine executed at power up or reset time. Volatile long range_flasher_counter = 0 // Count down counter for flashing distance LED Volatile int trigger_time_count = 0 // Count down counter to trigger pulse time ![]() Volatile long echo_duration = 0 // Duration - difference between end and start Volatile long echo_end = 0 // Records end of echo pulse Volatile long echo_start = 0 // Records start of echo pulse #define TICK_COUNTS 4000 // 200 mS worth of timer ticks #define TIMER_US 50 // 50 uS timer duration #define echo_int 0 // Interrupt id for echo pulse #define onBoardLED 13 // Pin 13 onboard LED #define trigPin 12 // Pin 12 trigger output #include // Header file for TimerOne library Install the library using the following guide: This sketch uses the TimerOne library downloadable from here: The duration of the sensor echo signal is measured by generating anĮxternal interrupt ervery time the echo signal changes state. The same interrupt is used to control the flash rate Interrupts from timer 1 are used to schedule and deliver the sensor Just like the parking sensor on a new car.Īrduino Uno HC-SR04 ultrasonic range finder program using interrupts The flash rate of the onboard LED will change to reflect the distance. Place an object in front of the HC-SR04 sensor and vary the distance. This LED is located near to the USB connector. ![]() If all is well then you will see the Arduino onboard LED start to flash. Load the sketch onto your Arduino Uno and let it run. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |