SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
#199648
Hi,
I am having difficulty with analogRead(A0) result. While powered via USB, I am supplying VIN to a voltage divider which reads a little more than .5V but always returns 1024 when input to ADC pin. If nothing connected to ADC pin the result floats. I have included the sketch below. Any tips for me? Thanks for your help!



results: ****************************************

adcRaw: 1024
LED on V1: off
LED on V1: on
adcRaw: 1024
LED on V1: off
LED on V1: on
adcRaw: 1024
LED on V1: off
LED on V1: on
adcRaw: 1024
LED on V1: off
LED on V1: on
adcRaw: 1024
LED on V1: off
LED on V1: on
adcRaw: 1024
LED on V1: off
LED on V1: on
adcRaw: 160
LED on V1: off
LED on V1: on
adcRaw: 164
LED on V1: off
LED on V1: on
adcRaw: 169
LED on V1: off
LED on V1: on



Sketch: *************************************


#define ESP8266_LED 5

const unsigned long baudRate = 115200; // test new thing dev board

int adcRaw;

void setup()
{
pinMode(ESP8266_LED, OUTPUT);

//Initialize serial port
Serial.begin(baudRate);

while (!Serial) {
; // wait for serial port to connect. Needed for native USB
}

Serial.println(" ");
Serial.println("Baud Rate: " + String(baudRate));
Serial.println("");
Serial.println("Simple LED sketch");
Serial.println(" ");

pinMode(A0, INPUT); // analog read adc

} // END setup


void loop()
{
digitalWrite(ESP8266_LED, HIGH); // LED off
Serial.println("LED on V1: off");

delay(500);
digitalWrite(ESP8266_LED, LOW); // LED on
Serial.println("LED on V1: on");

delay(500);

adcRaw = analogRead(A0);

Serial.println(" adcRaw: " + String(adcRaw));

} // END loop
#199656
Thanks for responding. After your comment I went back to the basics. Yes, you were right. My external voltmeter was on the wrong leads of the voltage divider. Essentially, my voltage divider was backwards (was 1K/10K instead of intended 10K/1K for .4V for test) so voltage was above 1V. The analogRead(A0) is in the proper range now after corrections. I thank you for helping me learn something better!