Automatic dimming 3w led

Hello. I have an aquarium and I bought some 3W leds to illuminated it. I have 3 led drivers one connected to yellow and red led that I trun on at the morning to simulate the sun rising. I have another driver connected to 12 white led to give maximun light to the plants I turn it on around 9:00 and trun off at 19:00. finally I use a third driver at night with blue moon light led. My idea is dimming it and not just turn it on and off. My idea was add an slider widget and schedule the increment from 10 to 255 slowly. Any idea to do this?

one thing you can do is when you turn ON the Led at 9:00, then program it so that it increments like you said 10 to 255 and then again to 10 and off at 19:00. As using a slider and then incrementing will be a-lot tough.

Is it possible to program events and schedule them to start every day at certain time like this:

create button for each event and schedule it to turn On which will start each . then program accordingly when you receive each button data.

How can I assign the increment/decrement to each button?. Should I need the code and then say to cayenne that all that part of code will be activated for one button?

Create 3 buttons: Yellow, White, Blue with channel 1 2 and 3. then read the status of each button in your code.

CAYENNE_IN(1)  //Yellow button
{
  int value = getValue.asInt();
if (value == 1)
{
//do the increment/decrement code
}
}

similarly, do for White and blue button.
Next add schedule for each button whenever required.

1 Like

Then is possible something like this and schedule it at the time I want??

