hi welcome to an Arduino step-by-step course by Robojax if you found this tutorial helpful please
thumb up and also click on the subscribe on the right side in the lower corner I really appreciate
it this video we are going to test and see this NJK5002C Hall magnetic sensor going to turn on
and off an ac bulb using magnetic field detection this is the hull sensor and the model number is
NJK 5002 c finally we are getting something from eb and an AliExpress that has a model number
and internally this has a hall sensor the job of heart sensor is to detect a magnetic field
when a magnetic field or a magnet is close to this it detects it and will send low signal this also
has a light here when it detects it this can operate between 5 to 36 volts it draws around
10 milliampere very low current any magnet or magnetic field that approaches at this point this
will detect it so it can have multiple application and robotics and production line and automation
that it detects position of either object that has magnet so what you do is you will either
put magnetic actual magnet on the other piece or electromagnet that attached to the arm or
to the a element that is getting close to this one or maybe the other piece is a stationary
and this is attached to something that moves so you will have a you will have a magnet a certain
position and when it approaches gets closer this will turn on and it has length of this wire as
112 centimeter or 44 inches the module weighs 40 grams the diameter is 11.7 millimeter
the snot is 16.5 millimeter the length of this sensor up to this point is 31.8 millimeter
also this led will turn on when it detects a magnetic field close to it I’ve got these pin
headers which I’m going to attach to this these wires this will be connected to five volts this
will be connected to the ground this is the output from this with the low trigger I’m
going to explain it in the code and on the diagram and here this has just not and also
briefly explaining you the relay the relay has three pin s here these two pins are normally
o pin and this one is normally closed whatever wiring you do you always will have your one wire
at the middle and the other will be either here which will be normally closed and here
which will be normally o pin what it means is when the signal comes to the relay these two wires will
connect this side we have vcc which will be connected to 5 volts ground will be connected
to the ground and n will be connected to the input of your Arduino which is pin 8. this green light
will turn on when it receives signal and relay is energized led will turn on when you
connect the relay to 5 volts when you're using relay pay attention to the current rating of
relay for example this is a very tiny relay and the current rating is 2 ampere for 30 volts 0.5
ampere 400 volts and 0.6 ampere 425 volts this is the amount of current that it can handle and
this can handle 10 ampere at 28 volts and 10 ampere at all voltages 120 and 250 and 30 volts
so to understand how much this can handle in north America the voltage is 120 volts time times 10
ampere is 1200 watt or 1.2 kilowatt if you're in Asia and Europe uh the voltage is let's say
220 or 240 volts for 220 times 10 is 2200 watt or 2.2 kilowatt death relay can handle and the
same way this one you have to also multiply the voltage times the current to get the power and the
same way this is a 12v relay but the rating is 10 ampere for majority of the voltages to avoid fire
and overheating do not allow the current above the rated current to pass through this relay
and here is a setup and diagram that I have done the positive five volts this is five volts
connected to the vcc and to the uh hull sensor and this ground or negative is also connected to
the ground of this relay and to this sensor and this black wire is connected to the in of this
relay and my load is also connected to the bulb so this is my bulb
now and this is connected to the ac load and magnet b proximity of this sensor
this is an ac desktop bulb and this is a power plug that I connected to the wall 120 volts which
will turn on and off now at this point I’ve cut one of these two wires at this point and twisted
it and soldered it can be connected to relay job of relay is to connect this and the ac bulb is on
or ac load whatever fan you have and disconnect it to turn it off so I will be connecting these
two to the relay my ac bulb now ac load is connected to this relay I’m not touching it
and this is a sensor and if I put the north pole of the
magnet it will not be triggered so the position of the sensor inside is such that it will be
triggered only with the south pole and here's the slide and also you will see it there so it's you
can have electromagnet or whatever way of magnet but the polarity is very important because this
will not work it will not work from even this distance so you have to be very close
and it will not work from the side
because the metal is blocking the path of electromagnetic field
from the sensor we have the three wires the brown is connected to five volts
blue is connected to the ground and the black is connected to pin two for the relay
vcc for the relay this vcc is connected to five volts the middle one is connected to the ground
and then the last one which is the n the orange one connected to pin eight
the two wires of the ac bolt that I showed you are connected to these two pin of this relay
let me now explain the code we first defined the sensor pin,
pin two there is no semicolon or anything so you can use any digital pin that you want to use make
sure it's available and this is a relay pin pin eight we will use this pin to connect to the relay
and this weight variable of type integer is 3 000 milliseconds or 3 seconds this is the amount of
time that when the switch turns on the relay you want to wait this amount of time if you wanted
this one to be real time just make it zero as soon as the switch is off the relay will be off
it's up to you inside the setup which starts from here to here this code will run only once we use
pin mode we say pin mode sensor pin which we have defined here pin two this is as if we type
two here and we say input pull up because this sensor needs a pull-up resistor I’ve explained
it a separate video in this link you can watch it so it just eliminates usage of extra resistor
and then we go pin mode and this time we relate and define the relay pin as an output this was
as an input this is an output and we initialize the serial monitor with 9600 baht so we can print
this text for us here and this must match the 9600 bar on this side must match this number in order
to be able to read it inside the loop which starts from here to here this will run continuously
we do the digital read sense pin we are reading pin two and the result of this either if it's
sensed or not will be stored in the sense sensed integer because the sense is either 0 or 1 so
we are storing it in an integer so 0 or 1 in Arduino means low or high then we say f sensed
equal equal low this equal is used for comparison one equal is for assignment we assign value but
here we compare we say if sense is equal equal or if it's low then we print this on the screen here
it will show it like this and then digital right relay pin low this goes to pan 8 and sets it to
low because my relay is low trigger I put low if your relay is different put high so turn on mean
put it to low and also wait for the amount of time that you set above and if there is no weight or
the weight is zero it just go immediately after that and if it's not load the sensor is not load
then we you go to the else and we say digital right relay pin high this now turns off the relay
again as the above if you're reversing this if this is high this must be low if this is low this
must be high so changing change it accordingly if in my case it's just high and then I just
print this one to print this dash I didn't say sense or anything to show that there is something
it did not detect anything 300 milliseconds is the weight to avoid hysteresis or continuous
connection on this connection so you can play with this but my experiment 300 milliseconds was good
let me now demonstrate this is a serial monitor the release connected this is my ac bulb here
and the proximity sensor is here now if I put this
closer will turn on and also you can see it's just sensed it needs to be very aligned
a little distance will not work even like this it will not work so the pool must be on this side
and also as you can see the light the led will turn on here
if I put the other pole the north pole
will not work the magnetic field now goes like this it must be within this area
if I’m holding it just continuously shows sensed
the amount of time that is running at the moment was zero so if I make this three second
now this is set at three seconds
if I remove it within three seconds it's on still
if I set
if I set this zero and if you want respond but this one which is 300 millisecond if I make this
0 now pay attention with this 0 that delay the main delay
so you will not get the result because it will be too quick connect and disconnect I will
suggest play with this to find an optimal time my experience was 300 but maybe millisecond 300
millisecond second and maybe in your application you need 100 millisecond or less or more
thank you for watching this was how to use this njk5 hull sensor please make sure to subscribe by
clicking at the subscribe button in here thank you thank you for watching if you learned something
and found this useful please thumb up as this will help my video in the search algorithm of YouTube
if you have comment or question please post it at the comment section below I try to
answer and reply and don't forget subscribe so you get updates on my upcoming videos you