Test Jig - HC-SR04 Ultrasonic Distance Sensor

This is the link to our product :

4x4 Matrix Keypad Membrane : http://nadieleczonesolutions.blogspot.my/2015/01/HC-SR04.html

HC-SR04 Ultrasonic Distance Sensor

The development of test jig is to test every single HC-SR04 Ultrasonic Distance Sensor is functioning well before we handle it over to customer .

Test jig without HC-SR04 Ultrasonic Distance Sensor

Test jig with HC-SR04 Ultrasonic Distance Sensor

Above picture is our test jig . The HC-SR04 Ultrasonic Distance Sensor is plug in into this test jig to test it functionality .

This test jig is able to :
+ Scan the distance of object in front of HC-SR04 Ultrasonic Distance Sensor
+ Show the output on the on-board test jig LCD

Below is the video how the HC-SR04 Ultrasonic Distance Sensor is test :
 

If you like to know how this test jig is develop or how is the wiring and circuit diagram , feel free to leave comment below and we will elaborated more on this blog . 

 Pin Hookup:

Code:

/////////////////////////////////////// // Title : Ultrasonic Sensor Test Jig // // Main programmer : Muhammad Ilyasaa @ Nadi Eleczone Solutions // // Description : Ultrasonic Sensor Test Jig // /////////////////////////////////////// /////////////////////////////////////// // Define /////////////////////////////////////// #include <NewPing.h> #include <LiquidCrystal.h> /////////////////////////////////////// /////////////////////////////////////// // Constant /////////////////////////////////////// #define SONAR_NUM 2 // Number or sensors. #define MAX_DISTANCE 50 // Maximum distance (in cm) to ping. #define PING_INTERVAL 33 // Milliseconds between sensor pings (29ms is about the min to avoid cross-sensor echo). /////////////////////////////////////// /////////////////////////////////////// // Constructor /////////////////////////////////////// LiquidCrystal lcd(A4, A5, A0, A1, A2, A3); NewPing sonar[SONAR_NUM] = { // Sensor object array, Each sensor's trigger pin, echo pin, and max distance to ping. NewPing(5, 4, MAX_DISTANCE), //Sensor number 3 NewPing(9, 8, MAX_DISTANCE) //Sensor number 4 }; /////////////////////////////////////// /////////////////////////////////////// // Variable /////////////////////////////////////// unsigned long pingTimer[SONAR_NUM]; // Holds the times when the next ping should happen for each sensor. unsigned int cm[SONAR_NUM]; // Where the ping distances are stored. uint8_t currentSensor = 0; // Keeps track of which sensor is active. /////////////////////////////////////// void setup() { Serial.begin(9600); lcd.begin(20, 4); lcd.setCursor(0, 1); //lcd.print(" "); lcd.print(" TestJig Start - up "); lcd.setCursor(0, 2); //lcd.print(" "); lcd.print(" Please Wait "); pingTimer[0] = millis() + 75; // First ping starts at 75ms, gives time for the Arduino to chill before starting. for (uint8_t i = 1; i < SONAR_NUM; i++) // Set the starting time for each sensor. pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL; lcd.clear(); lcd.home(); lcd.setCursor(0, 0); //lcd.print(" "); lcd.print("Ultrasonic number 1 "); lcd.setCursor(0, 1); //lcd.print(" "); lcd.print(" cm "); lcd.setCursor(0, 2); //lcd.print(" "); lcd.print("Ultrasonic number 2 "); lcd.setCursor(0, 3); //lcd.print(" "); lcd.print(" cm "); } void loop() { for (uint8_t i = 0; i < SONAR_NUM; i++) { // Loop through all the sensors. if (millis() >= pingTimer[i]) { // Is it this sensor's time to ping? pingTimer[i] += PING_INTERVAL * SONAR_NUM; // Set next time this sensor will be pinged. if (i == 0 && currentSensor == SONAR_NUM - 1) oneSensorCycle(); // Sensor ping cycle complete, do something with the results. sonar[currentSensor].timer_stop(); // Make sure previous timer is canceled before starting a new ping (insurance). currentSensor = i; // Sensor being accessed. cm[currentSensor] = 0; // Make distance zero in case there's no ping echo for this sensor. sonar[currentSensor].ping_timer(echoCheck); // Do the ping (processing continues, interrupt will call echoCheck to look for echo). } } // The rest of your code would go here. } void echoCheck() { // If ping received, set the sensor distance to array. if (sonar[currentSensor].check_timer()) cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM; } void oneSensorCycle() { // Sensor ping cycle complete, do something with the results. for (uint8_t i = 0; i < SONAR_NUM; i++) { //Serial.print(i); //Serial.print("="); //Serial.print(cm[i]); //Serial.print("cm "); lcd.home(); lcd.setCursor(0, 0); if(i==0) { //lcd.print(" "); lcd.setCursor(7, 1); lcd.print(" "); lcd.setCursor(7, 1); lcd.print(cm[i]); } else if(i==1) { lcd.setCursor(7, 3); lcd.print(" "); lcd.setCursor(7, 3); lcd.print(cm[i]); } } Serial.println(); }

2 comments:

  1. May i know if this ultrasonic distance sensors can measure the depth of water?

    ReplyDelete