CAYENNE_IN(VIRTUAL_CHANNEL 8)
{
int value = getValue.asInt();
if (value == 1)

{

//increment code

analogWrite(ACTUATOR9_PIN, 10);
delay(20000);
analogWrite(ACTUATOR9_PIN, 30);
delay(20000);
analogWrite(ACTUATOR9_PIN, 50);
delay(20000);
analogWrite(ACTUATOR9_PIN, 70);
delay(20000);
analogWrite(ACTUATOR9_PIN, 90);
delay(20000);
analogWrite(ACTUATOR9_PIN, 110);
delay(20000);
analogWrite(ACTUATOR9_PIN, 130);
delay(20000);
analogWrite(ACTUATOR9_PIN, 150);
delay(20000);
analogWrite(ACTUATOR9_PIN, 170);
delay(20000);
analogWrite(ACTUATOR9_PIN, 190);
delay(20000);
analogWrite(ACTUATOR9_PIN, 210);
delay(20000);
analogWrite(ACTUATOR9_PIN, 230);
delay(20000);
analogWrite(ACTUATOR9_PIN, 255);

you can try something like this to avoid delay.

void loop() {
  Cayenne.loop();
  if (millis() - lastMillis > 100) {
    lastMillis = millis();
    if (y == 1)
    {
      analogWrite(led, brightness);
      brightness = brightness + fadeAmount;
      Serial.println(brightness);
      if ( brightness >= 255)
      {
        y = 0;
      }
    }
  }
}
 CAYENNE_IN(2)
{
  y = getValue.asInt();
}

Something like this should be enough I am a neofit on this:

/*
This sketch connects to the Cayenne server using an ESP8266 WiFi module as a shield connected via a hardware serial to an Arduino.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:

  1. Install the ESP8266SerialLibrary.zip library via the Arduino IDE (Sketch->Include Library->Add .ZIP Library) from the Cayenne extras/libraries
    folder (e.g. My Documents\Arduino\libraries\CayenneMQTT\extras\libraries) to compile this example.
  2. Connect the ESP8266 as a shield to your Arduino. This example uses the Serial1 hardware serial pins available on the Mega. You can also try
    using a software serial, though it may be less stable.
  3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
  4. Set the network name and password.
  5. Compile and upload the sketch.
  6. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.

NOTE: This code requires ESP8266 firmware version 1.0.0 (AT v0.22) or later.
*/

//#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTESP8266Shield.h>

// WiFi network info.
char ssid = “ssid”;
char wifiPassword = “wifiPassword”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “0af9d8c0-aa28-11e8-b20b-f17b9147793f”;
char password = “f25f0c5226e410f557e6fe890cc4d8e4263e98fc”;
char clientID = “3cd009c0-c1d2-11e8-b882-b98903039cac”;

// Set ESP8266 Serial object. In this example we use the Serial1 hardware serial which is available on boards like the Arduino Mega.
#define EspSerial Serial1

const int VIRTUAL_PIN = 2;

ESP8266 wifi(&EspSerial);

void setup()
{
Serial.begin(9600);
delay(10);

// Set ESP8266 baud rate
EspSerial.begin(115200);
delay(10);

Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
}

void loop() {
Cayenne.loop();
if (millis() - lastMillis > 100) {
lastMillis = millis();
if (y == 1)
{
analogWrite(led, brightness);
brightness = brightness + fadeAmount;
Serial.println(brightness);
if ( brightness >= 255)
{
y = 0;
}
}
}
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
Cayenne.virtualWrite(0, millis());
// Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN(2)
{
y = getValue.asInt();
}

there are something missing in your code. Compile and you will find the error.

Could be something similar with servos I realize I have a rgb dimmer with 3 knobs and I have several servos I already atach them to move the knobs and now I would like to program the servos to move slowly to perform the diming. Is it posible move the servo slowly or maybe create 3 buttons and make something similar to the code you give me ? My current code is this one.

#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>
#include <Servo.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “bcf1bed0-c508-11e8-9747-bb363659b178”;
char password = “1225cd96da23253685e23fbaad8495abf4a562e5”;
char clientID = “c3df6d50-c508-11e8-bf81-6b1a7e6fd7d2”;

#define VIRTUAL_CHANNEL 8
#define ACTUATOR_PIN 4
#define VIRTUAL_CHANNEL 7
#define ACTUATOR_PIN 3
#define VIRTUAL_CHANNEL 9
#define ACTUATOR_PIN 5

Servo s1;
Servo s2;
Servo s3;

void setup()
{
Serial.begin(9600);
Cayenne.begin(username, password, clientID);
s1.attach(4);
s2.attach(3);
s3.attach(5);
}

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

// This function is called when data is sent from Cayenne.
CAYENNE_IN(8)
{
// Determine angle to set the servo.
int value = getValue.asInt();
int position1 = value * 360;
s3.write(position1);
}
CAYENNE_IN(7)
{
// Determine angle to set the servo.
int value = getValue.asInt();
int position2 = value * 360;
s3.write(position2);
}
CAYENNE_IN(9)
{
// Determine angle to set the servo.
int value = getValue.asInt();
int position3 = value * 360;
s3.write(position3);
}

Could be posible to do something like this

Servo s1;
Servo s2;
Servo s3;

void setup()
{
Serial.begin(9600);
Cayenne.begin(username, password, clientID);
s1.attach(4);
s2.attach(3);
s3.attach(5);
}

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

// This function is called when data is sent from Cayenne.
CAYENNE_IN(8)
{
// Determine angle to set the servo.
int value = getValue.asInt();
if (value == 1)
{
int position1 = value
for (int position1=1; position1 <= 255; i++){
s3.write(position1);
delay(10);
}

i did not understand what are you trying to do. can you provide more detail

I want to move activate a button in cayenne dashboard and that my servo starts moving slowly maybe 10° every 20 seconds or something like that. Then create another button to move the opposite until get 0° again.

so you want two button: clockwise and anticlockwise
when clockwise is turned ON move servo from 0 to 180° and when anticlockwise is turned ON move servo from 180 to 0° at interval of 10° ?

yes exactly basically that is what I want.

you can try something like this:

void loop() {
  Cayenne.loop();
  if (millis() - lastMillis > 1000) {
    lastMillis = millis();
    if (x == 1)
    {
     position1 = position1 + 10;
     s1.write(position1);
     if (position1 == 180)
     {
      x = 0;
     }
    }
  }
}

  CAYENNE_IN(4)
  {
     x = getValue.asInt();

  }

Similarly add for decrementing the servo position.

Why do I need to use millis & last millis?

millis() and lastMillis are used to keep track of time. millis() returns the number of milliseconds since the program ran. Here as the millis() becomes greater than lastMillis by 1000, the statements inside the if loop are executed and lastMillis is updated with the new value returned by millis(), this is basically done to avoid delay().

1 Like

Should I need to define something previously? The code send me a message stating that lastmillis was not declared.