Led Cayenne OUT


#1

Hi everyone, I’m new to this field and I have a problem with my project (using Arduino Uno). I would like to turn on the led connected to pin 11 on both the board and Cayenne at the same time.

The problem in my case is how to turn the Led on Cayenne too. I used the Digital Input by selecting the correct pin but the widget on the dashboard does not turn on.

I opted for using the Virtual Pin, by entering Cayenne_OUT in the program as follows:

CAYENNE_OUT (Virtual_Pin0) {
If (ledPin == HIGH) Cayenne.virtualWrite (V0, 1);
}

But even in this case nothing happens … how can I do it? Thanks to who will respond

P.S The Led turn correctly ON on the board.


#2

Hello and welcome to the Cayenne Community,
What do you mean both on the board and Cayenne? The Cayenne is connected with the board and once you turn on the led on the Cayenne, the led on the board will be turned on.
Can you post the whole code here please? I can help you with it :slight_smile:


#4

My program turns on a led when the ultrasonic sensor detects an object. What I want is to turn on the widget on Cayenne at the same time as the physical Led, in order to then use the triggers later. :slight_smile:


#5

Since your application is controlling the state of the LED rather than Cayenne, how about reading in the pin state for the physical pin the LED is connected to, and then changing a 2-State widget on your dashboard, which would reflect the ON/OFF state of the LED? You could then use this 2-State widget to base Cayenne triggers on.

For example in the code below, my LED is wired to digital pin 9 on the Arduino, and I have a 2-State widget on Virtual Pin 6:

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "token";

int ledpin = 9;  

void setup()
{
	//Baud rate can be specified by calling Cayenne.begin(token, 9600);
	Cayenne.begin(token);
  
}

void loop()
{
	Cayenne.run();
}

CAYENNE_OUT(V6)
{
if(digitalRead(ledpin) == HIGH) 
  {
    Cayenne.virtualWrite(V6, 1);
  }
else
  {
    Cayenne.virtualWrite(V6, 0);
  }  
}

#6

Thanks @rsiegel, I was writing similar code :wink:


#7

I’ve used 2-State Widget and all work perfectly!
Thank you so much my friend! :slight_smile: