Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Dulag Utok
#42309
martinayotte wrote:Yes ! as long as the input voltage is between 0V-1V.


there is this Serial.read command where we can use the arduino tx to send data to the esp8266 rx. are you familiar with its syntax? I'm a bit having trouble with my project. It's actually a school project. :)
User avatar
By martinayotte
#42312 What do you mean ?
Serial class provide Serial.available() to figure out if RX buffer has something to read, if it is the case, simply do Serial.read() to read the character one by one and place it into you own buffer for processing.
If the source of the RX is an Arduino board, beware that you need voltage divider to drop the 5V to 3V of the ESP.
User avatar
By Dulag Utok
#42313
martinayotte wrote:What do you mean ?
Serial class provide Serial.available() to figure out if RX buffer has something to read, if it is the case, simply do Serial.read() to read the character one by one and place it into you own buffer for processing.
If the source of the RX is an Arduino board, beware that you need voltage divider to drop the 5V to 3V of the ESP.


I send data from an uno board with this program. so every 5 seconds, the arduino board transmits sensor reading.

int sensorPin =0;
int sensorValue = 0;
int sensorValue2 = 0;
void setup(){
Serial.begin(115200);
pinMode(sensorPin,INPUT);
}

void loop() {

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
sensorValue2=map(sensorValue,0,720,0,100);
if(sensorValue2>100)
{
sensorValue2=100;
}
Serial.println(sensorValue2);
delay(5000);

}

To receive the signal, i tried using this code on an esp8266-1. this is just a basic webserver page to display the sensor reading but the values it displays does not coincide with the values sent by the uno board.

#include <ESP8266WiFi.h>

const char* ssid = "pistinani";
const char* password = "redled01";
int value;
WiFiServer server(80);

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

// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

// Start the server
server.begin();
Serial.println("Server started");

// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");

}

void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
if(Serial.available()>0){
value = Serial.read();

}
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connetion: close");
client.println("Refresh: 5");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");

client.print("Soil moisture: ");
client.print(value);

client.println("<br><br>");
client.println("Automatic drip irrigation<br><br>");
client.println("</html>");

delay(1);
client.stop();
Serial.println("Client disonnected");
Serial.println("");

}
User avatar
By martinayotte
#42316 Serial.read() is returning characters one by one of the string, not the actual integer value from sensor that you sent.
You need to acumulate all the characters until newline and then you can send it to Wifi client.
Code: Select all  char buf[64];
  int i = 0;
  if (Serial.available()) {
    int inByte = Serial.read();
    buf[i] = (char)inByte;
    if (inByte == '\r' or inByte == '\n' or i > (sizeof(buf) - 1)) {
      buf[i] = 0;
      i = 0;
      client.println(buf); // here we sent the whole line to the WiFi client
    }