shramik salgaonkar
Published

Cayenne Diwali Lantern

A smart IOT Diwali lantern which can be turned on, scheduled to turn on at particular time using Cayenne app.

IntermediateShowcase (no instructions)582
Cayenne Diwali Lantern

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
×1
Relay (generic)
×1

Software apps and online services

Cayenne
myDevices Cayenne
Arduino IDE
Arduino IDE

Story

Read more

Code

Smart_Diwali_Lattern.ino

Arduino
class Flasher
{
    // Class Member Variables
    // These are initialized at startup
    int ledPin;      // the number of the LED pin
    long OnTime;     // milliseconds of on-time
    long OffTime;    // milliseconds of off-time

    // These maintain the current state
    int ledState;                 // ledState used to set the LED
    unsigned long previousMillis;   // will store last time LED was updated

    // Constructor - creates a Flasher
    // and initializes the member variables and state
  public:
    Flasher(int pin, long on, long off)
    {
      ledPin = pin;
      pinMode(ledPin, OUTPUT);

      OnTime = on;
      OffTime = off;

      ledState = LOW;
      previousMillis = 0;
    }

    void Update()
    {
      // check to see if it's time to change the state of the LED
      unsigned long currentMillis = millis();

      if ((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
      {
        ledState = LOW;  // Turn it off
        previousMillis = currentMillis;  // Remember the time
        digitalWrite(ledPin, ledState);  // Update the actual LED
      }
      else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
      {
        ledState = HIGH;  // turn it on
        previousMillis = currentMillis;   // Remember the time
        digitalWrite(ledPin, ledState);   // Update the actual LED
      }
    }
};
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

// WiFi network info.
char ssid[] = "Redmi";
char wifiPassword[] = "shramik49";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "1e6889a0-a8a0-11e6-a85d-c165103f15c2";
char password[] = "0a7443db1f633b13a06d00adea16f34e1b14f1d2";
char clientID[] = "aa3a2da0-b329-11e7-b177-579293954599";
int x;

Flasher led1(4, 1000, 1000);
Flasher led2(0, 2000, 1000);
Flasher led3(2, 3000, 1000);

void setup()
{
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop()
{
  Cayenne.loop();
  if (x == 1)
  {
    led1.Update();
    led2.Update();
    led3.Update();
  }
  if (x == 3)
  {
    digitalWrite(4, HIGH);
    digitalWrite(0, LOW);
    digitalWrite(2, LOW);
  }
  if (x == 4)
  {
    digitalWrite(4, LOW);
    digitalWrite(0, HIGH);
    digitalWrite(2, LOW);
  }
  if (x == 5)
  {
    digitalWrite(4, LOW);
    digitalWrite(0, LOW);
    digitalWrite(2, HIGH);
  }
  if (x == 2)
  {
    digitalWrite(4, LOW);
    digitalWrite(0, LOW);
    digitalWrite(2, LOW);
  }
}
CAYENNE_IN(1)
{
  int ledpattern = getValue.asInt();
  if (ledpattern == 1)
  {
    x = 1;
  }
}

CAYENNE_IN(3)
{
  int ledpattern3 = getValue.asInt();
  if (ledpattern3 == 1)
  {
    x = 3;
  }
}
CAYENNE_IN(4)
{
  int ledpattern4 = getValue.asInt();
  if (ledpattern4 == 1)
  {
    x = 4;
  }
}
CAYENNE_IN(5)
{
  int ledpattern5 = getValue.asInt();
  if (ledpattern5 == 1)
  {
    x = 5;
  }
}
CAYENNE_IN(6)
{
  int ledpattern6 = getValue.asInt();
  if (ledpattern6 == 1)
  {
    x = 2;
  }
}

Credits

shramik salgaonkar

shramik salgaonkar

1 project • 0 followers

Comments