15 votes
Accepted

Can I use analogRead to read a digital pin?

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). ...
user avatar
15 votes
Accepted

Does ADC conversion to a voltage rely on the actual value of the +5 V pin?

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, ...
user avatar
  • 36.2k
11 votes
Accepted

How to loop over analog pins?

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 ...
user avatar
  • 2,090
11 votes
Accepted

Why analogue pins affect each other?

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 ...
user avatar
  • 11.1k
11 votes

What is the most efficient voltage divider for Arduino?

The most efficient is not to have a voltage divider at all. Or at least to only have a voltage divider when you actually need one. My preferred schematic is this: simulate this circuit – ...
user avatar
  • 102k
9 votes

Does ADC conversion to a voltage rely on the actual value of the +5 V pin?

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 (...
user avatar
  • 2,092
8 votes
Accepted

Is it wise to use analog input pins to read digital buttons?

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 ...
user avatar
8 votes

A question about resistance measurement with arduino

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. ...
user avatar
  • 102k
8 votes

what is arduino adc reference?

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) ...
user avatar
7 votes

How to add hysteresis to threshold values?

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 ...
user avatar
7 votes
Accepted

Can I connect a PWM pin on one Arduino to an analog input on another?

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 ...
user avatar
7 votes
Accepted

Precision voltmeter using Arduino

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 ...
user avatar
  • 102k
7 votes
Accepted

How can I create a battery level circuit

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 ...
user avatar
  • 102k
6 votes

Analog pins all reading same value

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 ...
user avatar
6 votes
Accepted

Arduino: Read frequency of input from audio jack

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: // ...
user avatar
  • 35.2k
6 votes

Uno - measure the voltage, NOT connecting GND

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 ...
user avatar
6 votes

How to measure the supply voltage of Arduino without using an analog pin

Yes, you can do it. You can measure the voltage of the internal (approximately) 1.1V reference voltage using the ADC and use the results of that to calculate what the reference voltage you used (VCC) ...
user avatar
  • 102k
6 votes
Accepted

Is it possible to measure analog output?

First: Why would you need to measure the PWM value. You already know it; it's saved in the val variable. Why not just use this variable for later use in code? Second: Doing the analogRead on the same ...
user avatar
  • 13.8k
6 votes

Can I test if something is connected to analog pin?

The input stage of the analog-to-digital converter is a sample-and-hold capacitor. When you take an analog reading, the capacitor is connected to the input pin, it is charged to the voltage you want ...
user avatar
  • 36.2k
6 votes
Accepted

Analog read not working while using WiFi

The ESP32 has two ADCs. One of them, ADC2, is actively used by the WiFi. From the IDF documentation: Since the ADC2 module is also used by the Wi-Fi, only one of them could get the preemption when ...
user avatar
  • 102k
5 votes

What's the most accurate way to time-stamp analogRead data?

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. ...
user avatar
  • 4,309
5 votes

Arduino unstable analog reading when using power supply

I solved a similar issue by adding a pin from supply to AREF and it's now stable. This fixed a frustrating pH meter issue on my Mega that every time I plugged USB in it would be right, but as soon as ...
user avatar
  • 51
5 votes

UNO analog input voltage reading not accurate

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 ...
user avatar
  • 1,635
5 votes

Can I connect a PWM pin on one Arduino to an analog input on another?

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 ...
user avatar
  • 1,635
5 votes

0-1 V input to 0-5 V Output

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 ...
user avatar
  • 280
5 votes

Reading a photoresistor

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 ...
user avatar
  • 35.2k
5 votes

Safely enabling voltage divider on a 12V battery

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 ...
user avatar
  • 102k
5 votes

Arduino: Read frequency of input from audio jack

If your signal is a pure 1 kHz tone, then you should use Nick Gammon's counting method, as it is the most straight-forward solution. If, however, you are picking the signal through a microphone, ...
user avatar
  • 36.2k
5 votes

AnalogRead value constant for a varying voltage (for LED brightness variation)

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 ...
user avatar
  • 5,509
5 votes
Accepted

ADC register always returning high

First, let me give a couple of suggestions on the programming style. There is no point in defining your own variables for accessing the hardware registers: the avr-libc does that for you, you just ...
user avatar
  • 36.2k

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