TUTORIAL: How to Measure / Read Voltages Into Arduino - (Part 1/3 Voltages Less than 5v)

Sdílet
Vložit
  • čas přidán 20. 08. 2024

Komentáře • 64

  • @NemonicanatLarge
    @NemonicanatLarge Před 3 lety +3

    Thank you very much....I've gone thru over a thousand code / hardware videos and I must say i anm extremely impressed. You explained that circuit perfectly. All the other sites were losy to bad but yours is good. I will be looking at your other videos as time permits. This one is going to get me by writers block and back to being productive again. Good timing too because my ordered Nano and display just came in last night. So let's go to work.

  • @adjgamer
    @adjgamer Před 2 lety +5

    Super simple, it's already working for me. My cheap aliexpress arduino uno had a different reference voltage as well. I also mapped my input to a different scale to output it onto an 8segment display to use as a tachometer for my car with the map() function. It will be a fun project and you did a great job explaining the adc of the arduino. I was also getting some weird values with no voltage applied but with 0v applied from my power supply it showed a 0v output.

    • @gaurabpokharel6373
      @gaurabpokharel6373 Před 2 lety

      How , I also want to make tachometer so landed here , Can you please share what component used and code ?

    • @mookfaru835
      @mookfaru835 Před rokem

      I'm getting weird values too when no voltage is applied. with 2 arduinos.

  • @benediktschluter7313
    @benediktschluter7313 Před 5 lety +3

    Thx a lot for the hint that the reference voltage may not be exactly 5V. I just measured mine and found out that it is 4.99V when the Arduino is connected to the power supply and only about 4.86V when powered by usb. Of course I was only using USB and man I was wondering why the measurements were so off! :) Thx again!

  • @Gallardo6669
    @Gallardo6669 Před 2 lety +1

    FINALLY!!!!! SOMEONE WHO ACTUALLY CAN REALLY EXPLAIN THE PROBLEM AND THE CODE STEP BY STEP! T H A N K. Y O U !!!

    • @AntonyCartwright
      @AntonyCartwright  Před 2 lety

      Thanks!

    • @Gallardo6669
      @Gallardo6669 Před 2 lety +1

      @@AntonyCartwright could you make a video where you actually use the same battery or two in series to power the Arduino? I read if doing wrong, power can be backfed into a pin and through the rest of the chip destroying it. Thx.

    • @AntonyCartwright
      @AntonyCartwright  Před 2 lety

      @@Gallardo6669 Hi, unfortunately I can't make a video on that at the moment, however, I can answer it for you. The battery could wreck the Arduino if you fed it directly into a random pin, however, the VCC/RAW pins are exempt from this. These pins are designed to handle the current. If you wanted to power the 5v arduino using this 4.2v cell, it would work if you fed the VCC pin with it. If you are trying to power a 3.3v arduino with this cell, then use the RAW pin. The raw pin has a regulator behind it which makes higher voltage safer. Antony...

    • @Gallardo6669
      @Gallardo6669 Před 2 lety +1

      @@AntonyCartwright thx! I plan on using 2 18650 in series to power an 5volt Arduino uno. As the voltage goes down over some hours, the voltage regulator on the board would still get something over 6,4 volt in and it still regulates itself to 5v for the board.
      So far so good. But, can I now use a voltage divider to bring the 6,4 battery voltage down to use it for an analog pin? On top of that, to be safe, I could go off the voltage devider and go through a 10kohm resistor before going into the analog pin? I don't know if it's needed but someone mentioned it for a similar project, trying to prevent a too high current across the atmega...?

    • @AntonyCartwright
      @AntonyCartwright  Před 2 lety

      @@Gallardo6669 The 18650s have a capacity of sometimes near 3000mah and the Uno uses around 50ma, so your battery pack should probably last 60hrs. The cells shouldn't be discharged to less than 3.6v ideally. Both together would give you 7.2vnom, or 8.4vmax. That's ok for the raw pin but not the vcc pin.
      If you want to find the battery's voltage, then yes, you'd use a voltage divider. This splits the voltage down to an Arduino-friendly voltage for you so that you can read it. You can put the anode to the raw pin and the start of the divider. The battery would be 8.4vmax, so you could use a 50:50 divider to keep it simple. If your battery was fully charged, the Arduino would read in 4.2v (half) on the ADC. To make this happen, you could use any resistors which have the same value. You could theoretically use 1ohm and 1ohm, and the divider would work! However, in reality, you'd never do that because that's way too low resistance for what you're trying to d -, the battery would love to shoot electric through that circuit, the wires would get extremely hot, the divider itself would draw approx 4 amps and it would burn through anything in its way to ground! (Maybe burn through your computer's USB/motherboard or burn through the Arduino to get back to the negative of the battery. It would drain your battery pack in about 40 minutes! If you make the resistors 10k, then the divider would draw approx 0.4ma which is much, much safer! You could even use 20k resistors but the signal may be too weak. Basically, whatever you connect to the pins, make sure it stays below 20ma and 40ma in total for all pins... Oh, always remember: electricity always takes the path of least resistance and it has no emotions. 🤣🤣🤣

  • @Estudio322
    @Estudio322 Před 4 lety +2

    Great video, i thought the same about the resistor in series, because the lithium ion cell that im using is actually powering the arduino itself, thank you very much!

  • @satreaaji
    @satreaaji Před 2 lety +2

    the difference voltage reader is because you add resistor on (+), to limit current, better to add resistor on (-)

  • @vedatorpeta
    @vedatorpeta Před 3 lety +1

    great tutorial, thanks, I am going to use it in my mini arduino project :) There will be GPS, GSM, temperature, pressure and humidity sensor and other things. But It will be in the 55x37x20mm box :D

  • @Revision369
    @Revision369 Před 5 lety

    brillianttttt..... this code is the most easy and straightforward that ive found , cheers

  • @DesertVox
    @DesertVox Před 11 měsíci

    THERE is an internal reference of 1V that can be used through code.

  • @mohfa1806
    @mohfa1806 Před 6 měsíci

    Hello ,
    Thank you for your great videos...iam new to arduino but learning...i have question please :
    The cell is connected in series with the resistor and then the resistor is connected to A0 and A0 is connected to ground , so how can the A0 pin reads the voltage across the cell ? .
    Thank you in advance

  • @BahadirKatipoglu
    @BahadirKatipoglu Před 3 lety +1

    How about using AREF pin for more generic solution?

  • @caseylocke4474
    @caseylocke4474 Před 5 lety +1

    So this is a super helpful video and thank you very much for it! One question I do have...in the serial monitor, you were getting the voltage reading only every OTHER number. There was another much smaller number that alternated with it. What is that and why?

  • @user-mt3hj8td4c
    @user-mt3hj8td4c Před 3 lety +2

    Thank you, but I do not understand why doesn't the resistor you added decrease the neasured voltage?

    • @soret
      @soret Před 3 lety

      Same question here!

    • @JasonGlisson
      @JasonGlisson Před rokem +1

      Resistors restrict current, not voltage.

  • @kurtguevarra9262
    @kurtguevarra9262 Před 5 lety +2

    What does the low reading (800 and 300) every other reading mean?

  • @JohnSmith-xn3fr
    @JohnSmith-xn3fr Před 6 lety +1

    Why do you think a 10k resistor in series with the PSU (battery) is needed ?
    The ADC has an input impedance (resistance) in the range of MegaOhms.
    How can the ADC draw too much of a current ?

    • @AntonyCartwright
      @AntonyCartwright  Před 6 lety

      John Smith Hi Mr Smith, I used to think that too, but without the resistors, the cell can power the arduino! Try it if you like... Take the usb port out but have a few pins from arduino to the cell. The cell will power the arduino! :)

  • @ClownWhisper
    @ClownWhisper Před 2 lety

    a battery is indeed a device

  • @squidben5780
    @squidben5780 Před rokem

    Insstead of calculating a value, cant you get the value from the 5v pin on the arduino and use it in the calculation ???

  • @ifell3
    @ifell3 Před 2 lety

    Awesome!

  • @yousaftoki1599
    @yousaftoki1599 Před rokem

    I like it...

  • @dickbrock
    @dickbrock Před 3 lety

    Thank you!

  • @the4hunters
    @the4hunters Před 4 lety

    Brilliant

  • @maheshcherlapelly
    @maheshcherlapelly Před 4 lety

    Am using stm32 so I need max 3.3v analog voltage & my step down transformer output voltage is 0 to 24V can you please suggest me resisters number to use.

  • @ivanpiineda
    @ivanpiineda Před 3 lety

    Any tutoríal, how to measure, diode voltage drop?

  • @hrperformance
    @hrperformance Před 3 lety

    thank you!

  • @mariaantoniavogelerbalcaza8729

    Thank you for this! Do you know how I could record weaker electrical signals? Up to 150 mV with a 0.1mV step? Any help is appreciated!!

    • @arhamupadhye5157
      @arhamupadhye5157 Před 2 lety

      You should certainly use a high gain amplifier. I would recommend using LM358 high gain amplifier module for millivolts. Hope this helps!

  • @BasilHerb
    @BasilHerb Před 4 lety

    Thanks for the Tutorial.
    I do have a question about some of this.
    The Delay messes with RC Cars because of the control Delay, is it possible to remove the Delay? Will that mess anything up?
    Or rather, is it possible to exclude this from the loop and make it it's own Void Function?
    Thanks for you time!

    • @mydarkguy
      @mydarkguy Před 3 lety +2

      I believe the delay's purpose is just for looking at the values, if there was no delay the numbers would flood in too quickly.

    • @AntonyCartwright
      @AntonyCartwright  Před 2 lety

      @@mydarkguy That's right. Sometimes, the Arduino can't cope of you try to do things too fast. The delay timing isn't necessarily thought through though. Maybe 1ms is enough - maybe too much. Maybe not...

  • @robertdbettis
    @robertdbettis Před 4 lety

    Could this work for reading power generated with a simple hand crank generator?

  • @codewithmarley
    @codewithmarley Před 2 lety

    Thank you a lot! Do you also know how chose the amount of amps I am outputting? @Antony Cartwright

  • @blackz06
    @blackz06 Před 3 lety

    Why is it fluctuating 10s of millivolts?

  • @ALLINONE-ec9jq
    @ALLINONE-ec9jq Před 2 lety

    i want make voltage current monitor for solar charger on mobile can you wrte a code for me?

  • @kevinmac5798
    @kevinmac5798 Před 6 lety

    Will this work on the ESP 8266 and ESP 32? I have a few Battery powered temperature and humidity sensors that i would like to monitor the battery voltage.

    • @AntonyCartwright
      @AntonyCartwright  Před 6 lety

      Kevin Mac it will work the same way but you need to check the adc voltage of the modules...

  • @RoyAndrews82
    @RoyAndrews82 Před 2 lety

    Hi Anthony, can you please tell me why the readings change constantly (821, 823, 823, 825, etc.) without any user interaction? Is it 823 or is it 821, 823, 825, 824, etc ? My digital Multimeter, car Speedometer, microwave clock/timer doesn't fluxuate, why does the reading change so much? Thanks.
    czcams.com/video/lec7kPv3VS8/video.html

  • @nicholaslabrecque
    @nicholaslabrecque Před 4 lety

    oooor power through the vcc pin and read it directly from that

  • @NemonicanatLarge
    @NemonicanatLarge Před 3 lety

    BTW wouldn't changing the resistors to 100 Megs be better as we're going to be watching 24/7 and we don't want to drain the battery and "defeat the purpose" of which they exist

  • @idvfpv
    @idvfpv Před 4 lety

    do i need to use float, i want the program to be on a attiny85 and it has not that much memory...

    • @jonasschindzielorz
      @jonasschindzielorz Před 4 lety

      the counts are integers
      the voltages probably need to be floats though

  • @CARRY_ON1909
    @CARRY_ON1909 Před 6 lety +2

    Vitórias amigo

  • @mikerilling2745
    @mikerilling2745 Před 9 měsíci +1

    You measure voltages in Arduino with a volt meter
    there I just save you 17 minutes

  • @roamingcelt
    @roamingcelt Před 2 lety

    Save all the math and make your code quicker and cleaner.
    float mV = counts / 5f; // change 5f to actual refV
    One line of code instead of 4.

  • @hacktheplanetraktor325

    Any voltage ?, Can I try with 100v Ac ? 😜

  • @korishan
    @korishan Před 6 lety +2

    Awww, you didn't include the auto-adjust reference code 😜

    • @AntonyCartwright
      @AntonyCartwright  Před 6 lety

      Is that with the internal reference?

    • @korishan
      @korishan Před 6 lety

      Yeah. It auto compensates for what ever the internal voltage is. The nice thing is you don't have to wire anything up to it, it can just do it.
      The only issue really is, you need to do a few blank readAnalog()'s afterwards to make sure it switches over before you use the value. At least, that's what the Arduino Dev site said.
      If you want to maintain your accuracy throughout the whole testing phase (referring back to your batter tester), you just put the call at the top of the loop() to update the global variable. If the value changed, then your calculations will be compensated for. This is nice considering, as you mentioned in this video, that the internal reference can fluctuate a little bit.

    • @AntonyCartwright
      @AntonyCartwright  Před 6 lety

      Korishan ok, maybe I'll add it to the capacity checker. :)

  • @fellpower
    @fellpower Před 4 lety

    Hey Antony. U need really really a proper microphone. Its sooo annoying, that i cant hear u in one video - and if im watching a playlist - in another video u are toooo loud. thats not sooo cool.
    And the most important part is, that u dont said, that the measuring of voltages with arduino, depends on the input voltage. so if i change the input voltage of the arduino - the measurement is not correct.