[ Blynk and Arduino + ESP8266 ] + Read analog Sensor

  • Arduino UNO + ESP8266
  • Using android
  • Blynk Server
  • Analog Sensor

Hello. i need help with my problems using Arduino + ESP8266.
first thing is i have 2 arduino, Arduino A i used for my project with esp and blynk, and Arduino B used for trials the sensor analog ( let’s say it’s pH sensor )
when Arduino B connect to my sensor in analog pin, the result was good enough (i see the results on serial monitor) and it match with the datasheet of this sensor.
but the problem starts with Arduino A for my project. i try to connect my sensor to my project, and displayed the results on my phone. the data doesn’t match with the first trial in Arduino B.
i don’t even move my sensor to another soil. but the results is different.
Arduino B have ADC range from 0-80, but arduino A 0-300.
i try to compare my sketch from Arduino A and B, and i think there isn’t any problem with that.
would you tell me how to fix it ? i know maybe this topic should be send in arduino forum. but my thanks if you guys help me…

#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Set your ESP-01 baud rate to 9600 with this command AT+UART_DEF=9600,8,1,0,0
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

#define DHTPIN 8
#define DHTTYPE DHT22
#define pHsensor A0
DHT dht(DHTPIN, DHTTYPE);
const int LEDPIN1 = 4;
const int LEDPIN2 = 5;
const int LEDPIN3 = 6;
const int LEDPIN4 = 7;
const int LEDPIN5 = 9; 
int Potensio;
int Potensio1;
int sensorPHValue = 0;
float sensorPH =0.0;
BlynkTimer timer;


BLYNK_WRITE(V1)
{
  // Send Data As Status 1/0 from Blynk App to Arduino Digital Pin
  int pinValue = param.asInt();
  if (param.asInt()){
    digitalWrite(LEDPIN1, HIGH);
  }
  else
  {
    digitalWrite(LEDPIN1, LOW);
  }
}

void PotensioSENSOR()
{
  // Read Analog Data from Sensor, then Send to Blynk App
  Potensio = analogRead(A1);
  Potensio = map(Potensio, 0, 1023, 100, 0);
  Blynk.virtualWrite(4, Potensio);
  void ledempat();
  void ledlima();
}
void ledempat(){
  if (Potensio <= 50){
    digitalWrite(LEDPIN2, HIGH);
  }
  else
  {
    digitalWrite(LEDPIN2, LOW);
  }
}
void ledlima(){
  if ( Potensio <=20){
    digitalWrite( LEDPIN4, HIGH);
  }
  else if ( Potensio >=80){
    digitalWrite( LEDPIN4, LOW);
  }
}

void Potensio1SENSOR()
{
  // Read Analog Data from Sensor1, then Send to Blynk App
  Potensio1 = analogRead(A2);
  Potensio1 = map(Potensio1, 0, 1023, 100, 0);
  Blynk.virtualWrite(6, Potensio1);
  void ledenam();
  void ledtujuh();
}
void ledenam(){
  if (Potensio1 <=50){
    digitalWrite(LEDPIN3, HIGH);
  }
  else 
  {
    digitalWrite(LEDPIN3, LOW);
  }
}
void ledtujuh(){
  if (Potensio1 <=20){
    digitalWrite(LEDPIN5, HIGH);
  }
  else if ( Potensio1 >=80){
    digitalWrite(LEDPIN5, LOW);
  }
}

void pHchecking(){
  sensorPHValue = analogRead(pHsensor);
  sensorPH = (-0.0693*sensorPHValue)+7.3855;
  Blynk.virtualWrite(7, sensorPH);
  Serial.println(sensorPH);
  delay(1000);
}

void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
}

void sendSensor()
{
  // Send Sensor Data from DHT22 to Blynk App
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    Serial.println(" Failed to read from DHT sensor!");
    return;
  }
  Blynk.virtualWrite(V3, h);
  Blynk.virtualWrite(V2, t);
  }

void Sent_Serial()
{
  String content = " ";
  char character;
  while(Serial.available()){
    character = Serial.read();
    content.concat(character);
    Serial.println();
  }
}

void setup()
{
  // Set Pin Mode in Arduino
  pinMode(LEDPIN1, OUTPUT);
  pinMode(LEDPIN2, OUTPUT);
  pinMode(LEDPIN3, OUTPUT);
  pinMode(LEDPIN4, OUTPUT);
  pinMode(LEDPIN5, OUTPUT);
  
  // Debug console
  Serial.begin(9600);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8442);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
  dht.begin();
  timer.setInterval(50L, sendSensor);
  timer.setInterval(50L, PotensioSENSOR);
  timer.setInterval(50L, Potensio1SENSOR);
  timer.setInterval(100L, pHchecking);
  timer.setInterval(50L, ledempat);
  timer.setInterval(50L, ledlima);
  timer.setInterval(50L, ledenam);
  timer.setInterval(50L, ledtujuh);
  timer.setInterval(500, Sent_Serial);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

any code perhaps? and the obvious question: did you check your ‘recalculations’ for both sensors, so the applied voltage vs its range? Also i thought that the ADC range for an arduino was 1023/

First of all, you need to edit your post and format your code correctly, using backticks.

Secondly, youve posted a snippet of your Blynk code, so it’s not possible to tell from that exactly how you’re handling your sensor data and what your void loop, timers etc look like. Post the full (correctly formatted) code.

Pete.

  1. you can edit your post, you don’t need to create a new one
  2. you still havent formatted it!

COPY THIS EXAMPLE AND PLACE YOUR CODE @your code:

```cpp
your code
```

this will result in:

your code

don’t start a new thread on the same topic, just edit your former topic. @Gunner you might want to step in here.
See my former post how to properly format your code and next actually READ what it says when you start a new topic.

Sorry, i’m new here :blush:
post was edited

Lots of timers trying to run simultaneously, and way too frequently in my opinion. You should stagger them.
Is your soil Ph really going to have changed significantly in the 50 milliseconds (0.05 of a second) since you last checked it? I’m fairly sure that checking it every 10 seconds would still to too often in most applications.

Pete.

1 Like