Nextion screen dimming relative to ambient lighting

Pretty new here, and fairly new to Arduino. I'm a few weeks into my project which is essentially a building automation system to control lights and a few other things in an RV.

Using a Nextion 10.1" intelligent screen and a Mega. The Nextion comes with a few of it's own GPIO. Have played with the screen a bunch, and am now wondering if anyone has used something like a photoresistor through the GPIO on the screen to auto dim the screen relative to ambient light levels. I suppose it would be the same for any other screen with processing going through the Arduino. I do have some photoresistors, so may just give it a shot.

I've used the Micro Wave Motion Modules to dim the backlight of the screen when no one is around and brighten the backlight when someone is near. I don't see why a photodiode could not be used to detect ambient light levels and adjust the screens output accordingly.

Here is my screen blanking code hope it helps.

void fScreenBlanking( void *pvParameters )
{
  int      TimeOfPause = 10000 * 1000;
  uint64_t PauseStartTime = esp_timer_get_time();
  bool     Pause = false;
  for ( ;; )
  {
    if (!Pause )
    {
      //if motion detect then show display otherwise blank display
      if ( !(gpio_get_level( GPIO_NUM_17)) )
      {
        tft.enableDisplay( false );
      } else {
        Pause = true;
        PauseStartTime = esp_timer_get_time();
        tft.enableDisplay( true );
      }
    } else {
      // still detecting movement reset blanking pause time
      if ( gpio_get_level( GPIO_NUM_17) )
      {
        PauseStartTime = esp_timer_get_time(); // extend pause blanking time
      }
      if ( (esp_timer_get_time() - PauseStartTime) >= TimeOfPause )
      {
        Pause = false;
      }
    }
    vTaskDelay( 125 );
  }
  vTaskDelete( NULL );
} //void fScreenBlanking( void *pvParameters )

Thanks! This is code running in a Nextion screen? I do have manual dimming and screen sleep timer set up through the screen instruction set already. Just wanted to add functionality for optionally auto dimming. Screen will still go to sleep after set time regardless. Don't want to have it set up to auto turn on, like an occupancy sensor would, as the screen is purposely in the highest traffic area.

After a short look, I found a TEMT6000 ambient light sensor module. Might get one of those and try it out.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.