AC control with D1 Wemos

Hello,

I’m creating a project for my AC with a D1 Wemos board, I’m a curious amateur, who is using bits of what I find in the community and a little I’ve created with what I’m learning. The result is this Frankenstein below.

Currently I intend to control two temperature sensors, a voltage meter, an output and an analog input on my AC.

Board: D1 Wemos
Temp Sensor: DS18B20
Resistor: 4,7Kohm
Relay: Tongling JQC-3FF-S-Z
Voltage sensor: GBK Robotics

The program worked fine, including in the app, but I have a problem with the temperatures, that on the serial monitor they appear correctly and in the app they keep switching between the virtual input V5 and V6 on app, how can I express myself, one second the value of the sensor 01 appears on the virtual input of sensor 2 and vice versa as well.

Everything is connected properly, but I have doubts. I read it here and there but I still do not understand what went wrong.

Oh I’m not using Sensor 3 yet, but I’ll use it in the future.

Sorry for the english, i’m still learning.

Thanks for the help in advance!

//*************************************************************************
    #define BLYNK_PRINT Serial
    #include <ESP8266WiFi.h>
    #include <BlynkSimpleEsp8266.h>
    #include <SimpleTimer.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    #define ONE_WIRE_BUS_PIN 14 //pin DATA ds18b20
//***************************************************************************

    SimpleTimer timer;

    int Vpin = 5;  // will use Virtual pins 5, 6 and 7 for Sensor data   

    OneWire oneWire(ONE_WIRE_BUS_PIN);
    DallasTemperature sensors(&oneWire);

    DeviceAddress Probe01 = { 0x28, 0xFF, 0x95, 0x58, 0x47, 0x16, 0x03, 0x06  }; 
    DeviceAddress Probe02 = { 0x28, 0xFF, 0xB1, 0x59, 0x47, 0x16, 0x03, 0x6E  };
    DeviceAddress Probe03 = { 0x28, 0xFF, 0xB1, 0x59, 0x47, 0x16, 0x03, 0x10  };


   //******************************************************************
     char auth[] = "XXXXXXXXXXXXXX";

    //******************************************************************

    //Button Logic
    int prevState = -1;
    int currState = -1;
    long lastChangeTime = 0;

    //*******************************************************************

    // Your WiFi credentials.
    // Set password to "" for open networks.
    char ssid[] =  XXXXXXXXXXXXX
    char pass[] = XXXXXXXXXXXXX

    //************************************************************************
    // Button Routine
    void checkPin()
    {
      // Invert state, since button is "Active LOW"
      int state = !digitalRead(12);

      // Debounce mechanism
      long t = millis();
      if (state != prevState) {
        lastChangeTime = t;
      }
      if (t - lastChangeTime > 50) {
        if (state != currState) {
          currState = state;
          Blynk.virtualWrite(V1, state);
          Blynk.setProperty(V1, "color", "#D3435C");
        }
      }
      prevState = state;
    }

    //************************************************************************
    //Voltage routine

    float acum  = 0;
    int analog0 = 0;
    int loops   = 0;
    float v1    = 0;

    void Timer_Voltage()
    {
      analog0 = analogRead(0);
      v1 = (5.0 * analog0)/14;
      
      if (v1 < 1){
        return;
      }
      else {
        
      
        float result = v1;

        Serial.println(result);

        Blynk.virtualWrite(V9, result);    
      }
    }
    void setup()
    {
      // Debug console
      Serial.begin(115200);
      
      Serial.print("Initializing Temperature Control Library Version "); //Serial version temperature, dispensable
      Serial.println(DALLASTEMPLIBVERSION); // Print of lib version, dispensable

    // Initiate sensor routines *********************************
       sensors.begin(); // Initialize the Temperature measurement library
      
      // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
      sensors.setResolution(Probe01, 12);
      sensors.setResolution(Probe02, 12);
      sensors.setResolution(Probe03, 12);

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

        timer.setInterval(3000L, myTimerEvent);  // Setup a function to be called every second
        timer.setInterval(3000L, Timer_Voltage); // Loop of the voltage
        
      // *************************************************************
      // Make pin 2 default HIGH, and attach INT to our handler
      pinMode(12, INPUT_PULLUP);
      //*************************************************************
      
    }
    void loop()
    {
      Blynk.run();
      checkPin(); //Check button.
      timer.run();
      
    }

    void myTimerEvent() {
      Serial.print("Number of Devices found on bus = ");  
      Serial.println(sensors.getDeviceCount());   
      Serial.print("Getting temperatures... ");  
      Serial.println();   
       
      sensors.requestTemperatures();  // Command all devices on bus to read temperature  
      
      Serial.print("Probe 01 temperature is:   ");
      printTemperature(Probe01); 
      Serial.println();

      Serial.print("Probe 02 temperature is:   ");
      printTemperature(Probe02);
      Serial.println();
     
      Serial.print("Probe 03 temperature is:   ");
      printTemperature(Probe03);
      Serial.println();  

    //  Blynk.virtualWrite(V5, Probe01);
    //  Blynk.virtualWrite(V6, Probe02);
    //  Blynk.virtualWrite(V7, Probe03);
      
    }

    /*-----( Declare User-written Functions )-----*/
    void printTemperature(DeviceAddress deviceAddress)
    {
       
       float tempC = sensors.getTempC(deviceAddress);

       if (tempC == -127.00) 
       {
        Serial.print("Error getting temperature  ");
       } 
        else
       {
         Serial.print("C: ");
         Serial.print(tempC);    
         Blynk.virtualWrite(Vpin,(tempC));
         Vpin++;
         if(Vpin >= 8){   // cycle through pins V5 to V7
            Vpin = 5;
         }
       }
    }

If you’re not using Probe03, won’t the last reading in printTemperature be -127 and thus skipping the Vpin++?

When using 12 bit resolution, the sensors have a (up to) 750 ms conversion time, so don’t set the timer interval too fast. And why do you count the devices each time you read the temp? Seems unnecessary? :wink:

2 Likes

Hi!

Thanks for the advice.

The probe 3 stats Sensor Error on the serial monitor, but i will try to connect other sensor.

The resolution bit i will change too and see whats happens.

And the last thing, count the devices, this i dont get…

Please explain to me.

Hi!

Connecting the 3th sensor or removing it of the code solved the problem!

Many thanks!

He was probably referring to this…

 Serial.print("C: ");
 Serial.print(tempC);    
 Blynk.virtualWrite(Vpin,(tempC));
 Vpin++;
 if(Vpin &gt;= 8){   // cycle through pins V5 to V7
  Vpin = 5;
 }

Which is fansnazzy and all… but not needed for a measly three pins… (but for 72 pins, now that is different :stuck_out_tongue_winking_eye: )

 Serial.print("C: ");
 Serial.print(tempC);    
 Blynk.virtualWrite(V5,(tempC));
 Blynk.virtualWrite(V6,(tempC));
 Blynk.virtualWrite(V7,(tempC));
1 Like