Skip to playerSkip to main content
  • 5 years ago
This guy showed off his talent by creating an automatic hand sanitizer dispenser. He built it in such a way that it could sense hands and pour the sanitizer on its own without the need to touch the bottle. He successfully displayed his creative and technical skills via his DIY invention.
Transcript
00:00Okay, so I'm not going to show you how you can make it from scratch because it's really
00:05easy to make one of these, but I will tell you in general how you can make one of these
00:10and we'll talk about the code also, okay.
00:13So if you see this at first, you need to make one of these containers.
00:16Now the advantage of using this container is like you can also attach the servo motor
00:21and all this thing in this bottle, but the problem will be that for each bottle you need
00:26to like attach a servo at it and that's not efficient.
00:29But with this model, the advantage is you can simply take one of these bottles and put
00:33them inside it, okay.
00:35So like this, okay, and this is the advantage of this model.
00:39So at first you can create this kind of a container, you can make it with a cardboard
00:43or like if you have a 3D printer, that will be much better.
00:47And after making a container, what you can need to do is you need one of these sensor,
00:53one of ultrasonar, you can use ultrasonar sensor or IR sensor.
00:56So what you basically need is you need to detect your hand.
00:59So whenever you will put your hand below this thing, you need to detect it and you can detect
01:04it through the ultrasonar sensor or you can also use IR sensor and there are VD2 sensors
01:09also.
01:10So you can simply put this sensor below or it will be better if you put this thing on
01:15the top, okay.
01:16Top because like many people say that if it is in bottom, in that case the soap can fall
01:21into it, okay.
01:22But if it will be in the top position, then there is no like, there is no such possibility.
01:26So you can put this sensor in the top or bottom also.
01:29Now you need one or two servo motors so that it can actually put this nozzle down.
01:37And here I have used two servo motors as you can see.
01:39So this is, there is one servo motor and there is another one, okay.
01:44But you can also use one, okay.
01:46And these two are actually metal gear servos, but you can use plastic gear too.
01:50And one, depending on your like, how much hard to put this nozzle down is, you can use
01:57one or two servo motors.
01:59And in my design, like I have used two servo motors, then I have used two metal wires here
02:04and then finally put, actually this is a pencil here, okay, I didn't have anything else to
02:09put it.
02:10So I just connected a pencil with these two wires and this is how it's working actually,
02:14okay.
02:15But you can simply put a wire and you can actually attach the wire with this nozzle.
02:20And that will also work, okay.
02:22And then if you see the like orientation of the servo motor, they are different.
02:26So this is, as you can see, in this side the servo is in this way and in this side the
02:31servo is in the opposite way.
02:32And this is because if you put these servo motors in this way, it will be easier to code
02:38in Arduino because whenever you will move the servo X position, X degree, this servo
02:43will also go X degree, okay.
02:45Because like to put this thing down, you need to move the servos in same, in this way, right.
02:50So whenever they will go down, they will go down like this and when they will go up, they
02:53will go up like this.
02:54So if they are in the opposite direction, opposite orientation, in that case, in both
02:58servos you can put a single angle.
03:01So whenever this servo is 45 degree, this will be also 45 degree, okay.
03:05And if you put them in the same orientation, you need to change a few things in the code
03:09actually.
03:10Okay.
03:11Now let's talk about the connections actually.
03:13So basically here you have V in, V positive, V in and ground.
03:17So like this, as you can see, there are, in this servo, if you see, like there are
03:20four pins, okay.
03:23And there is a one V in pin, one ground pin and one trigger and echo pin.
03:27So V in will go into the 5 volts of Arduino, V in will go to the 5 volts of Arduino and
03:31ground will go to the ground of Arduino, as you know.
03:34And trigger and echo pin, you can attach trigger and echo pin anywhere.
03:37So I have used pin number 2 and 3, I think, but you can use any pin, doesn't matter at
03:42all.
03:43Now coming to the servo, like as you know that in a servo, there are three wires, as
03:46you can see.
03:48So there are, actually there is a red wire, there is a orange wire and there is a brown
03:52wire.
03:53Okay.
03:54The red one actually signifies 5 volts, I mean, V in.
03:57The brown one actually signifies that it's ground and orange one is a signal.
04:03So you need to put the red one into positive 5 volts and then the brown one to the ground
04:11and orange one to the signal pin.
04:14Okay.
04:15So the signal pin must be a PWM pin, okay, because we need to write some PWM signals
04:19there.
04:20So PWM pins are in Arduino UNO and Nano, it's pin number 3, pin number 5, pin number 6,
04:27pin number 9, and there are very few pins, all of these pins are PWM, so you can use
04:31any of these pins for the signal pin.
04:33Okay.
04:34And another important thing is if you are using metal gear servos and especially more
04:37than one metal gear servo, in that case, your Arduino will not be enough powerful to give
04:42the whole power.
04:43So in that case, you need to use the external power supply.
04:45So in my case, I have used external power supply, as you can see.
04:48So here if you see, I have used external power supply.
04:55So what I have is, I have connected this USB cable and from this wire, I have put this
05:00USB 5 volts to the V in of Arduino and the ground to the ground of Arduino.
05:06So this is a way you can power up your Arduino, then I will put this USB to any power bank
05:11or wall adapter, like 5 volts wall adapter, and it will work just properly.
05:16So if you are using more than one servo, you can use this external power supplies to power
05:21them up.
05:22Okay.
05:23And so this is all about the connection, it's pretty easy.
05:26Now let's talk about the code in Arduino.
05:30Okay, so let me explain you the connections again with this diagram.
05:35So as you can see, it is the ultrasonic sensor, here is the Arduino Nano, two servo motors
05:39and one battery.
05:41So instead of a battery, you can use a 5 volt source actually.
05:44So it can be a power bank or I think mobile adapter or, or whatever you have, but it must
05:49be 5 volts.
05:51So here as you can see, the 5 volts of the ultrasonic sensor will go to the V in of the
05:56Arduino, then the ground of the ultrasonic sensor will go to the ground of Arduino.
06:03Then we have trigger and echo pin.
06:05For the trigger pin, I have used pin number two and for the echo pin, I have used pin
06:09number three.
06:10Now we have two servo motors.
06:12For both of them, the 5 volt will go to the V in and the ground will go to the ground.
06:18And then here we have two signal pins.
06:21So I have used pin number five and pin number nine for the signal pins, okay.
06:25So you can use any PWM pins, so five and nine both are PWM pins.
06:29So and finally, we have an external power source and I have powered it through.
06:34So the positive of the power source will go to the V in of Arduino and the negative will
06:38go to the ground of Arduino.
06:40And basically from this external power source, all the other components are also getting
06:45the power.
06:46So if you have a single servo motor, in that case, you may not need external power source,
06:50you can simply power through the Arduino USB.
06:53But if you have, you are using more than one servo and you are using metal gear servos,
06:58in that case, you may have to use one of these external power sources, okay.
07:04So this is about the connection.
07:06Now let me open the Arduino and explain you the code.
07:10So this is how the code actually looks like.
07:11So it's a pretty small code.
07:14So at first you need two libraries, the servo and ultrasonic.
07:17So I think servo library is already pre-installed in Arduino.
07:20And for the ultrasonic one, you need to go to sketch, include library.
07:25And from here you need to go to manage libraries.
07:28So in manage libraries, it will take some time to download the indexes.
07:33You can search for ultrasonic, okay.
07:38And if you search for ultrasonic, you will get many libraries.
07:41So the one I am using is, yeah, this one I am using.
07:47So ultrasonic by Eric Simons, I think.
07:51So you can use this one.
07:52So I am using this one actually.
07:55And as you can see, so at first we are importing the two libraries.
07:59And then here I am creating two, like you can see instances of servo class.
08:04So basically I have two servo motors.
08:07That's why I am creating here two, myservo1 and myservo2.
08:10If you have one, you can create only one.
08:13And then also I am creating an object of this ultrasonic, okay.
08:17And here one thing is important.
08:18As you can see in the ultrasonic in the bracket, I am mentioning two comma three, which basically
08:24means for the trigger pin, I am using two and for the echo pin, I am using three.
08:29So if you are using different pins, in that case, you need to write different like those
08:33pin numbers here, okay.
08:35And then here are some variables.
08:38And now in the setup, we have to at first myservo.attach9 and myservo2.attach5.
08:44This is because, so basically for servo1, I am using pin number nine and for servo2,
08:50I am using pin number five.
08:52But again, this is because my orientation is like I have already shown you.
08:57So due to that, it doesn't matter for me the servo number because both of my servos
09:04are going to move in the same degree.
09:07But if you are using a different orientation for the servos, you need to like take care
09:12of these things.
09:14And then for myservo1 and myservo2, I am writing 30 degrees.
09:17So basically, when these two lines will be executed, both of the servos will create like
09:24they will move in angle of 30 degree.
09:26So why 30 degree?
09:28Because it is actually working pretty well with me.
09:32And depending on the your wire length and like how the like orientation is, you can
09:37change the initial position.
09:39So this is the initial position actually of your servo, like initial angle.
09:44And now the loop.
09:45So in the loop, as you can see, at first in the distance variable, I am getting the ultrasonic
09:50read.
09:51That basically means it will find like the distance between the ultrasonic sensor.
09:56And if anything comes between it.
09:57So whenever you will put your hand in above the ultrasonic sensor or near of it, in that
10:03case, if the distance is less than 20, so you can also change the distance according
10:08to your needs.
10:09In my case, I have used 20 semi, but you can use according to your needs.
10:13So as you can see, if the distance is less than 20, so here you can change the value
10:16with like 10, 15, whatever you want.
10:19So this basically represents the distance.
10:21So whenever the distance between your hand and the sensor will be less than 20, this
10:26function will be triggered.
10:28So this all the statement will be executed.
10:32So and here as you can see, so basically whenever the distance will be less than 20, the servo
10:39will start from 30 degree and it will end at 180 degree, both of the servo.
10:43So as you can see, this is actually for a position 30 to 180.
10:48I am writing my servo 1 and my servo 2 both.
10:52So and I am increasing it by 3.
10:55OK, now why 3?
10:57You can use 1, 2, 3, 4, whatever you want.
10:59But depending on this value, your speed will change.
11:02So if I write 1 here, so basically at first it will move the servo at 30 degree and then
11:08it will be 33, 36, 39, like this it will increase.
11:11But if you write here 1, then it will move slowly.
11:14If you write here like a bigger number 6, it will move fast.
11:18So that's the difference.
11:19So 3 works pretty well for me and I am writing that angle to both of my servos and then I
11:24am giving a delay of 15 milliseconds.
11:29And this is about, this is when, so this will happen when the like the servo will go down.
11:35So it will put the nozzle down and then again we need to put the nozzle up and for that
11:40from 180 degree, we have to like move the servo to the angle of 30 degree.
11:45So the initial position and the same technique, we will like decreasing the angle by 3 and
11:50again we will write those angles on the servo.
11:53And then finally we are giving a 15, 10 milliseconds of delay.
11:57So that is the whole code.
11:58So basically whenever the distance will less than 20, it is going to put the nozzle down.
12:03This part will put the nozzle down and then this part will put the nozzle up.
12:08And you can change this, like I said, these numbers to like your, according to your needs.
12:13So after that, after you are write this, you can go to tools and you need to connect
12:17your Arduino with the computer.
12:25And after that you will see that in the port option.
12:29So to see in the port option, you will see port, you will see like in my case it is showing
12:35two ports, but you will get a port for the Arduino.
12:38In my case, I know that COM5 is the port for Arduino.
12:41So you need to select that port and then you can simply upload the sketch, okay.
12:49And it will take few seconds to upload.
12:57So it is compiling the sketch and it is uploading it and it is uploaded successfully.
13:05So this is how it will work.
13:10And now even if you can also like test it.
13:13So whenever you will put your hand now on the sensor, as you will see the servos are
13:18rotating perfectly.
13:19So this is working pretty well.
13:22And at the end of the day, this will look something like this.
13:40Thank you for watching this video and I hope you liked it.
Comments

Recommended