I m trying to reduce the use of pins used on arduino uno so that i can connect more sensors. I plan to use a 1 by 4 demux IC which uses 2 select lines. so with just 2 pins i can connect 4 loads. I’m new and i dont know how to use it that way. Any advice will be valuable. Thank you
How many sensors you plan to connect?
I know two methods for increase the possibilities - Second MCU or Multiplexing.
Also you can use some ready shields?
wish to connect as much with a single uno
You can use OneWire and connect as much you want temp sensors for example
Yes, but i want to know whether there is a way to control multiple digital pins via single actuators.
Like press a light switch get 2 led’s off or one ON and another OFF
I think that you can. I am posting some code, please note that I might miss something, but I show how I command two relays with one widget and one virtual port I hope you catch the logic!
#define VIRTUAL_BUT V6
#define RELAY1_DIGITAL_PIN 4
#define RELAY2_DIGITAL_PIN 5
char token[] = "AuthenticationToken";
void setup()
{
// set digital pin to output
pinMode(RELAY1_DIGITAL_PIN, OUTPUT);
pinMode(RELAY2_DIGITAL_PIN, OUTPUT);
Serial.begin(9600);
Cayenne.begin(token);
}
void loop()
{
Cayenne.run();
}
CAYENNE_IN(VIRTUAL_BUT)
{
// read the integer value which should be 0 or 1
int enabled = getValue.asInt();
if (enabled == 1) {
// turn both motors on
digitalWrite(RELAY1_DIGITAL_PIN, HIGH);
digitalWrite(RELAY2_DIGITAL_PIN, HIGH);
} else {
// turn both motors off
digitalWrite(RELAY1_DIGITAL_PIN, LOW);
digitalWrite(RELAY2_DIGITAL_PIN, LOW);
}
}
tried it and its awsome awsome awsome, thanks a lot
Just to know, what does the “CAYENNE_IN” do?
is there any thing similar to this?
CAYENNE_IN(vPIN) CAYENNE_IN defines a function that is called when the device receives an updated Virtual pin value from the Cayenne server.
For more information, you can visit Docs → HERE