-->
Page 1 of 2

ESP8266-01 couldn't detect sensor value(AnalogRead)

PostPosted: Mon Nov 21, 2016 1:50 pm
by Sammy888
I am trying to program my ESP8266-01 to detect a turbidity sensor through an Arduino UNO. The code works fine on the Arduino UNO but once I uploaded it on to the ESP8266 Module, what showed on the serial monitor of Arduino IDE are just zeroes. I'm just a few days into this project, can someone help? Can the ESP8266 actually detect analog values? Is there any specifications I need to select for the board? Or is there any connections I need to make? Or is it impossible?
The following are my code:

#include <SPI.h>

int sensor1 = A0 ;//the port of the sensor's connected to on Arduino UNO

void setup() {
Serial.begin(115200);
delay(10);
}

void loop() {
int voltage = 0;
int sensorValue = analogRead(sensor2);
float voltage = sensorValue * (5.0 / 1024.0);
Serial.println(voltage);
Serial.print(" Turbidity:");
Serial.println(voltage);
delay(3000);
}

My connections:
RX>>RX//what's working for me
TX>>TX
VCC,CH_PD>>3.3v
GPIO0>>Ground
GND>>Ground
RST,GPIO2>>not connected
Sensor's connected to A0, 5v and GND of Arduino UNO.

Re: ESP8266-01 couldn't detect sensor value(AnalogRead)

PostPosted: Tue Nov 22, 2016 6:11 am
by FreddyVictor
Please double-check your connections of your sensor to/from the board and that the output is going to A0
Your program does not actually compile for a couple of reasons, but if fixed should work

Note that the Aref voltage (Analog Reference voltage) is different between Arduino & ESP8266 so your calculation of the voltage should be:
sensorValue * (3.3 / 1024.0);

Re: ESP8266-01 couldn't detect sensor value(AnalogRead)

PostPosted: Tue Nov 22, 2016 8:20 am
by Barnabybear
Hi, the ADC on an ESP is only Zero to one volt - it looks like the code and your sensor are looking for Zero to five volts. You may need a 5:1 voltage divider and to mod the code removing the "5.0/"
Code: Select allfloat voltage = sensorValue * (5.0 / 1024.0);

Re: ESP8266-01 couldn't detect sensor value(AnalogRead)

PostPosted: Wed Nov 30, 2016 10:53 pm
by Sammy888
Barnabybear wrote:Hi, the ADC on an ESP is only Zero to one volt - it looks like the code and your sensor are looking for Zero to five volts. You may need a 5:1 voltage divider and to mod the code removing the "5.0/"
Code: Select allfloat voltage = sensorValue * (5.0 / 1024.0);


Hi, thank you for the reply, but our sensors need to work under the voltage of 5, no? I tried changing the voltage supply to the sensor to 3.3V from the Arduino and changed the code to 3.3/1024. The values now just fluctuate around 2.00 even though the sensor's not triggered. Is there other codes needed. Like does it has anything to do with the I2C concept (I dont really know what is it yet) or something about slave/master of the arduino board and ESP8266 board? Do advice, thanks.