🎁📬❄️📦 Holiday Shipping Deadlines are approaching! International customers and domestic ground - get your orders in 12/9/2020 📦❄️📬🎁
0

How to activate multiple relays off one feeds.
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

How to activate multiple relays off one feeds.

by castecod on Tue Sep 29, 2020 7:46 am

Like the heading says. Is it possible to do that?

I've successfully done this with just one by having ifttt add data (0,1) to the feed. And then my esp8266 well listen to the feed and turn on the corresponding relay. But when I try to do this with just two more data points two and three it no longer works. Any ideas?
Attachments
garage door.ino
(2.84 KiB) Downloaded 3 times
garage door.ino
(2.84 KiB) Downloaded 1 time

castecod
 
Posts: 5
Joined: Wed Jul 11, 2018 2:54 pm

Re: How to activate multiple relays off one feeds.

by brubell on Wed Sep 30, 2020 12:39 pm

Hi castecod,

Could you please post your code within [code] tags? I'll take a look at it.

When you say " it no longer works.", what exactly happens? The relays do not turn on when you've posted more than one data point to the feed the ESP8266 is listening to?

Thanks,

Brent R.

brubell
 
Posts: 1116
Joined: Fri Jul 17, 2015 10:33 pm

Re: How to activate multiple relays off one feeds.

by castecod on Mon Oct 05, 2020 10:10 pm

Thanks brubell,

I have attached the code. But when I say it no longer works. I mean that I can have it accept either a 0 or 1 from IFTTT and my relay takes those numbers and uses it. But when I try to accept any other numbers from the Ada feed than those (2,3, or anything else) it just runs the exact same line: the "Bethiah's garage" door function.

You can see this by the serial prints.

castecod
 
Posts: 5
Joined: Wed Jul 11, 2018 2:54 pm

Re: How to activate multiple relays off one feeds.

by brubell on Wed Oct 07, 2020 10:42 am

Could you please paste the code here in [code] tags? Thanks

brubell
 
Posts: 1116
Joined: Fri Jul 17, 2015 10:33 pm

Re: How to activate multiple relays off one feeds.

by castecod on Thu Oct 08, 2020 11:18 am

Code: Select all | TOGGLE FULL SIZE
#include <ESP8266WiFi.h>
#include "AdafruitIO_WiFi.h"
 
#define WIFI_SSID       "xxx"
#define WIFI_PASS       "xxx"
 
#define IO_USERNAME    "xxx"
#define IO_KEY         "xxx"

#define RelayCody 2  // EPS8266 GPIO0 //temp onboard led
#define RelayBethiah 16  // EPS8266 GPIO2 //temp onboard led

// Connect to Wi-Fi and Adafruit IO handel
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
 
// Create a feed object that allows us to send data to
AdafruitIO_Feed *garageFeed = io.feed("garage");
 
 
void setup()
{
  //define relay output
  pinMode(RelayCody, OUTPUT);
  pinMode(RelayBethiah, OUTPUT);
 
  // start the serial connection
  Serial.begin(115200);
 
  // wait for serial monitor to open
  while(! Serial);

  // Connect to WiFi access point.
  Serial.println(); Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WIFI_SSID);

  Serial.println();

 
  // connect to io.adafruit.com
  Serial.print("Connecting to Adafruit IO");
  io.connect();
 
  // set up a message handler for the 'digital' feed.
  // the handleMessage function (defined below)
  // will be called whenever a message is
  // received from adafruit io.
  garageFeed->onMessage(handleMessage);
 
  // wait for a connection
  while(io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
 
  // we are connected
  Serial.println();
  Serial.println(io.statusText());
 
  garageFeed->get();
}
 
void loop()
{
// io.run(); is required for all sketches.
  // it should always be present at the top of your loop
  // function. it keeps the client connected to
  // io.adafruit.com, and processes any incoming data.
  io.run();
}

// this function is called whenever an 'digital' feed message
// is received from Adafruit IO. it was attached to
// the 'digital' feed in the setup() function above.
void handleMessage(AdafruitIO_Data *data) {
 
  Serial.print("received <- ");
 
 
 //Cody's Garage Door
  if(data->toPinLevel() == 11){
    Serial.println("Opening Cody's Garage Door");
        digitalWrite(RelayCody, HIGH);
        delay(1000);
        digitalWrite(RelayCody, LOW);
        delay(1000);
  }

  if(data->toPinLevel() == 10){
    Serial.println("Closing Cody's Garage Door");
        digitalWrite(RelayCody, HIGH);
        delay(1000);
        digitalWrite(RelayCody, LOW);
        delay(1000);
  }

//Bethiahs's Garage Door
  if(data->toPinLevel() == 1){
    Serial.println("Opening Bethiah's Garage Door");
        digitalWrite(RelayBethiah, HIGH);
        delay(1000);
        digitalWrite(RelayBethiah, LOW);
        delay(1000);
  }

  if(data->toPinLevel() == 0){
    Serial.println("Closing Bethiah's Garage Door");
        digitalWrite(RelayBethiah, HIGH);
        delay(1000);
        digitalWrite(RelayBethiah, LOW);
        delay(1000);
  }
 
 
}

castecod
 
Posts: 5
Joined: Wed Jul 11, 2018 2:54 pm

Re: How to activate multiple relays off one feeds.

by brubell on Fri Oct 09, 2020 10:20 am

Instead of toPinLevel, try using toInt. toPinLevel only handles boolean values and it seems you're passing integers.

brubell
 
Posts: 1116
Joined: Fri Jul 17, 2015 10:33 pm

Re: How to activate multiple relays off one feeds.

by castecod on Sun Oct 11, 2020 12:41 pm

Awesome I'll try that and let you know thank you so much!

castecod
 
Posts: 5
Joined: Wed Jul 11, 2018 2:54 pm

Re: How to activate multiple relays off one feeds.

by castecod on Sat Oct 24, 2020 7:53 am

That worked! Thank you so much!

castecod
 
Posts: 5
Joined: Wed Jul 11, 2018 2:54 pm

Re: How to activate multiple relays off one feeds.

by brubell on Mon Oct 26, 2020 10:19 am

np!

brubell
 
Posts: 1116
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.