Control relay with two different components

Hello

can someone tell me how I can do that eg I would like to control a relay with on / off and then the reails should still be controlled by a temperature sensor I can not get it I can only control the relay via the temperature sensor have the instruction with timer .run and if I still want to add off / on the relay goes off after a certain time again

It is not quite as simple as getting directions to the corner grocery… particularly since we don’t know where you are, your method of transport, or the location of the grocery :stuck_out_tongue_winking_eye:

You need to break things down into steps; Independent functions that can be called from multiple sources, and each of those calling sources should supply and receive feedback from the other’s in-order to keep synchronized.

Here is a rough logic layout…

  1. Make your relay ON and OFF functions independent
  2. Make your sensor function in a timed loop
  3. Make your button function
  4. Make both 2 & 3 call the appropriate relay function as required
  5. Make both 2 & 3 supply feedback to each other as required (AKA sensor state change updates button state, button state change starts/stops/resets sensor logic as required.

However, the actual code and fiddly bits is all on you. There is probably dozens of different ways to do each step, but with time and effort you can find a way that works best for you, while reaping the overall knowledge and experience in the process.

Show your work and we can assist with pointers along the way.

3 Likes

Hello my code

#define BLYNK_PRINT Serial

#include <TimeLib.h>
#include <SPI.h>
#include <Fishino.h>
#include <BlynkSimpleFishino.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);
float tempout = 0;
float state =0;
int setTemp = 0;
int button = 0; 
 int test = 0;
DallasTemperature sensors(&oneWire);
BlynkTimer timer;
char auth[] = "e0b91bccfb6";
WidgetLED led6(V3);
void setup()
{
  // Debug console
  Serial.begin(9600);
  pinMode(9, OUTPUT);
sensors.begin();
timer.setInterval(1000, Temperaturmessung);
  Blynk.begin(auth, "");
}
BLYNK_WRITE(V5) {
 test = param.asInt();
 
    digitalWrite( 9, HIGH);
}
   
void Temperaturmessung(){
     
  sensors.requestTemperatures();
  tempout = (sensors.getTempCByIndex(0));
  Blynk.virtualWrite(V4, tempout);
   if((tempout > 24 && !state == HIGH )) {
  digitalWrite( 9, HIGH);
  }
  
  else if(tempout <24){ 
    digitalWrite(9, LOW);
  }
  }
void loop()
{
  Blynk.run();
  timer.run();
}

Now take that code, start breaking it apart and creating the separate functions as I suggested… although I would honestly start by creating a new base Blynk code and working with one function at a time, starting with the timed sensor… triggering an LED, Display Widget, Serial print or something; Then a button function to do same triggering thing; Then working on the feedback between them both; And finally switching the LED/Display/Serial print with a relay function and your final control.

I do not know how to do it

as @Gunner said, you have to create a relay function to be call under certain conditions,
as an example :

void RelayOff {
digitalWrite(9, LOW);
}

void RelayOn {
digitalWrite(9, HIGH);
}

You have been on this forum a long time, so you should know this… We help you learn… we do NOT do it all for you. If you want that service, then there are websites that will write your programs for you, at a cost.

1 Like