My name is Ahmad Shamshiri and I am presenting this tutorial from Canada.
Hi, welcome to another video tutorial from Robojax. In this video we are going
to see how we can use this voltage sensor for Arduino as you can see this
is the input voltage that is connected so this is detecting it
now this is connected to Arduino and you can see the reading here on the screen
so let me change the voltage so you can see it I've just changed 10.4 let me
just increase it make it 20 volts
so let's get started and explain how we can use it you can get the code for this
project by clicking at the link at the description below which will take you to
www.robojax.com/learn/arduino
Hardware Explained
so this is the module and we have here labeled as ground and then we have the
VCC this is the point that you connect the voltage ground and the point
that you want to measure. and then on this side we have three terminal here if
the S the signal this goes to A0 and then negative goes to the ground the
positive is just useless you don't have to connect it it's not connected to
anything so this is how it looks like so you just unscrew and connect your wires
it's very simple just two resistors but it eliminates a lot of wiring that you
do so it makes life easy. so here is the Width. the Width is 13.7,mm
millimeter
the length of this the length is 26.8mm and the depth or
height is 11 point 6 millimeter .so now I'm going to show you the connection so
let me explain the wiring here now so this goes to the ground of the source
voltage wherever you want to measure and this is the actual voltage so this is
ground so you put it at two points but this must be ground and this side must
be connected to the actual voltage pint. the s the signal is connected to the A0
here and then the negative that is labeled here is connected to the ground
Code Explained
now let me explain the code. I've set here an integer offset that is 20 so
this is a correction value if you see some variation you can add your value
here otherwise you can just set it to zero. so in my case I have added 24
correction after that inside the setup we have setup the serial monitor so you
can see this text that is due to this one and make sure that you have here
this 9600 baud set selected because if this is different you will not be able
to see it so this must match. and then inside the loop which is sourced from
here to here we read we say read analog 0 A0 so that is analog read it reads the
value and stores it in VOLT variable so this is a value between 0 and 1023 in the
next line this method calls map it has a 5 parameter the first one is the value
that you want to map to something so we say get the value of volt which is from
0 to 1023 and map it to 0 and 2500 to the result of this whatever it is
we say plus the offset that is offset that we have here so if your module
works perfectly just set 0 don't touch this it will work fine or completely
remove this whichever way you are comfortable. and then the voltage is now
a value that needs 100 times bigger because we have 2 zeros and here we say
it takes voltage and then divided by 100 so it makes it 100 times small and then
we get the decimal point. so that is very nice otherwise if you just make it from
0 to 25 you will get only 1 volt increment so we get 1 2 3 4 5 or 10 20
and you will never get some numbers in between and then we print this text and
then the value of the voltage will be printed here and then we with 500
millisecond which is half a second before we read again.
so if you want to read it faster, reduce this value if you want to make it slower
increase this value and the voltage will be displayed.
Demonstration
once again for the demonstration as you can see we have here 20 volts so the
maximum that this one till measure is 25 volts because the module is made for 25
volts so now even if I put here 30 volts it measures 25 plus
that 200 millivolts that I put for the offset so that is the maximum that this
can measure but actual voltage is 30 so this cannot do it and there is a trick
which I'm going to explain it to do it. so let me go to the lower voltage as you
can see now we are at 17 so that is 8 point so it's pretty accurate.
so now my multimeter my voltmeter needs some voltage to work so 3.92
How to measure Higher Voltage
so that let me explain the module so this these are the two-wire the input of
the module that we measure and connect and these are the world this goes to A0
here this goes to A0 and this goes to the ground so actually we are measuring
the voltage across this but proportionally we are just adjusting it
so doesn't matters so when we put that connected to a source let's say and a
battery or whatever you're trying to measure there is a 30 kilo ohm and then
7.5 kilo ohm resistor that is defining the voltage and it goes so
two measures let's say the voltage a higher voltage then you can put another
resistor between the two from this point this goes to a 1 so we are putting
another resistor here at this point we are putting another resistor so when we
put the other resistor because we cannot change this this is depending on the
voltage we can select now here is a calculation let's call that our X the
unknown R so our X is equal V X the voltage that you are measuring minus 25
over this 25 over 30 kilo ohm seven point five kilo ohm this has amount of
the current so R is equal V over I so we are getting the voltage here and that's
our formula now let's say you're trying to measure 120 volts and you want to
find out what resistor is needed then 120 minus 25 divided by this is hundred
142.5 kilo ohm so you need to put hundred and forty two point
five kilo ohm resistor here and then connect this to up to 120V
volts and then you will be able to measure but accordingly you have to
change this one here four hundred and twenty volts just put hundred and twenty
and then two zeros that we put so then it will work fine and for any other
voltage just remembers just extra two zeroes because here we are
dividing by hundred if you put 1 0 divided by 10 if you put 3 zeroes
divided by 1000 so this is just an example at this point just put 142 kilo
ohm resister and that's a ground then connect and then connect this point to
the point that you are measuring with a ground thank you very much
this was introduction to this voltage sensor please thumb up 👍 the video please
share it and also subscribe and also you can see a lot of other projects and
codes that we have at the www.robojax.com/learn/arduino
Subtitle typed and corrected on May 04, 2020
This is very hard time of COVID-19. I did my part to help you learn.
Now you can simply subscribe, thumb up 👍 this video and say something in the comment section.