#10 Tutorial: Make the Arduino Analog Readings more precise

Поділитися
Вставка
  • Опубліковано 23 лис 2024

КОМЕНТАРІ • 122

  • @andyj2106
    @andyj2106 5 років тому +25

    I know you posted this sometime ago, but I just wanted to thank you for doing so. Has significantly improved the accuracy of my Arduinos readings. Brilliant.

  • @MrRfaass
    @MrRfaass 4 роки тому +10

    Very nice video! To increase the resolution, you can add up multiple samples, as there is some uncorrelated noise on the A/D and input signal. To get a more stable measurement you can for example add 4 values and divide by two to get an extra bit. Experiment a bit as there is enough sample time for a reading on a display... averaging cancels out noise.

  • @francoisdastardly4405
    @francoisdastardly4405 4 роки тому +12

    The man with the Swiss accent and super high quality videos !!

  • @mbaksa
    @mbaksa 8 років тому +23

    Nice video. Just a tiny correction - in formula one should use 1024 instead of 1023. It's not the highest value that one should be multiplying, it's the number of values (resolution), and the number of 10-bit values is 1024. So the formula should be VCC=1.1*1024/measured result

    • @AndreasSpiess
      @AndreasSpiess  8 років тому +12

      You are right

    • @mbaksa
      @mbaksa 7 років тому +12

      Actually, I was wrong, and you were right! :) One person explained the issue with my "correction" - it should be 1023 because the maximum value is 1023, and we are basically calculating percentage, not resolution. One should divide by 1024 if one wants to find out resolution - if one wants to know size of the step ADC can resolve.

    • @GRBtutorials
      @GRBtutorials 7 років тому +5

      mbaksa No, you were right from the beginning. See this: forum.arduino.cc/index.php?topic=303189.0 and this: www.electro-tech-online.com/threads/why-adc-1024-is-correct-and-adc-1023-is-just-plain-wrong.132570/

    • @robert574
      @robert574 2 роки тому

      The maximum 10 bit number 1111111111=1023. The math would tell you that the maximum voltage should be 1023. BUT (capitals), the ADC does something you are not expecting. It subtracts one division (LSB) from the reading. To get the full reading you have to use 1024.

  • @rodrigomourapereira266
    @rodrigomourapereira266 4 роки тому +1

    Thank you so much! I'm using a soil moisture capacitive sensor. With your code, my calibration Has significantly improved.

  • @ericgibbs301
    @ericgibbs301 4 роки тому +1

    The ADC of the Arduino is normally ratiometric, as in referenced to Vcc. You can switch to an internal fixed reference of about 1.1V instead. Most external ADCs have their own built-in fixed reference. Both have different use cases.2

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      The point of this video is to use the internal reference instead of VCC, I think.

    • @ericgibbs301
      @ericgibbs301 4 роки тому

      Hi Andreas, My comment seems to have been edited, it is not my original text.?
      As you know the use of a ratio metric ADC means that the supply to the Arduino can vary but the ADC count should track the changes in the supply and give the correct conversion.
      BTW: I am no way being critical of your excellent tutorials.
      Regards Eric.

  • @thevideoboy87
    @thevideoboy87 8 років тому

    Hello Sir, brilliant yet simple way of correcting hardware issue with software. My two ways of correcting this issue were: 1) use a higher supply voltage (2 series Lipo) and a 7805 to power the sensitive projects or 2) use a 3.3v regulator to feed the Aref, which limits the input voltage on analog input pins. Now I have an option #3 (or #0)! Thank you !

    • @AndreasSpiess
      @AndreasSpiess  8 років тому

      Thanks! I am not the inventor, I just liked the concept when I saw it.

    • @ArugaPH
      @ArugaPH 8 років тому

      +thevideoboy87 hello.. I'm having the same problem.. can i use a 12v supply and a 7805 to supply my acs712 current sensors? my reading is pretty bad.. can u give me a sample circuit?

    • @thevideoboy87
      @thevideoboy87 8 років тому

      +Renatzu Agura Hi. the ACS712 consume approx 10mA, which means a dissipation of approx 70mW in the 7805. There should be no issue, make sure to install filter caps on the in/out of the linear voltage regulator. It's always a good idea to put a "dummy" load on the 7805 output, like a small LED+resistor to improve ripple.

    • @AndreasSpiess
      @AndreasSpiess  8 років тому

      +Renatzu Agura Thevideoboy87 is right. I could add that you need short wires between the acs712 and the Arduino to avoid noise pick up.In addition, you also could check with a voltmeter if the "bad reading" comes from the acs712 (disconnect everything else exept the current test wires and the supply voltage and measure directly on the module) already or is somehow created by the Arduino.
      In addition it is always good practice to wire ground as a "star", not a "net".

  • @leandrohugosobrino7741
    @leandrohugosobrino7741 5 років тому +3

    Nice explanation. The problem is that 1,1v internal reference is not so precise. It actually varies between 1.0 and 1.2v

  • @Taran72
    @Taran72 6 років тому +1

    your videos #9 and #10 were extremely helpful: i am putting together my first data logger and the bits of information are good. i will probably apply the code for the keyboard and the OLED to the next project. :) . thank you!

  • @s.sradon9782
    @s.sradon9782 3 місяці тому

    Try use high external voltage and a linear regulator to power arduino, then don't draw much current from the arduino itself - this works well for bigger applications which already use multiple voltages, also make sure to keep arduino away from magnetic fields such as those made by power supplies, motors, power wires and wireless transmitters.

  • @robert574
    @robert574 2 роки тому

    Did you ever take out the kitchen trash, then get out a new bag, put it in the basket and it just wouldn't fit? So you take your hand and thrash it about against the sides until you give up. That's what my brain felt like with the ADC conversion until I went back and watched video #9 again. It was so simple. Put some air in the bag and squeeze the top while you put it in.

  • @pjwlk
    @pjwlk 4 роки тому +1

    You saved me my last little bit of hair. (Not much left to pull out...lol). The precision you have described here is just what I was looking for. Thanks!!!

  • @alphonsesynrem28
    @alphonsesynrem28 6 років тому +1

    Dear sir, again a very good work on reading very precise voltage with fluctuating usb voltages. I had this problem as during testing my uno from the supply of my pc usb, the voltage fluctuats around 4.95 to 5.1 volts according to the pc cpu load etc. After uploading the sketch and when it's built outside the readings are all off. So again to plug to the pc and rewrite the values as per the external 7805 regulator. This video lesson will really help me. I will give it a try. Thank you so much again.

    • @AndreasSpiess
      @AndreasSpiess  6 років тому

      You are welcome. I hope it will do the job for you.

  • @chesshooligan1282
    @chesshooligan1282 Рік тому

    If the Arduino comes with an accurate, built-in voltage reference, you'd think it would use that voltage reference by default (possibly combined with a voltage divider placed in front of the ADC).

    • @AndreasSpiess
      @AndreasSpiess  Рік тому

      I do not understand. We use the built-in voltage reference for this project.

    • @chesshooligan1282
      @chesshooligan1282 Рік тому

      @@AndreasSpiess Yes, I know, I've watched the video. I'm only wondering why that isn't the default. There are several things about these ADCs, that have me scratching my head, especially the one in the ESP32. It's a shame such a great little device is let down by such a poor ADC. It would probably cost a few pence (cents/pennies) to get that fixed.

  • @codebeat4192
    @codebeat4192 2 роки тому

    Tried this on a LG ( LightGreen 328p-LQFP48 ) Nano 'equivalent' but this doesn't seem to work. The VCC function returns -1.00 and with the calculations it will end up as 0.00. Is there a chance to make it work with these type of 'clone' MCU's?

    • @AndreasSpiess
      @AndreasSpiess  2 роки тому

      I do not know. You have to read their datasheets and maybe adapt the code.

  • @effgee123
    @effgee123 3 роки тому

    Great video, thanks Andreas.
    In the video the equation is presented as 1.1*1023*1000 but in the code on github it is actually 1.1*1024*1000. Which is correct ? I assume 1023, since the ADC reading will max out at 1023, and dividing that by 1024 will not give exactly 1.1V

    • @AndreasSpiess
      @AndreasSpiess  3 роки тому +3

      There are different opinions about it. I do not care...

  • @bartdepauw1156
    @bartdepauw1156 3 роки тому

    Hello Andreas. Nice trick ! Would this also work (or even be needed) on the ESP32 (WROOM) ? Need to measure up to 85 volts and I'm wondering if I would use the build in ADC or an additional AD1115 module ( both with resitor divider). AD1115 is higher resolution ( 15b in place of 12b ) and has a build in voltage reference, but 0.02 Volt resolution is good enough

    • @AndreasSpiess
      @AndreasSpiess  3 роки тому

      1. It does not work on the ESP32
      2. I made a video about the ADCs inside the ESP32 and the AD1115

  • @robert574
    @robert574 2 роки тому

    Does the converted analog to digital value of the internal voltage reference of 1.1V, the digital value, change all the time with variations in Vin and Vcc? It would be interesting to see that digital value with changes in input voltage, if I understand it correctly.

    • @AndreasSpiess
      @AndreasSpiess  2 роки тому

      Yes, it changes as shown in the video.

    • @robert574
      @robert574 2 роки тому

      The term was "bit banging", it says "bit panning" on CC. So bit banging is using software to do the job of hardware. That I could look up. Todos los dias apprendo algo nuevo.

  • @christophermalau5299
    @christophermalau5299 8 років тому +3

    Very good video, but I just have to point out that this is making it more accurate not more precise. The number of decimal places is the same each time, so the precision is constant, but the measured value is not close to the actual value, so it is not accurate.
    I'm sure you know this already, just pointing this out to others out there...

    • @AndreasSpiess
      @AndreasSpiess  8 років тому +5

      English is my third language, so I probably mixed the words. So, you are absolutely right and I hope, the video itself is clear.

    • @christophermalau5299
      @christophermalau5299 8 років тому +3

      Wow, third language! I'm currently studying German, it's great

    • @AndreasSpiess
      @AndreasSpiess  8 років тому +2

      But for sure not easy. Keep on!

  • @stevebailey1682
    @stevebailey1682 Рік тому

    Do you have a similar trick for the PICO as it has a noisy ADC as well.

  • @rahulanshan1371
    @rahulanshan1371 6 років тому

    Sir, recently i'm facing a problem when i connect ACS712 20a current sensor to my node mcu 8266 microcontroller.The reading value is not accurate at some points.then i searched on the internet and find out that the current sensor is 5v module while the esp8266 is only giving 3.3v. so how do i fix this?

    • @AndreasSpiess
      @AndreasSpiess  6 років тому

      you get level shifters from 5 to 3.3 volts

  • @Karl_Levine
    @Karl_Levine 4 роки тому

    Andreas thank you.
    You refer to some video "as seen on the previous AMPÈREMETER VIDEO", but you don't link it, and I can't find it, can I get a link please?

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      I did not hear this sentence. But I might be wrong. This is video #10. So there are only 9 which were produced before. And none was about current measurement

  • @TautologyTechSystems
    @TautologyTechSystems Рік тому

    How about a tutorial on how to build that screen?

    • @AndreasSpiess
      @AndreasSpiess  Рік тому

      This is quite old technology. So no more relevant today...

  • @rockabanane
    @rockabanane 4 роки тому

    Thx!! I was already wondering why my PV Energy meter was not correct! Grüße aus München :D

  • @erikvanderleer7790
    @erikvanderleer7790 5 років тому

    Does the ESP8266 have an internal reference voltage which would enable it to apply this method to the analog in readings too?

    • @AndreasSpiess
      @AndreasSpiess  5 років тому

      I never heard of something like in the Arduino.

  • @Gallardo6669
    @Gallardo6669 3 роки тому

    Thank you for the video. But please help: an Arduino has a 10bit system, so for my logic it can only represent 512 values. How the system can actually represent 1024???

    • @AndreasSpiess
      @AndreasSpiess  3 роки тому

      In my world: 2^10=1024

    • @Gallardo6669
      @Gallardo6669 3 роки тому

      @@AndreasSpiess servus Andreas. Had a brain fart. In the mean time I figured it out.greetings from California. Machs gut

  • @newtechai4367
    @newtechai4367 2 роки тому

    i am using an stm32 12bit adc what formular should i use please ?

    • @AndreasSpiess
      @AndreasSpiess  2 роки тому

      This is very Atmel328P specific. So it probably will not work on an STM chip

    • @newtechai4367
      @newtechai4367 2 роки тому

      @@AndreasSpiess ok

  • @ejkitchen
    @ejkitchen 8 років тому

    Great video! Also thanks for the code. Worked great!

  • @wizdumb420
    @wizdumb420 3 роки тому

    Thanks a lot, Swiss man. Here's a one-liner using your help:
    vIN = ((analogRead(voltageSensor_pin) * (readVcc() / 1000.0)) / 1024.0) / .2;

    • @AndreasSpiess
      @AndreasSpiess  3 роки тому

      What was the question?

    • @wizdumb420
      @wizdumb420 3 роки тому

      @@AndreasSpiess my Q was why is this temperature reading wrong. You solved that for me. thanks again. So, I condensed the lines of code to make it smaller.

  • @brandonly27
    @brandonly27 6 років тому

    I have gone from 3 volts to 5 volts with 98 percent accuracy. As long as you tie one of the ground ports of the Arduino to whatever you are measuring, its 98-99 percent accurate. Am i wrong in doing this?

    • @AndreasSpiess
      @AndreasSpiess  6 років тому

      If it is 98-99% accurate it seems to be ok for me.

  • @zedBel4ever
    @zedBel4ever 5 років тому

    Thanks for the post. Is there any such kind of trick for MKR family mine is 1010? I have tested the analogRead(ADC_BATTERY) .

    • @AndreasSpiess
      @AndreasSpiess  5 років тому

      I do not know. Maybe not. They use much different chips

    • @zedBel4ever
      @zedBel4ever 5 років тому

      @@AndreasSpiess Thanks for the fast feedback. Yes the MKR 1010 is based on SAMD21 Cortex-M0+ 32bit chip.

    • @AndreasSpiess
      @AndreasSpiess  5 років тому

      I know

  • @howardsway782
    @howardsway782 9 років тому

    Thank you, a very useful and precise description, good job. Is there something special about the Leonardo in relation to excel ? or can you do the same with the Uno or Mega2560?

    • @AndreasSpiess
      @AndreasSpiess  9 років тому

      +Howard Bailey thank you for your comment! Yes, something is special. Only Leonardo, Due, and Pro Micro can act as an USB host. Only these boards know the command keyboard.print() which I used to transfer the data from the arduino via an emulated keyboard to Excel. If you want to do it with an Uno you could use a usb host shield for this purpose. But I never tried it.
      Just google arduino keyboard.print and you should find more infos.

    • @howardsway782
      @howardsway782 9 років тому

      +Andreas Spiess thanks. I had a look at your other vids (all good) and more on utube, I now realise the Atmega32U4, and some others, have the USB coms built in, i.e. 'Host' USB, I'm learning gradually. It's more difficult 'teaching myself' so videos like yours are a godsend, I look forward to your future posts.

    • @AndreasSpiess
      @AndreasSpiess  9 років тому +6

      +Howard Bailey I learned it the same way you do now. This is the reason for my videos. I want to give back what I got...

  • @Arthurk346
    @Arthurk346 5 років тому +1

    your accent remindes me Toto Wolff (principal of mercedes f1 team). he is austrian

    • @AndreasSpiess
      @AndreasSpiess  5 років тому +1

      I was already compared with Arnold Schwarzenegger ;-) He is also Austrian and our native languages are similar, so our accents.

  • @alanvargheseninan1237
    @alanvargheseninan1237 3 роки тому

    hi .. is there any way to reduce analogue value fluctuation while reading from analogue pin

    • @AndreasSpiess
      @AndreasSpiess  3 роки тому

      This is a complex topic and I cannot give you a short answer. The simplest thin is: Keep the wires short.

    • @alanvargheseninan1237
      @alanvargheseninan1237 3 роки тому

      @@AndreasSpiess wt about adding a capacitor ? since making wires short is not possible . if yes , can u tell me wt value of capacitor should be required ??

    • @incxxxx
      @incxxxx Рік тому

      100u and 100n at the supply input.@@alanvargheseninan1237

  • @PhDFernandoCoach
    @PhDFernandoCoach 7 років тому

    Thank you for this video, Andreas! Could you please explain me the formula
    Vcc = 1.1*1023*1000/measured result ?
    God bless you!

    • @AndreasSpiess
      @AndreasSpiess  7 років тому +1

      I do not remember, how I calculated this (it is a long time since then). It has to do that you measure a value which should be 1.1 volts (internal reference voltage), but in reality, is not, because you measuring is wrong. Maybe you can figure it out if you look at the other calculations in the code...

    • @alfrond
      @alfrond 4 роки тому +7

      In case you or someone else still wonders:
      The ADC returns values 0-1023 proportional to the measured voltage with 1023 corresponding to VCC.
      Proportionality is to say that the ratio voltage/ADC-value is constant for all voltages in its range, specifically this holds for VCC and 1,1 V. We know that VCC is measured as 1023 for any VCC, and measuring our 1,1 reference voltage, the corresponding ratios must be equal:
      1,1 / measured result = VCC / 1023
      This of course also holds for voltages in milli-volts in which case our reference voltage becomes 1,1*1000 mV, and (after rearranging) we get to Andreas' formula. Looking through the code this conversion seems a bit redundant though, as he immediately converts back to volts in line 29 introducing the 'supply' variable (supply = readVCC()/1000.0;)

  • @winandd8649
    @winandd8649 Рік тому

    VERY helpful!! thank you!!

  • @sandyblogs4568
    @sandyblogs4568 4 роки тому +1

    what is the sampling rate of adc

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      I do not know. Maybe you find it in the datasheet

  • @puriap250
    @puriap250 3 роки тому

    That was a great tip thank you.

  • @ChronoGXay
    @ChronoGXay 2 місяці тому

    I don’t understand… you used the number 1023 in the formula you gave at 3:20 because 2^10=1024. These are not the same number. Why not use 1024 in the formula?

    • @AndreasSpiess
      @AndreasSpiess  2 місяці тому

      Because there are only 1023 "distances" between values. But I am not sure which one is correct :-(

    • @ChronoGXay
      @ChronoGXay 2 місяці тому

      @@AndreasSpiess Gotcha

  • @sallen135
    @sallen135 5 років тому

    Hi! Does this work the same for the ESP32?

  • @SodAlmighty
    @SodAlmighty Рік тому

    Why not just switch to the internal reference?

    • @AndreasSpiess
      @AndreasSpiess  Рік тому

      This is what this sketch does.

    • @SodAlmighty
      @SodAlmighty Рік тому

      @@AndreasSpiess I watched the video. You're measuring the internal reference and using that deviation as an offset to fix the inaccurate readings. But if you just switched to using the internal reference as the active reference, it would just work properly anyway.

  • @_tinkerBOY
    @_tinkerBOY 5 років тому

    Will this work with atmega32u4?

  • @Developer981
    @Developer981 Рік тому

    Can i use this for esp32

  • @santoshshivgan6275
    @santoshshivgan6275 3 роки тому

    thank you very much Sir

  • @vivekvenkatsubramaniam437
    @vivekvenkatsubramaniam437 5 років тому

    Hi, Mr Spiess, I'm trying to use the ADC if the nodemcu, which accepts only a maximum of 1V input, so how would this formula be affected?

    • @AndreasSpiess
      @AndreasSpiess  5 років тому

      This is a video for an Arduino, not for an ESP8266.

  • @JavierCamacho
    @JavierCamacho 5 років тому

    I used you code and I'm still getting wrong readings. The fluctuation is from 0.5v up to 1.5v

    • @AndreasSpiess
      @AndreasSpiess  5 років тому +1

      Then something is really screwed up. I would first try to get stable values without the code.

    • @JavierCamacho
      @JavierCamacho 5 років тому

      @@AndreasSpiess I'll keep searching then. Thanks for your time

    • @JavierCamacho
      @JavierCamacho 5 років тому

      Andreas Spiess i think i found the problem. I need to use a voltage divider to lower my input V to match the internal reference

  • @MrScrewy
    @MrScrewy 8 років тому

    Thanks a lot! very usefull

  • @beaconofwierd1883
    @beaconofwierd1883 6 років тому

    Trying to use an Arduino for a high speed, "high" accuracy application, and getting fluctuation on the first digit, is this fluctuation likely due to the supply voltage from the Arduino fluctuating or is it just inherent noise in the system? Like, would adding a capacitor to smooth out the supply voltage make it more accurate? :)

    • @AndreasSpiess
      @AndreasSpiess  6 років тому

      If the first bit is the one with the highest weight your setup is completely screwed up. If it is the one with the least weight this is what you have to expect. Any source, also the ones you describe can be the reason for that.

  • @SashNone
    @SashNone 7 років тому

    Maybe its too late after two years and you figure it youself already, but. if you write
    analogReference(INTERNAL); // it will limit analogRead to 1.1v maximum input with 1023 value.
    And you can use simple resistor voltage divider to limit any of your input voltage to 1.1v maximum.
    www.arduino.cc/en/Reference/AnalogReference
    You made a huge job with register tweaking... but is it worth it?

    • @AndreasSpiess
      @AndreasSpiess  7 років тому +1

      I think, it is worth it, because you use the internal connection and do not need a divider for that purpose.
      BTW: I did not do the work of tweaking. My contribution is just the communication ;-)