The distance between the hand and the AAGD is measured by HC-SR05 sensor. Indeed, the HC-SR05 sensor is a low cost ultrasonic sensor that used two transducers to transmit and receive the sound waves, and operates with a supply voltage of 5 volts (Jeswin et al. 2017). It has a measurement angle of approximately 15 degrees and allows distance measurements between 2 cm and 4 meters with an accuracy of.
The process of distance measurement is entirely dependent on the speed of sound. For this purpose, a high impulsion of 10µs duration is sent to the TRIGGER pin of ultrasonic sensor. In this state, the impulsion will be generated by the microcontroller “Arduino nano”, and the TRIGGER pin of HC-SR05 sensor is linked in the pin D2 of microcontroller, as illustrated in Fig. 2. Moreover, the impulse sent to the TRIGGER pin will be split by the sensor, to produce a series of impulsions (8 pulses of 40 kHz). Then, the ultrasonic sensor will be sent these pulses outside, to detect the distance between the hand and dispenser. In the next step, the signal waves propagate through the air until contact an impediment. These sound waves will be returned on the other way to the transducer of sensor. On the other hand, the signal ECHO of ultrasonic sensor is remain high value when the sensor trying to detect the distance. It is important to note that the ECHO pin has been attached to the pin D2 of microcontroller, to confirm the reception of the transmitted signal.
3.1 Code source of distance measurement.
The Arduino Software (IDE) allows writing the program of the distance measurement, and uploads it to the microcontroller board. This program will be transmitted from computer to the microcontroller device by a mini USB cable. One of the problems encountered during the uploading of the programs, is that the serial PORT is not detected when the mini USB cable inserted in the computer device. For this purpose, an Arduino megaAVR Core is added in the IDE software, as shown in Fig. 3. Then, the computer software should be running automatically its driver installation process once the mini USB cable plugged in the computer device.
The source code of distance measurement between the hand and the alcohol dispenser is a key element in this work. Indeed, the code first specifies all the constants and variables used in the program. There are four constants; two constants for the TRIGGER and ECHO pins of the ultrasonic sensor, a constant that specifies the measurement delay (Delay_Time) and a constant to define the speed of sound. In addition, the source code is contains two variants; one is used to ensure the alcohol dispenser button is pressed once when the hand remains close to the ultrasonic sensor. Moreover, the second variable is used to control the rotation angle of servo-motor. These specific declarations are shown in declaration code.
[Declaration code]
#include < Servo.h> //Implementing the sevomotor library in the program.
Servo Myservo ; //Creating an object "Myservo" from the class "Servo".
const byte ECHO_PIN = 2; //Connecting the ECHO_PIN of sensor with the D2 pin.
const byte TRIGGER_PIN = 3; //Linking the TRIGGER_PIN of Ultrasonic by the D3 pin.
const byte LED = 5; //Placing the signal LED in the D5 pin of Arduino Nano.
const unsigned long Delay_Time = 25000UL; // Defining the waiting time.
const float SOUND_SPEED = 340.0 / 1000; // Defining the sound speed.
int Hand_Test, rotation_angle; //Declaring global variables of hand testing and rotation
//angle.
[/Declaration code]
In the next step of source code generation, the setup function initializes the baud rate of transmission data by the serial port. This communication between the microcontroller and computer is used to monitor the distance measurement between the hand and alcohol dispenser in real-time. In addition, the TRIGGER pin of the sensor is defined as output in the setup function and made it on low voltage, and sets the ECHO pin of the HC-SR05 sensor as an input pin. On the other hand, the connection of servo-motor on the microcontroller board is declared in the function. This setup function is presented in setup code.
[Setup code]
void setup() { //The setup function will run for one time (In each
// start-up of the microcontroller device).
Serial.begin(9600); //Initializing the baud-rate of transmission data
//(the distance between the hand and AAGD).
pinMode(ECHO_PIN, INPUT); //Configuring the Pin D2 of Arduino Nano as input.
pinMode(TRIGGER_PIN, OUTPUT); //Configuring the Pin D3 of microcontroller as output.
digitalWrite(TRIGGER_PIN, LOW); //Initializing the state of Pin D3 by 0 Volts.
pinMode(LED, OUTPUT); //Configuring the Pin D5 of microcontroller as output.
digitalWrite(TRIGGER_PIN, HIGH);//Lighting the signal LED, to ensure that the
//program is running
Myservo.attach(4); //Linked the PWM pin of servo-motor device in the D4 pin.
Myservo.write (0); //Initializing the rotation-angle of servomotor by
//zero degree.
Hand_Test = 0; //Initializing the hand testing variable by zero value.
delay (100); //Giving a delay time before moving to the loop function.
}
[/Setup code]
In the last part of the source code, the loop function is used to measure the distance between the hand and dispenser. In addition, it’s used to control the servo-motor rotation, as presented in loop code. For the purpose of measurement, it first generates a high-value pulse of 10µs duration, which transmitted to the TRIGGER pin of the HC-SR05 sensor. After that, it measures the time required to receive the sound waves. This time is represented the round trip of the ultrasound signal, and it can be measured by pulseIn function. Finally, the distance between the hand and the alcohol dispense will be measured and will be sent to the computer device for monitoring. This communication between the microcontroller and computer device is done under the UART protocol. On the other hand, the servo-motor angle is controlled by two angles (0 and 150 degrees).
3.2 Results of distance measurement
The source code of distance measurement between the hand and alcohol dispenser is tested. For this purpose, the distance is measured by a tap-meter and with Ultrasonic sensor. The result obtained is presented in the Fig. 4 and Fig. 5. Indeed, the error of the distance measurement is augmented when the distance between the hand and alcohol dispenser is less than 6 cm, it’s reached 25% on average above 7 mm. This error will be decreased when the distance between them is greater than 5 cm. Indeed, this experiment is repeated many times when the hand is far from the sensor because the hand is representing a small impediment. However, the AAGD is required that the hand become close from Ultrasonic sensor (6 cm). Without this condition, the servo-motor stay in the initial state (0 degrees).
[Loop code]
void loop() { //The loop function will be executed simultaneously.
digitalWrite(TRIGGER_PIN, HIGH); //Transmitting a high impulsion to TRIGGER_Pin.
delayMicroseconds(10); //Defining the duration of the impulsion.
digitalWrite(TRIGGER_PIN, LOW); //Stop transmitting the impulsion (10 us is enough).
long measure_time = pulseIn(ECHO_PIN, HIGH, Delay_Time); //Measures the time between
//sending the sound wave and its Echo.
float distance_mm = measure_time / 2.0 * SOUND_SPEED; //The distance will be calculated.
if (distance_mm > = 60) { //This condition is implemented, to test if the hand is
//not closed to the dispenser.
Hand_Test = 0; //Giving the global variable a value equals zero.
}
if (Hand_Test = = 0) { //This condition is integrated, to confirm that
//the distance between The hand and dispenser was more
//than 6 Cm
if (distance_mm < = 60) { //This condition is implemented, to test if the hand is
//closed to the dispenser.
Myservo.write(150); //Rotating the servo-motor by angle equals to 150 degree
delay(600); //Waiting the alcohol exit ( The push-pull button is
//pressed).
Myservo.write(0); //Returning to the initial state.
delay(15); //Giving a time delay to servo-motor (for stabilization).
Hand_Test = 1; //Changing the state of global variable, to test
//if the hand is still closed to the dispenser.
}
}
Serial.print(distance_mm); //Monitoring the distance measurement, by using UART
//protocol.
}
[/Loop code]