Pass Value from arduino analog read to esp

Good morning,

Does anyone know how to transfer an analog reading from arduino to the esp8266?

The best approach is to use the serial communication between the arduino and the ESP8266, so the arduino writes analog reads to the serial interface, and ESP8266 reads them. Hope it helps.

Yew i had that in mind but lets say that i print to the serial,how i can read the values to the esp and how does thinger handles those values?

The ESP8266 can open the serial and read from them, check if there is data available, and so on. Check the Arduino documentation https://www.arduino.cc/en/Serial/Read

So in the ESP8266 loop you should be reading the serial values (may be splitted by a line end to make it easier to parse), and probably updating a global variable in your sketch. Then in the setup method you can add an output value for the variable you are filling with serial reads in the loop. Something like the following approach:

// declaration of the variable that will hold analog reads from serial
unsigned int analogRead = 0;

// declare the output resource for your vairable
void setup{
    thing["analog"] >> outputValue(analogRead);
}

void loop(){
    thing.handle();
    // update analogRead from Serial reads...
}

Notice hoever that the ESP8266 and Arduino (at least 5v boards) have different logic levels, so the serial interface could not work correctly unless you introduce some level shifter.

1 Like

I still don’t fully get it…Let’s say that i print to the serial of arduino the value that i get from analog pin 2 and let’s assume that it is a float. How does the esp receives that analog reading?