HeathenHacks
Published © GPL3+

Distance Activated Night Light w/ Brightness Control

Using Ultrasonic Sensor + WS2812B LED Strip & 10K Potentiometer

BeginnerFull instructions provided684
Distance Activated Night Light w/ Brightness Control

Things used in this project

Hardware components

LED Strip, NeoPixel Digital RGB
LED Strip, NeoPixel Digital RGB
WS2812B Addressable RGB LED Strip
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
10K Potentiometer
×1
Arduino Nano Every
Arduino Nano Every
To Manage Everything.
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
VS Code
Microsoft VS Code
PlatformIO IDE
PlatformIO IDE

Story

Read more

Schematics

Schematic Diagram

Code

Final Code

Arduino
Pretty much just a concoction of sample codes from their libraries merged together.
#include <Arduino.h> 
#include <Ultrasonic.h>
#include <FastLED.h>
#define NUM_LEDS 10
#define DATA_PIN 6

Ultrasonic ultrasonic1(3, 4); 
CRGB leds[NUM_LEDS];
int Pot = A0;
int PotVal = 0;
int OutVal = 0;

void setup()
{
  Serial.begin(9600);
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
}

void loop()
{
  PotVal = analogRead(Pot);
  OutVal = map(PotVal, 0, 1023, 0, 255);

  if (ultrasonic1.read() <= 10)
  {
    fill_solid(leds, NUM_LEDS, CRGB::OrangeRed);
    analogWrite(NUM_LEDS, OutVal);
    FastLED.setBrightness(OutVal);
    FastLED.show();
    delay(5000);
  }
  else
  {
    FastLED.clear();
    FastLED.show();
  }

  delay(100);
}

Credits

HeathenHacks

HeathenHacks

24 projects • 57 followers
I don't know what I'm doing here.

Comments