#10 Tutorial: Make the Arduino Analog Readings more precise

  Рет қаралды 82,817

Andreas Spiess

Andreas Spiess

Күн бұрын

Пікірлер: 122
@andyj2106
@andyj2106 5 жыл бұрын
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.
@francoisdastardly4405
@francoisdastardly4405 4 жыл бұрын
The man with the Swiss accent and super high quality videos !!
@MrRfaass
@MrRfaass 4 жыл бұрын
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.
@mbaksa
@mbaksa 8 жыл бұрын
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 жыл бұрын
You are right
@mbaksa
@mbaksa 7 жыл бұрын
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 жыл бұрын
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 жыл бұрын
Thank you so much! I'm using a soil moisture capacitive sensor. With your code, my calibration Has significantly improved.
@AndreasSpiess
@AndreasSpiess 4 жыл бұрын
Glad it helped!
@Taran72
@Taran72 5 жыл бұрын
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!
@AndreasSpiess
@AndreasSpiess 5 жыл бұрын
You are welcome!
@leandrohugosobrino7741
@leandrohugosobrino7741 5 жыл бұрын
Nice explanation. The problem is that 1,1v internal reference is not so precise. It actually varies between 1.0 and 1.2v
@pjwlk
@pjwlk 4 жыл бұрын
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!!!
@AndreasSpiess
@AndreasSpiess 4 жыл бұрын
You are welcome!
@ericgibbs301
@ericgibbs301 4 жыл бұрын
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".
@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
@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 жыл бұрын
There are different opinions about it. I do not care...
@s.sradon9782
@s.sradon9782 2 ай бұрын
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.
@AndreasSpiess
@AndreasSpiess 2 ай бұрын
Good idea!
@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.
@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
@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.
@AndreasSpiess
@AndreasSpiess 2 жыл бұрын
Exactly ;-)
@alphonsesynrem28
@alphonsesynrem28 6 жыл бұрын
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.
@stevebailey1682
@stevebailey1682 Жыл бұрын
Do you have a similar trick for the PICO as it has a noisy ADC as well.
@AndreasSpiess
@AndreasSpiess Жыл бұрын
I do not use the Pico often :-(
@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.
@ejkitchen
@ejkitchen 7 жыл бұрын
Great video! Also thanks for the code. Worked great!
@AndreasSpiess
@AndreasSpiess 7 жыл бұрын
You're welcome!
@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 жыл бұрын
+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...
@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
@ChronoGXay
@ChronoGXay Ай бұрын
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 Ай бұрын
Because there are only 1023 "distances" between values. But I am not sure which one is correct :-(
@ChronoGXay
@ChronoGXay Ай бұрын
@@AndreasSpiess Gotcha
@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.
@winandd8649
@winandd8649 Жыл бұрын
VERY helpful!! thank you!!
@AndreasSpiess
@AndreasSpiess Жыл бұрын
You are welcome!
@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
@puriap250
@puriap250 3 жыл бұрын
That was a great tip thank you.
@AndreasSpiess
@AndreasSpiess 3 жыл бұрын
You are welcome!
@christophermalau5299
@christophermalau5299 8 жыл бұрын
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 жыл бұрын
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 жыл бұрын
Wow, third language! I'm currently studying German, it's great
@AndreasSpiess
@AndreasSpiess 8 жыл бұрын
But for sure not easy. Keep on!
@rockabanane
@rockabanane 4 жыл бұрын
Thx!! I was already wondering why my PV Energy meter was not correct! Grüße aus München :D
@AndreasSpiess
@AndreasSpiess 4 жыл бұрын
You are welcome!
@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
@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.
@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.
@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
@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 11 ай бұрын
100u and 100n at the supply input.@@alanvargheseninan1237
@TautologyTechSystems
@TautologyTechSystems Жыл бұрын
How about a tutorial on how to build that screen?
@AndreasSpiess
@AndreasSpiess Жыл бұрын
This is quite old technology. So no more relevant today...
@sandyblogs4568
@sandyblogs4568 4 жыл бұрын
what is the sampling rate of adc
@AndreasSpiess
@AndreasSpiess 4 жыл бұрын
I do not know. Maybe you find it in the datasheet
@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 жыл бұрын
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 жыл бұрын
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;)
@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.
@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.
@santoshshivgan6275
@santoshshivgan6275 3 жыл бұрын
thank you very much Sir
@AndreasSpiess
@AndreasSpiess 3 жыл бұрын
You are welcome!
@sallen135
@sallen135 5 жыл бұрын
Hi! Does this work the same for the ESP32?
@AndreasSpiess
@AndreasSpiess 5 жыл бұрын
No
@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 жыл бұрын
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
@_tinkerBOY
@_tinkerBOY 5 жыл бұрын
Will this work with atmega32u4?
@AndreasSpiess
@AndreasSpiess 5 жыл бұрын
I do not know
@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.
@Developer981
@Developer981 Жыл бұрын
Can i use this for esp32
@AndreasSpiess
@AndreasSpiess Жыл бұрын
No.
@Arthurk346
@Arthurk346 5 жыл бұрын
your accent remindes me Toto Wolff (principal of mercedes f1 team). he is austrian
@AndreasSpiess
@AndreasSpiess 5 жыл бұрын
I was already compared with Arnold Schwarzenegger ;-) He is also Austrian and our native languages are similar, so our accents.
@MrScrewy
@MrScrewy 8 жыл бұрын
Thanks a lot! very usefull
@AndreasSpiess
@AndreasSpiess 8 жыл бұрын
You are welcome!
@AndreasSpiess
@AndreasSpiess 8 жыл бұрын
You are welcome
@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 жыл бұрын
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 ;-)
Wait for the last one 🤣🤣 #shorts #minecraft
00:28
Cosmo Guy
Рет қаралды 10 МЛН
How it feels when u walk through first class
00:52
Adam W
Рет қаралды 24 МЛН
REAL 3D brush can draw grass Life Hack #shorts #lifehacks
00:42
MrMaximus
Рет қаралды 11 МЛН
How to Use Arduino Interrupts The Easy Way
33:28
Rachel De Barros
Рет қаралды 87 М.
EEVblog #601 - Why Digital Oscilloscopes Appear Noisy
24:37
EEVblog
Рет қаралды 195 М.
Why are my ADC readings messed up? (Arduino example)
5:44
Jacob Sorber
Рет қаралды 6 М.
Arduino MCUs and MCP48XX/MCP49XX Family DACs - The Basics
29:32
Robert's Smorgasbord
Рет қаралды 8 М.
#9 Arduino Data Logger with Direct Input to Excel
10:12
Andreas Spiess
Рет қаралды 129 М.
GPIO Inputs and Outputs - an intermediate guide for Arduino and ESP projects
44:00
Wait for the last one 🤣🤣 #shorts #minecraft
00:28
Cosmo Guy
Рет қаралды 10 МЛН