We’re rewarding the question askers & reputations are being recalculated! Read more.
16

The ADC inside the Arduino does not measure voltage, but rather a voltage ratio. Namely the ratio from the voltage at the analog input to the voltage at the Vref pin. In the default configuration, the Vref pin is internally tied to the +5 V line. You can select to use instead an internal reference as Vref: analogReference(INTERNAL); This reference ...


13

To answer the question in the title: No, you cannot use analogRead() to read a digital pin. A digital pin cannot behave as analog because it isn't connected to the ADC (Analog to Digital Converter). If you call something equating to analogRead(15) on an Uno, then it should read pin A1. You can see the pin assignments in the board-specific versions of ...


11

Yes, the analog pins must be addressed using A0, A1,... when using them for digital I/O. Depending on the board you are using A0,A1,etc. are mapped to different values (for instance it looks like A0 is 18 on some boards but 14 on others. One solution for looping over the analog pins would be this: static const uint8_t analog_pins[] = {A0,A1,A2,A3,A4}; // ...


11

This is to be expected. The other pins have nothing connected to it, so their voltage is floating. The Arduino MCU only has a single ADC. To read the different analog pins, it uses a multiplexer to connect the pin you want to read to the single ADC. The ADC inside the MCU have a "sample and hold" capacitor inside it. To read the voltage at the pin, it ...


9

A USB-powered Arduino Nano will have an ADC voltage reference which can't be relied on, due to the +/- 5% tolerance of the incoming USB voltage. On top of that, the Nano has an MBR0520 Schottky diode (D1) that will drop between 0.1 and 0.5 V depending on its own manufacturing tolerances, its temperature, and the current draw of your board. What can you ...


8

The Analog pins are essentially identical in functionality to digital pins when used as digital I/O. If desired you could "be clever" and use an analog input in analog mode to read multiple keys using one pin. eg using 10k, 22k, 39k, 82k, 150k in series with 5 buttons from V+ to pin and a say 4k7 to ground would result in 5 voltages which were easily ...


7

AVR-based Arduinos only have 10-bit ADCs, but the ATSAM3X in the Due has 12-bit ADCs. Additionally, it is possible to interface to higher-resolution external ADCs via I2C or SPI.


7

Yes, you can do this with "a little programming" or more easily by adding two cheap components. If you connect a say 47k resistor from PWM_Out to Analog_In and a say 100 uF capacitor from Anaolg_In to ground you will be able to read the equivalent analog value to an accuracy of around 1%. Read it N times (maybe 10 times) with a delay of say 12 ms between ...


7

If you know Ohm's Law (which you should) and you realise that the ADC measures voltage, you should be able to work it out from there. But I will go into minute detail for you to ensure you understand. Ohm's Law defines the relationship between Voltage (V), Current (I) and Resistance (R). R = V/I To find one unknown value (in your case R) you need to know ...


7

Firstly, if I understand your schematic right, you're not "dividing" anything there. If the ringed red symbol is where you are connecting the ADC then either you will see near 4V on there (if it's only connected to the ADC), or 0V (if it's connected to ground). You should be connecting the ADC between the resistors to get a reading. Secondly, you should be ...


6

Adding hysteresis behavior to your code is not difficult. You just need to store the state you're in and make the thresholds for transitioning into another state dependent on that. You can use an enum to store the state: enum BatteryStates { Red, Orange, Green }; Then, instead of defining and checking against one threshold value, define two thresholds ...


6

int A0, A1,A2,A3,A4; delay(200); A0= analogRead(A0); A1= analogRead(A1); A2= analogRead(A2); A3= analogRead(A3); A4= analogRead(A4); Your local variables (A0 through A4) are shadowing the global variables for the pins (A0 through A4). Give your local variables different names.


6

You can measure a single "pure" frequency by counting the number of times that the pin changes, by using the inbuilt timers. Here is a sketch from my page about timers that accomplishes that: // Timer and Counter example // Author: Nick Gammon // Date: 17th January 2012 // Input: Pin D5 // these are checked for in the main program volatile unsigned long ...


6

The AD converter in the ATMega microcontroller (as used in Arduino) converts an input voltage to a number. This ADC happens to be 10 bit that means 2^10 states which is 1024. The number 0 (zero) means 0 Volt input voltage. The number 1023 means the maximum input voltage. Since 0 is also a value the scale runs from 0 to 1023 making 1024 values. The scale ...


5

How much accuracy do you really need? If it's just 1 or 2 extra bits of resolution you are after, you might be able to achieve that with a bit of oversampling. Basically, you take a ton of readings and average them. It only works if there is at least a few mV of random noise in your signal or in your ADC, and if your input signal bandwidth is low enough to ...


5

There is no more accurate way of getting time on the arduino, but I would suggest you use millis() instead. micros() returns microseconds, or millionths of a second, since the arduino was turned on. The issue is that the 32 bit unsigned integer used to store time on the arduino can only count about 70 minutes worth of micros before overflowing and resetting ...


5

Your question contains a number of errors and misconceptions. Firstly the maximum output of a successive approximation ADC (here 0x3ff) corresponds to Vref - 1 LSB The voltage will thus be sensorValue*5000.0/1024. Note this error is less than the error of ±2LSB. Measuring your 5V is futile, as this is the default analog reference, so the result must be ...


5

It is possible, but not the best idea. The analog inputs require a reasonably stable input - this can be achieved with a RC filter to smooth the PWM output. This would work for reasonably slow data rates. You would be better to use one of the many communication protocols supported by Arduino (serial, SPI, I²C).


5

Since you used Arduino tag..., you don't need an opamp. Instead you can select ADC reference voltage on your arduino to 1.1V. This way you don't need any additional parts and you get the whole precision range. analogReference(INTERNAL1V1); http://www.arduino.cc/en/Reference/AnalogReference


5

Wouldn't this be simpler? Note: amended answer increases R1 to 10 k. The 10 k resistor limits current to 0.17 mA. The 3.3 V zener diode clamps the input voltage to 3.3 V (I measured 2.3 V on mine so that is well within spec). The other end of the zener diode goes to the Arduino ground pin. I originally had R1 as 1 k however if you had a high voltage input ...


5

I use a similar system on a product I recently worked on to monitor the battery voltage - and of course I didn't want it on all the time to drain the battery. The trick, though, is to do the exact opposite of what you are doing. Instead of isolating the ground (which leaves the battery then directly connected to the Arduino) you need to completely isolate ...


5

A divider is used to (as the name suggests) reduce a higher voltage to a lower voltage. Using a divider on a small voltage will only make it smaller and harder to measure. To get the most out of your measuring you need to have the reference voltage as close to the highest voltage you want to measure as possible. The highest voltage that can be applied is ...


5

If I understand the description correctly, neither side of the resistor is at ground potential. There's a wide gamut of methods of dealing with this, for example using a differential ADC unit, or using an instrumentation amplifier ahead of a single-ended ADC. But perhaps the simplest method is to use two ADC channels, one attached to each end of the ...


5

One possibility that has not been mentioned yet: the issue may be the calibration of your ADC converter. Your code carries the implicit assumption that the voltage you measure is V = Vref × RawADC ÷ 1023 The correct formula is V = Vref × (RawADC + offset) ÷ scale where offset is ideally 0 and scale is ideally 1024 (and not 1023, as you are assuming). ...


5

First, let's consider the logic of your program. You have two groups of pins: 6 pins connected to the wires and 6 pins connected to the terminals. The first thing I would do is forget that these are two different groups. Consider you just have 12 pins that the user has to connect in a specific fashion. This way most “weird things” the user ...


5

The simplest fix to your problem is to change the map() call to byte alrmSet = map(alrmSwState, 0, 1024, 0, 3); In the call above, the mapped intervals are of the semi-open type, e.g. [a, b), where the start values (namely 0) are understood as being inclusive and the end values (1024 and 3) are exclusive. Although not clear from the documentation, ...


5

As CrossRoads says, there really isn't any such thing as analog output on an Arduino. (Any Arduino unless it has a built-in DAC.) It uses pulse-width modulation to vary the "duty cycle" of the output from 100% on to 0% on, which simulates an analog voltage. If you drive an LED with PWM (and the required current limiting resistor) your eyes will not see the ...


4

... won't the ADC reference voltage constantly be dropping with the battery? Yes, which is why you either use or measure an internal bandgap reference instead. Use the analogReference() function to select a reference appropriate for the board in use. Note that you will need to use a voltage divider to reduce the battery voltage to a value below that of the ...


4

At least an Uno/Megas/leonardos, all the values mapped to analog pin numbers are consecutive, so for (int i = A0; i < A4; i++) { pinMode(i, OUTPUT); digitalWrite(i, LOW); } will set A0, A1, A2, and A3 to OUTPUT, and then LOW.


4

The datasheet says: The first ADC conversion result after switching reference voltage source may be inaccurate, and the user is advised to discard this result. Then you could try to take each reading twice, looping over four ADC readings: Read bandgap with Vcc as reference, discard the value. Re-take the same, keep the value. Read A1 with 1.1V ...


Only top voted, non community-wiki answers of a minimum length are eligible