Hey friends!
Today, I am going to teach you about making an automatic water dispenser using ultrasonic sensor. I got this idea when I referred to a university's project, with five members and a duration of five days. I managed to do this project with limited resources within three hours.
If you have any suggestions on how I could improve this project, please don't hesitate to comment them below. In this project, I am using the ultrasonic sensor (HC-SR04) to detect the water bottle within the range of 2-3 cm. Read further on to learn the codes and how I did this project.
The ultrasonic sound sensor has an ultrasonic wave transmitter and receiver. A transmitter emits a signal which is reflected off an object - within 2 cm to 400 cm - and received by the receiver. The time taken for the signal to travel from the transmitter to the receiver is divided by two and multiplied by the speed of sound in air to give us the distance between the sensor and the object.
Create global variables for the trigger pin, echo pin and the relay module. You must also create variables for the duration and distance. The type of variable for the duration must be long, and that for the distance must be int.
Within void setup( ), configure whether the pins of both ultrasonic sensor and the relay module are INPUT or OUTPUT. Within void loop( ), set the trigger pin LOW for 5 microseconds before setting it HIGH. Set a delay period of 10 microseconds to emit an ultrasonic pulse before setting the trigger pin LOW. Read the duration of the pulse using pulseIn( ) function and wait for the echo pin to go HIGH.
Calculate the distance by using simple high school mathematics and physics.
If you have any questions, or suggestions, about this project, please feel free to comment below or send me an email at arduinoprojectsbyr@gmail.com.
Supplies
- Arduino Uno/ Nano
- USB Type A/ B cable (for Arduino Uno) or USB Type A to mini B cable (for Arduino Nano)
- Solderless Breadboard - Mini
- Ultrasonic sensor (HC-SR04)
- Relay module - 5V single channel
- 5V DC mini Water pump - Submersible
- Container - filled with water
- Empty Water bottle (optional)
- Male-to-Male jumper wires (x9) - 10 cm
- Female-to-Female jumper wires (x7) - 70 cm
- Cardboard box / 3D printed casing
Setup
Your setup must look somewhat familiar to the one in the images above.
Connections
Ultrasonic sensor (HC - SR04)
- VCC - 5V
- Trigger pin - D5
- Echo pin - D4
- GND - Ground
Relay Module (5V single channel)
- S - D6
- (+) - 5V
- (-) - Ground (GND)
Coding
Let me explain you how this project works. The pin of the relay module is set HIGH when the bottle is detected at a range of 2-3 cm away from the ultrasonic sensor. When the bottle is taken out of range, the relay module is automatically switched off. Now, I will explain you the codings.The ultrasonic sound sensor has an ultrasonic wave transmitter and receiver. A transmitter emits a signal which is reflected off an object - within 2 cm to 400 cm - and received by the receiver. The time taken for the signal to travel from the transmitter to the receiver is divided by two and multiplied by the speed of sound in air to give us the distance between the sensor and the object.
Create global variables for the trigger pin, echo pin and the relay module. You must also create variables for the duration and distance. The type of variable for the duration must be long, and that for the distance must be int.
Within void setup( ), configure whether the pins of both ultrasonic sensor and the relay module are INPUT or OUTPUT. Within void loop( ), set the trigger pin LOW for 5 microseconds before setting it HIGH. Set a delay period of 10 microseconds to emit an ultrasonic pulse before setting the trigger pin LOW. Read the duration of the pulse using pulseIn( ) function and wait for the echo pin to go HIGH.
Calculate the distance by using simple high school mathematics and physics.
- Distance = Speed of ultrasonic pulse in air x Duration
- 1 microsecond = 1e-6 seconds
- Speed of ultrasonic pulse = 3 x 10^8 m/s (3e8 metres per second)
* Note: Before calculating the speed, please don't forget to divide the distance by 2, because the pulse is reflected off by an object. If you still don't understand, please feel free to comment below. I can help you with it.
As I already mentioned, the relay module must only be switched on when the object (in this case: bottle) is kept within 2-3 cm away from the sensor. To do this, you must use the 'if ...else' function.
**Note: I am sorry for not uploading the image of this project's codes. I am trying to upgrade this project so the codes are still being developed. Once I complete them, I will make sure that I upload the codes.
If any of you have doubts with the codes, please feel free to comment below or send an email to arduinoprojectsbyr@gmail.com.
Plz plz will you give me the complete circuit diagram of it
ReplyDeleteSorry. The diagram will be available after this project is completed.
Delete