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.
@francoisdastardly44054 жыл бұрын
The man with the Swiss accent and super high quality videos !!
@MrRfaass4 жыл бұрын
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.
@mbaksa8 жыл бұрын
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
@AndreasSpiess8 жыл бұрын
You are right
@mbaksa7 жыл бұрын
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.
@GRBtutorials7 жыл бұрын
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/
@robert5742 жыл бұрын
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.
@rodrigomourapereira2664 жыл бұрын
Thank you so much! I'm using a soil moisture capacitive sensor. With your code, my calibration Has significantly improved.
@AndreasSpiess4 жыл бұрын
Glad it helped!
@Taran725 жыл бұрын
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!
@AndreasSpiess5 жыл бұрын
You are welcome!
@leandrohugosobrino77415 жыл бұрын
Nice explanation. The problem is that 1,1v internal reference is not so precise. It actually varies between 1.0 and 1.2v
@pjwlk4 жыл бұрын
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!!!
@AndreasSpiess4 жыл бұрын
You are welcome!
@ericgibbs3014 жыл бұрын
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
@AndreasSpiess4 жыл бұрын
The point of this video is to use the internal reference instead of VCC, I think.
@ericgibbs3014 жыл бұрын
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.
@thevideoboy878 жыл бұрын
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 !
@AndreasSpiess8 жыл бұрын
Thanks! I am not the inventor, I just liked the concept when I saw it.
@ArugaPH8 жыл бұрын
+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?
@thevideoboy878 жыл бұрын
+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.
@AndreasSpiess8 жыл бұрын
+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".
@bartdepauw11563 жыл бұрын
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
@AndreasSpiess3 жыл бұрын
1. It does not work on the ESP32 2. I made a video about the ADCs inside the ESP32 and the AD1115
@effgee1233 жыл бұрын
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
@AndreasSpiess3 жыл бұрын
There are different opinions about it. I do not care...
@s.sradon97822 ай бұрын
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.
@AndreasSpiess2 ай бұрын
Good idea!
@codebeat41922 жыл бұрын
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?
@AndreasSpiess2 жыл бұрын
I do not know. You have to read their datasheets and maybe adapt the code.
@Karl_Levine4 жыл бұрын
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?
@AndreasSpiess4 жыл бұрын
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
@robert5742 жыл бұрын
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.
@AndreasSpiess2 жыл бұрын
Exactly ;-)
@alphonsesynrem286 жыл бұрын
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.
@AndreasSpiess6 жыл бұрын
You are welcome. I hope it will do the job for you.
@stevebailey1682 Жыл бұрын
Do you have a similar trick for the PICO as it has a noisy ADC as well.
@AndreasSpiess Жыл бұрын
I do not use the Pico often :-(
@robert5742 жыл бұрын
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.
@AndreasSpiess2 жыл бұрын
Yes, it changes as shown in the video.
@robert5742 жыл бұрын
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.
@ejkitchen7 жыл бұрын
Great video! Also thanks for the code. Worked great!
@AndreasSpiess7 жыл бұрын
You're welcome!
@howardsway7829 жыл бұрын
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?
@AndreasSpiess9 жыл бұрын
+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.
@howardsway7829 жыл бұрын
+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.
@AndreasSpiess9 жыл бұрын
+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...
@rahulanshan13716 жыл бұрын
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?
@AndreasSpiess6 жыл бұрын
you get level shifters from 5 to 3.3 volts
@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Ай бұрын
Because there are only 1023 "distances" between values. But I am not sure which one is correct :-(
@ChronoGXayАй бұрын
@@AndreasSpiess Gotcha
@erikvanderleer77905 жыл бұрын
Does the ESP8266 have an internal reference voltage which would enable it to apply this method to the analog in readings too?
@AndreasSpiess5 жыл бұрын
I never heard of something like in the Arduino.
@winandd8649 Жыл бұрын
VERY helpful!! thank you!!
@AndreasSpiess Жыл бұрын
You are welcome!
@zedBel4ever5 жыл бұрын
Thanks for the post. Is there any such kind of trick for MKR family mine is 1010? I have tested the analogRead(ADC_BATTERY) .
@AndreasSpiess5 жыл бұрын
I do not know. Maybe not. They use much different chips
@zedBel4ever5 жыл бұрын
@@AndreasSpiess Thanks for the fast feedback. Yes the MKR 1010 is based on SAMD21 Cortex-M0+ 32bit chip.
@AndreasSpiess5 жыл бұрын
I know
@puriap2503 жыл бұрын
That was a great tip thank you.
@AndreasSpiess3 жыл бұрын
You are welcome!
@christophermalau52998 жыл бұрын
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...
@AndreasSpiess8 жыл бұрын
English is my third language, so I probably mixed the words. So, you are absolutely right and I hope, the video itself is clear.
@christophermalau52998 жыл бұрын
Wow, third language! I'm currently studying German, it's great
@AndreasSpiess8 жыл бұрын
But for sure not easy. Keep on!
@rockabanane4 жыл бұрын
Thx!! I was already wondering why my PV Energy meter was not correct! Grüße aus München :D
@AndreasSpiess4 жыл бұрын
You are welcome!
@newtechai43672 жыл бұрын
i am using an stm32 12bit adc what formular should i use please ?
@AndreasSpiess2 жыл бұрын
This is very Atmel328P specific. So it probably will not work on an STM chip
@newtechai43672 жыл бұрын
@@AndreasSpiess ok
@brandonly276 жыл бұрын
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?
@AndreasSpiess6 жыл бұрын
If it is 98-99% accurate it seems to be ok for me.
@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 Жыл бұрын
I do not understand. We use the built-in voltage reference for this project.
@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.
@Gallardo66693 жыл бұрын
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???
@AndreasSpiess3 жыл бұрын
In my world: 2^10=1024
@Gallardo66693 жыл бұрын
@@AndreasSpiess servus Andreas. Had a brain fart. In the mean time I figured it out.greetings from California. Machs gut
@alanvargheseninan12373 жыл бұрын
hi .. is there any way to reduce analogue value fluctuation while reading from analogue pin
@AndreasSpiess3 жыл бұрын
This is a complex topic and I cannot give you a short answer. The simplest thin is: Keep the wires short.
@alanvargheseninan12373 жыл бұрын
@@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 ??
@incxxxx11 ай бұрын
100u and 100n at the supply input.@@alanvargheseninan1237
@TautologyTechSystems Жыл бұрын
How about a tutorial on how to build that screen?
@AndreasSpiess Жыл бұрын
This is quite old technology. So no more relevant today...
@sandyblogs45684 жыл бұрын
what is the sampling rate of adc
@AndreasSpiess4 жыл бұрын
I do not know. Maybe you find it in the datasheet
@PhDFernandoCoach7 жыл бұрын
Thank you for this video, Andreas! Could you please explain me the formula Vcc = 1.1*1023*1000/measured result ? God bless you!
@AndreasSpiess7 жыл бұрын
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...
@alfrond4 жыл бұрын
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;)
@wizdumb4203 жыл бұрын
Thanks a lot, Swiss man. Here's a one-liner using your help: vIN = ((analogRead(voltageSensor_pin) * (readVcc() / 1000.0)) / 1024.0) / .2;
@AndreasSpiess3 жыл бұрын
What was the question?
@wizdumb4203 жыл бұрын
@@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 Жыл бұрын
Why not just switch to the internal reference?
@AndreasSpiess Жыл бұрын
This is what this sketch does.
@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.
@santoshshivgan62753 жыл бұрын
thank you very much Sir
@AndreasSpiess3 жыл бұрын
You are welcome!
@sallen1355 жыл бұрын
Hi! Does this work the same for the ESP32?
@AndreasSpiess5 жыл бұрын
No
@JavierCamacho5 жыл бұрын
I used you code and I'm still getting wrong readings. The fluctuation is from 0.5v up to 1.5v
@AndreasSpiess5 жыл бұрын
Then something is really screwed up. I would first try to get stable values without the code.
@JavierCamacho5 жыл бұрын
@@AndreasSpiess I'll keep searching then. Thanks for your time
@JavierCamacho5 жыл бұрын
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
@_tinkerBOY5 жыл бұрын
Will this work with atmega32u4?
@AndreasSpiess5 жыл бұрын
I do not know
@vivekvenkatsubramaniam4375 жыл бұрын
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?
@AndreasSpiess5 жыл бұрын
This is a video for an Arduino, not for an ESP8266.
@Developer981 Жыл бұрын
Can i use this for esp32
@AndreasSpiess Жыл бұрын
No.
@Arthurk3465 жыл бұрын
your accent remindes me Toto Wolff (principal of mercedes f1 team). he is austrian
@AndreasSpiess5 жыл бұрын
I was already compared with Arnold Schwarzenegger ;-) He is also Austrian and our native languages are similar, so our accents.
@MrScrewy8 жыл бұрын
Thanks a lot! very usefull
@AndreasSpiess8 жыл бұрын
You are welcome!
@AndreasSpiess8 жыл бұрын
You are welcome
@beaconofwierd18836 жыл бұрын
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? :)
@AndreasSpiess6 жыл бұрын
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.
@SashNone7 жыл бұрын
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?
@AndreasSpiess7 жыл бұрын
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 ;-)