Monday, April 4, 2016

NodeMCU to read analog input, A0.


Last post introduced "Serial Plotter in Arduino IDE" with Arduino Uno example to read analog input and println to Serial Port, to display on Arduino Software's Serial Plotter. The example can direct re-compile and run target NodeMCU/ESP8266.



remark: Fritzing part of NodeMCU can be found HERE.

Example code, same as in last post.
const int AnalogIn  = A0;

int readingIn = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  readingIn = analogRead(AnalogIn);
  Serial.println(readingIn);
}


5 comments:

  1. How can I transmit analog reading from pin A0 of Nodemcu to a webpage? Thank you in advance!

    ReplyDelete
    Replies
    1. after connecting to a client
      we can print it using client.println(readingIn)

      Delete
  2. That depends on what page you want to write to. For my project, i'm sendind data from an ESP8266 to a web page hosted on my Raspberry Pi using MQTT protocol. I don't know if this will suit your needs, but you can search a little bit about MQTT an how it works :)

    ReplyDelete
  3. How can I get more than one analog data ..as it has only one analog pin ??

    ReplyDelete
    Replies
    1. It should be only one analog input pin on ESP8266.
      Reference: http://esp8266.github.io/Arduino/versions/2.0.0/doc/reference.html
      ESP8266 has a single ADC channel available to users...To read external voltage applied to ADC pin, use analogRead(A0). Input voltage range is 0 — 1.0V.

      Or. you have to connect external ADC if you need more.

      Delete