Fan Control

I am building a fan control that will control the whole house fan.

It has 5 speed + the off position. What is the best way of doing this. I am using ESP8266 with a 4 Channel relay board to control the fan. Right now I am using the Slider control and then reading the int value and selecting the right speed but the problem is the slide control on iPhone doesn’t work in integer increments like it does in the web console so most of the time it doesn’t trigger correctly.

I was thinking of just adding 6 buttons, but I need to somehow ensure that only 1 button can be selected ON at one point.

Any help on this would be appreciated.

In your code to set the relays after a button is pressed on the dashboard you can add in a reset for all other pins. Ex: if button 1 is pressed

CAYENNE_IN(V1){
  if (getValue.asInt() == HIGH){
    digitalWrite(2, LOW);
    Cayenne.virtualwrite(V2,LOW);
    digitalWrite(3, LOW);
    Cayenne.virtualwrite(V3,LOW);
    digitalWrite(4, LOW);
    Cayenne.virtualwrite(V4,LOW);
    digitalWrite(1, HIGH);
  }
  else{
    digitalWrite(1, LOW);
  }
}

Repeat for the remaining buttons. The important part of the code is writing the value of the other buttons back to Cayenne since setting the pin low doesn’t automatically update the value on the dashboard.

I edited the code a bit. First of all you want to set the new relay high last to avoid having two on at the same time like you stated. Second, test this code out before you use it because I’m not 100% sure how it will work. I added in the else statement to turn off the relay if the button is pressed to turn off the fan completely but that may be run when Cayenne.virtualwrite(VX,LOW); is called too. Let me know if it works for you!