Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to turn the bulbs off in software? #17

Open
SapientHetero opened this issue Oct 7, 2020 · 12 comments
Open

Is it possible to turn the bulbs off in software? #17

SapientHetero opened this issue Oct 7, 2020 · 12 comments

Comments

@SapientHetero
Copy link

I'd like to integrate a PIR sensor with a NCS314 V2.2 in order to extend bulb life by turning them off when nobody is in the room to see them. Is there any way to do this in software?

@afch
Copy link
Owner

afch commented Oct 8, 2020 via email

@Delorean14
Copy link

Write this variable LOW and they shut off.

@regorwislon
Copy link

Can you shed more light (information) on the logic / pinout for a PIR sensor on the NCS314 board (I have v3.4) that you refer to. I note from the board schematic that pin D8 is not used by the shield and potentially could be used to connect a PIR sensor. I was thinking of using this to set BL (SHDN) on pin D5 “LOW” when the sensor did not detect any motion for a period, which would turn off the high voltage to all of the tubes, but there is probably a more elegant way of accomplishing this. The link you suggested to another customer didn’t really help me with this as much as I had hoped.

@SapientHetero
Copy link
Author

SapientHetero commented Feb 21, 2023

I ended up switching from the PIR sensor to an ultrasonic sensor: https://www.amazon.com/HiLetgo-HC-SR04-Ultrasonic-Distance-MEGA2560/dp/B00E87VXH0/ref=sr_1_9?crid=3RQ8SC81A2C1C&keywords=proximity+sensor&qid=1676989931&sprefix=proximity+sensor%2Caps%2C110&sr=8-9 because the PIR sensor kept detecting the airflow from air conditioning vents in the ceiling and no filter algorithm I tried could reject it well enough while still sensing human presence. These aren’t perfect either but they’re better than the PIR sensors.

// Proximity Sensor – note that it also needs power and ground
#define TRIGGER_PIN  23   // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     25   // Arduino pin tied to echo pin on the ultrasonic sensor.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

Here's the code I use with the sensor

// ***** Handle Peeking - detect/extend/end peek mode

  // Starting peek mode in response to ultrasonic sensor
  // If object is detected within configured distance while bulbs are off (sleeping), turn bulbs on in dimmed mode (set elsewhere) for the configured period of time.
  // If daytime, leave them on as long as object is detected
  if (sleeping) {

    if (Settings.alarmBulbsOnDuration && alarmRinging) {               // if configured to do so...
      if (!peekStart)                                                  //  and not already peeking...
        peekStart = millis();                                          //  enter Peek mode on alarm...
      peekDuration = Settings.alarmBulbsOnDuration;                    //  for the configured period of time.
      sleeping = false;                                                //  turn sleeping off when alarm sounds so bulbs turn on
      dimming = false;                                                 //  turn off dimming so PWM doesn't distort alarm music
      RGBLedsOn = Settings.RGBLedsOn;                                  //  and restore RGB LEDs to previous setting
      //DEBUG_PRINTLN(F("Entering peek mode due to alarm"));
    }

    // while waiting for peeking to end, just disable sleeping
    if (peekStart > 0 && (millis() - peekStart < (uint32_t)peekDuration * 1000UL)) { // leave bulbs on if in peek mode...
      sleeping = false;
    }

    // check for sonar ping indicating peeking should start or be extended
    if (millis() - lastSonarPingTime > SONAR_READ_INTERVAL &&                // only do pings at specified interval...
        !ESPTransactionInProgress) {                                         //  and NOT when a transaction is in progress or Serial3 data will be lost
      lastSonarPingTime = millis();                                          // don't ping too often or processor becomes sluggish
      uint16_t maxDistance = (uint16_t)Settings.dayPeekDistance;             // if not dimming, activate sonar at max distance
      if (dimming)                                                           // at night, activate only when sensor is triggered at configured distance
        maxDistance = Settings.peekDistance;
      if (alarmRinging)
        maxDistance = Settings.peekDistance;                        // if alarm is ringing, turn it off if hand is waved in front of sensor
      maxDistance = maxDistance*2 + maxDistance/2;                           // convert maxDistance to cm from inches, roughly
      uint32_t distance = sonar.ping_in(maxDistance);                        // do a ping
      if (distance > 0 && distance <= maxDistance) {                         // if distance is zero, there was no detection, otherwise...
        if (alarmRinging) {                                                  //  if alarm is ringing...
          alarmRinging = false;                                              //   turn it off...
          song = parseSong(noSong);                                          //   and stop playing song
        } else if (!peekStart)
          peekDuration = Settings.peekDuration;                              // determines how long peek will last
        peekStart = millis();                                                // indicates peek cycle in progress and tells us when to end it if it's night time
        sleeping = false;                                                    // turn off sleeping so time is displayed
      }
    }
  }

  // ending peek mode
  if (peekStart > 0) {
    if (millis() - peekStart > (uint32_t)peekDuration * 1000UL) {            // turn peek mode off after configured time elapses
      DEBUG_PRINTLN(F("Leaving peek mode"));
      peekStart = 0;
    }
  }

@regorwislon
Copy link

Thank you. I'll try and get my head around that. I still haven't figured out the best way to actually turn the tubes off / on.

@regorwislon
Copy link

I'm thinking of using LEpin as suggested above, and only allowing it to go HIGH if recent motion has been detected. Is that too simple?

@regorwislon
Copy link

It was too simple! Setting LEpin LOW only stops the tubes from changing from what they are already displaying. However my original idea of using BL (the Blanking pin) by setting pinSHDN LOW does turn them off, and restoring pinSHDN to HIGH turns them back on again. 🙂

@SapientHetero
Copy link
Author

SapientHetero commented Feb 22, 2023 via email

@regorwislon
Copy link

regorwislon commented Feb 22, 2023 via email

@SapientHetero
Copy link
Author

By the way, I am using a combination Mega/ESP8266 board to control my Nixie Clock [https://www.amazon.com/gp/product/B07THDDFSJ/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1. Instead of using the non-user-friendly buttons on the back of the clock to change settings, I run a webserver on the ESP8266 and control it via WiFi.

@regorwislon
Copy link

Nice idea. I have played around with the ESP32Cam board which also runs a webserver to monitor the camera so I might explore this combined board when I have a bit of time. Still have to build a case for my clock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants