- Thu Jul 05, 2018 5:01 pm
#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
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