if you want to remove an article from website contact us from top.

    in arduino uno, for the maximum input of 5.0v applied to an adc channel will give the following output

    Mohammed

    Guys, does anyone know the answer?

    get in arduino uno, for the maximum input of 5.0v applied to an adc channel will give the following output from screen.

    Gammon Forum : Electronics : Microprocessors : ADC conversion on the Arduino (analogRead)

    Gammon Forum : Electronics : Microprocessors : ADC conversion on the Arduino (analogRead)

    Log on

    Register forum user name Search FAQ

    Gammon Forum

    See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

    Entire forum Electronics Microprocessors ADC conversion on the Arduino (analogRead)ADC conversion on the Arduino (analogRead)Postings by administrators only.

    Refresh page

    Posted by Nick Gammon   Australia  (22,812 posts)   bioDate Fri 27 Feb 2015 08:24 AM (UTC)

    Amended on Fri 05 Feb 2016 04:24 AM (UTC) by Nick Gammon

    Message

    This page can be quickly reached from the link: http://www.gammon.com.au/adc

    Introduction

    The Arduino has an ADC (Analog to Digital Converter) which is connected to various input pins on the board. In the case of the Uno they are labelled A0 to A5.

    The basic usage is very simple:

    int value = analogRead (A0); // read A0

    The results are a number in the range 0 to 1023.

    Using default settings, a return value of 0 would represent approximately 0V, and a return value of 1023 (the maximum) would represent approximately 5V. However more about the exact conversion details later.

    This thread explores various things you can do with the ADC, including:

    Speeding it up

    Using different reference voltages

    Making it non-blocking

    Using an interrupt

    Reading other things such as the internal chip temperature

    Measuring resistances

    Measuring voltages higher than 5V

    Interpreting the results accurately

    Timing

    The ADC takes 13 ADC clock cycles to perform a conversion, except the first one after the ADC is enabled, at which time it takes 25 ADC cycles, while the circuitry is initialized.

    You can choose various prescalers, from 2 to 128. This divides down the processor clock speed to give an ADC clock speed. You can do that by changing the ADCSRA register, like this:

    ADCSRA &= ~(bit (ADPS0) | bit (ADPS1) | bit (ADPS2)); // clear prescaler bits

    ADCSRA |= bit (ADPS0); // 2

    ADCSRA |= bit (ADPS1); // 4

    ADCSRA |= bit (ADPS0) | bit (ADPS1); // 8

    ADCSRA |= bit (ADPS2); // 16

    ADCSRA |= bit (ADPS0) | bit (ADPS2); // 32

    ADCSRA |= bit (ADPS1) | bit (ADPS2); // 64

    ADCSRA |= bit (ADPS0) | bit (ADPS1) | bit (ADPS2); // 128

    The conversion time will be 13 times the clock period (or 25 for the first conversion) thus each one would be (assuming a 16 MHz clock):

    Prescaler

    2 * 13 * 1/16E6 = 0.000001625 ( 1.625 µs)

    4 * 13 * 1/16E6 = 0.00000325 ( 3.25 µs)

    8 * 13 * 1/16E6 = 0.0000065 ( 6.5 µs)

    16 * 13 * 1/16E6 = 0.000013 ( 13 µs)

    32 * 13 * 1/16E6 = 0.000026 ( 26 µs)

    64 * 13 * 1/16E6 = 0.000052 ( 52 µs)

    128 * 13 * 1/16E6 = 0.000104 (104 µs)

    Taking the inverse of the period we can work out the maximum theoretical conversion rate per second:

    Prescaler Conversions/sec

    2 615,385 4 307,692 8 153,846

    16 76,923

    32 38,462

    64 19,231

    128 9,615

    Of course, it won't ever get that good because there would be code needed to start the conversion, get the result, etc., but this is a ballpark figure.

    Tip:

    There is an extra time before a conversion starts. The conversion starts on the leading edge of the ADC clock, not the moment the code asks for it. In the case of a scaler of 128, there could be 127 extra (processor) clock cycles added, because the hardware has to wait for the next ADC clock cycle. This could add 7.938 µs to the conversion time.

    Using a lower prescaler will not only make the conversion faster, but will also reduce this wait time.

    A more accurate average conversion time would be 13.5 times the ADC clock time, as that 0.5 clock cycles allows for you having to wait, on average, half a clock cycle.

    The datasheet mentions optimal ADC clock frequencies so let's see what the ADC clock will be for each prescaler:

    Prescaler ADC Clock Frequency (kHz) 2 8000 4 4000 8 2000 16 1000 32 500 64 250 128 125

    From the datasheet, section 23.4:

    Quote:

    By default, the successive approximation circuitry requires an input clock frequency between 50 kHz and 200 kHz to get maximum resolution. If a lower resolution than 10 bits is needed, the input clock frequency to the ADC can be higher than 200 kHz to get a higher sample rate.

    Thus the choice by the analogRead library of a prescaler of 128 is the only one that gives the maximum resolution. The next prescaler (64) would give a frequency (250 kHz) slightly higher than the recommended one, however that could well be acceptable for many applications.

    Note that the datasheet (Table 28-7. ADC Characteristics) mentions that the ADC clock frequency range is 50 kHz to 1000 kHz. Thus (at this CPU clock speed of 16 MHz) the smallest prescaler you are allowed to use is 16, which is born out by testing below.

    Accuracy with various prescalers

    The test below gets an average of 1000 readings of 4 voltages on A0 to A3, namely:

    स्रोत : www.gammon.com.au

    Analog to Digital Conversion

    HOME TUTORIALS ANALOG TO DIGITAL CONVERSION

    Analog to Digital Conversion

    ≡ Pages CONTRIBUTORS: NATE FAVORITE 57 SHARE Share on Twitter Share on Facebook Pin It

    The Analog World

    Microcontrollers are capable of detecting binary signals: is the button pressed or not? These are digital signals. When a microcontroller is powered from five volts, it understands zero volts (0V) as a binary 0 and a five volts (5V) as a binary 1. The world however is not so simple and likes to use shades of gray. What if the signal is 2.72V? Is that a zero or a one? We often need to measure signals that vary; these are called analog signals. A 5V analog sensor may output 0.01V or 4.99V or anything inbetween. Luckily, nearly all microcontrollers have a device built into them that allows us to convert these voltages into values that we can use in a program to make a decision.

    Here are some topics and concepts you may want to know before reading this tutorial:

    Voltage, Current, Resistance

    Binary Analog vs Digital

    Arduino analogRead()

    Voltage Dividers Digital Multimeter

    Powering Your Project

    What is the ADC?

    An Analog to Digital Converter (ADC) is a very useful feature that converts an analog voltage on a pin to a digital number. By converting from the analog world to the digital world, we can begin to use electronics to interface to the analog world around us.

    Not every pin on a microcontroller has the ability to do analog to digital conversions. On the Arduino board, these pins have an ‘A’ in front of their label (A0 through A5) to indicate these pins can read analog voltages.

    ADCs can vary greatly between microcontroller. The ADC on the Arduino is a 10-bit ADC meaning it has the ability to detect 1,024 (2^10) discrete analog levels. Some microcontrollers have 8-bit ADCs (2^8 = 256 discrete levels) and some have 16-bit ADCs (2^16 = 65,536 discrete levels).

    The way an ADC works is fairly complex. There are a few different ways to achieve this feat (see Wikipedia for a list), but one of the most common technique uses the analog voltage to charge up an internal capacitor and then measure the time it takes to discharge across an internal resistor. The microcontroller monitors the number of clock cycles that pass before the capacitor is discharged. This number of cycles is the number that is returned once the ADC is complete.

    Relating ADC Value to Voltage

    The ADC reports a ratiometric value. This means that the ADC assumes 5V is 1023 and anything less than 5V will be a ratio between 5V and 1023.

    Analog to digital conversions are dependant on the system voltage. Because we predominantly use the 10-bit ADC of the Arduino on a 5V system, we can simplify this equation slightly:

    If your system is 3.3V, you simply change 5V out with 3.3V in the equation. If your system is 3.3V and your ADC is reporting 512, what is the voltage measured? It is approximately 1.65V.

    If the analog voltage is 2.12V what will the ADC report as a value?

    Rearrange things a bit and we get:

    Ahah! The ADC should report 434.

    Arduino ADC Example

    To show this in the real world let’s use the Arduino to detect an analog voltage. Use a trimpot, or light sensor, or simple voltage divider to create a voltage. Let’s setup a simple trimpot circuit for this example:

    To start, we need to define the pin as an input. To match the circuit diagram we will use A3:

    pinMode(A3, INPUT);

    and then do the analog to digital version by using the analogRead() command:

    int x = analogRead(A3); //Reads the analog value on pin A3 into x

    The value that is returned and stored in x will be a value from 0 to 1023. The Arduino has a 10-bit ADC (2^10 = 1024). We store this value into an int because x is bigger (10 bits) than what a byte can hold (8 bits).

    Let’s print this value to watch it as it changes:

    Serial.print(“Analog value: “);

    Serial.println(x);

    As we change the analog value, x should also change. For example, if x is reported to be 334, and we’re using the Arduino at 5V, what is the actual voltage? Pull out your digital multimeter and check the actual voltage. It should be approximately 1.63V. Congratulations! You have just created your own digital multimeter with an Arduino!

    Hooking Things Up Backward

    What happens if you connect an analog sensor to a regular (digital) pin? Nothing bad will happen. You just won’t be able to do an analogRead successfully:

    int x = analogRead(8); //Try to read the analog value on digital pin 8 - this doesn’t work!

    This will compile but x will be filled with a nonsensical value.

    What happens if I connect a digital sensor to an analog pin? Again, you will not break anything. If you do an analog-to-digital conversion on a button, you will most likely see ADC values very close to 1023 (or 5V which is binary 1) or very close to 0 (or 0V which is binary 0).

    Interested in learning more foundational topics?

    See our Engineering Essentials page for a full list of cornerstone topics surrounding electrical engineering.

    स्रोत : learn.sparkfun.com

    What happens if you try to analogRead a voltage slightly higher than 5 volts?

    I'm aware that this can and will damage the Arduino, but I'm more concerned about what the actual analog input value would be and why. Would this overvoltage result in no input at all? Or could you theoretically get an …

    What happens if you try to analogRead a voltage slightly higher than 5 volts?

    Using ArduinoSensors

    SniffLimit Apr '19post #1

    I'm aware that this can and will damage the Arduino, but I'm more concerned about what the actual analog input value would be and why.

    Would this overvoltage result in no input at all? Or could you theoretically get an artificially low input value, like 100 out of 1023?

    Thanks for your time.

    created

    Apr '19

    last reply

    May '21 8

    replies

    5.3k

    views

    6

    users

    2

    links

    2 2 IdahowalkerShannon Apr '19post #2

    Why not just use a voltage divider to bring the over 5 volt level down to 5V range?

    Imagine if you will a site like this http://www.ohmslawcalculator.com/voltage-divider-calculator 54 where you can start off with 12V for a source voltage and 100K for R1, which will then give R2.

    Then you can use some simple code, like this:

    void TaskAnalogVoltRead_LIDAR( void *pvParameters )

    { String localBuffer; int iBit = 1;

    float ADbits = 4095;

    float offSET = 0.0f;

    float r1 = 100800.0f; // R1 in ohm, 100k = 100,800.0 //

    float r2 = 38780.0f; // R2 in ohm, 38k = 38000.0 //actual 38780K

    float uPvolts = 3.3f;

    // ADC1 channel 0 is GPIO36

    // ADC1 channel 1 is GPIO37

    // ADC1 channel 6 is GPIO34

    // https://dl.espressif.com/doc/esp-idf/latest/api-reference/peripherals/adc.html

    // to get resistor R2 go to:

    // http://www.ohmslawcalculator.com/voltage-divider-calculator

    //  used 12 volts for the input voltage to calculate R2, used 100K for R1

    for (;;) {

    xEventGroupWaitBits( eg, evtAnalogVoltReadTask_LIDAR, pdTRUE, pdTRUE, portMAX_DELAY );

    // read the input iBit = iBit << 1;

    //    Serial.println ( iBit );

    if ( iBit == 1073741824 )

    {

    if ( xSemaphoreTake( sema_AnalogVoltRead_LIDAR, xSemaphoreTicksToWait ) == pdTRUE )

    {

    Vbatt_LIDAR += ( ((( uPvolts * adc1_get_raw(ADC1_CHANNEL_6)) / ADbits) / r2 * ( r1 + r2)) + offSET );

    Vbatt_LIDAR = Vbatt_LIDAR /2; // average readings

    xSemaphoreTake( sema_Time, xSemaphoreTicksToWait );

    fMakeTimeStamp ( localBuffer );

    xSemaphoreGive( sema_Time ); // give up semaphore

    } // if ( xSemaphoreTake( sema_AnalogVoltRead_LIDAR, xSemaphoreTicksToWait ) == pdTRUE )

    iBit = 1;

    } // if ( iBit == 1073741824 )

    }

    vTaskDelete( NULL );

    }

    to take a reading and get the voltage read and not put the uController at risk of making smoke!

    The part your most interested in is: Vbatt_LIDAR += ( ((( uPvolts * adc1_get_raw(ADC1_CHANNEL_6)) / ADbits) / r2 * ( r1 + r2)) + offSET ); I like this part too Vbatt_LIDAR = Vbatt_LIDAR /2; // average readings to get an average reading over time, I find the value to be close to spot on.

    You analog reading will be the voltage you put onto the input pin. The converted digital reading could be smoke or high heat or max but eventually smoke and or high heat.

    MorganS Apr '19post #3

    If you exceed 5V but not more than 5.5V then you will get 1023 from analogRead().

    It doesn't wrap around or anything silly.

    MarkT Apr '19post #4

    Its a successive approximation ADC, so if you know how those work its obviously they

    are saturating, not wraparound. Most ADCs are saturating anyway, its really nasty if

    they aren’t.

    When the internal 1.1V reference is used the output is 1023 whenever the input is above the 1.1V

    reference voltage, no damage is possible until the input rises above Vcc even with the 1.1V reference.

    wvmarle Apr '19post #5

    Mind: the limit before damaging the ADC is not 5.5V. It is Vcc + 0.5V, which would be 5.5V if Vcc = 5.0V.

    For a 3.3V Arduino powered at 3.3V the limit is 3.8V (and readings over 3.3V will be 1023).

    For a 5V Arduino powered off a 4.6V USB supply (nominally 5V and it will operate just fine at that voltage) the limit would be 5.1V.

    Dana1954 Apr '19post #6

    Take care when using the analog inputs. I made the mistake of using it to monitor the robots battery voltage directly to the analog input (no resistor) which worked fine until I unplugged the USB. Then it back powered the Arduino board through the chip burning it and other board components out.

    Use voltage dividers and insure to limit the current so not to burn it out.

    wvmarle Apr '19post #7

    What burned was the clamping diode, they're rated at 1 mA, and you are allowed to rely on them to keep your pins safe (iirc Atmel even gives a suggestion of reading a 12V signal that way). What you do need is a current limiting resistor - keep your current below 0.5 mA and you're safe.

    Your mistake was to not add a protection resistor. A 5V battery connected to a pin at Vcc=0V means you have a 5V difference, so a 10k resistor brings it down to 0.5 mA. That same resistor, being not part of a voltage divider or so, does not affect the voltage as seen by the analog pin.

    Be aware that you also shouldn't go much above 10k as then the pin may not be able to follow the voltage well (not an issue for battery monitoring normally).

    Another way to monitor your battery voltage is to use the "secret voltmeter 38" trick, this works great if the battery is actually powering the Arduino directly, as you'd do with e.g. a 3.7V LiPo or 2-3 1.5V AA batteries.

    स्रोत : forum.arduino.cc

    Do you want to see answer or more ?
    Mohammed 15 day ago
    4

    Guys, does anyone know the answer?

    Click For Answer