Devices & Components
Arduino Nano Every
Breadboard (generic)
Rotary potentiometer (generic)
Ultrasonic Sensor - HC-SR04 (Generic)
Jumper wires (generic)
LED Strip, NeoPixel Digital RGB
Software & Tools
PlatformIO IDE
Arduino IDE
VS Code
Project description
Code
Final Code
arduino
Pretty much just a concoction of sample codes from their libraries merged together.
1#include <Arduino.h> 2#include <Ultrasonic.h> 3#include <FastLED.h> 4#define NUM_LEDS 10 5#define DATA_PIN 6 6 7Ultrasonic ultrasonic1(3, 4); 8CRGB leds[NUM_LEDS]; 9int Pot = A0; 10int PotVal = 0; 11int OutVal = 0; 12 13void setup() 14{ 15 Serial.begin(9600); 16 FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); 17} 18 19void loop() 20{ 21 PotVal = analogRead(Pot); 22 OutVal = map(PotVal, 0, 1023, 0, 255); 23 24 if (ultrasonic1.read() <= 10) 25 { 26 fill_solid(leds, NUM_LEDS, CRGB::OrangeRed); 27 analogWrite(NUM_LEDS, OutVal); 28 FastLED.setBrightness(OutVal); 29 FastLED.show(); 30 delay(5000); 31 } 32 else 33 { 34 FastLED.clear(); 35 FastLED.show(); 36 } 37 38 delay(100); 39} 40
Final Code
arduino
Pretty much just a concoction of sample codes from their libraries merged together.
1#include <Arduino.h> 2#include <Ultrasonic.h> 3#include <FastLED.h> 4#define 5 NUM_LEDS 10 6#define DATA_PIN 6 7 8Ultrasonic ultrasonic1(3, 4); 9CRGB 10 leds[NUM_LEDS]; 11int Pot = A0; 12int PotVal = 0; 13int OutVal = 0; 14 15void 16 setup() 17{ 18 Serial.begin(9600); 19 FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, 20 NUM_LEDS); 21} 22 23void loop() 24{ 25 PotVal = analogRead(Pot); 26 OutVal 27 = map(PotVal, 0, 1023, 0, 255); 28 29 if (ultrasonic1.read() <= 10) 30 { 31 32 fill_solid(leds, NUM_LEDS, CRGB::OrangeRed); 33 analogWrite(NUM_LEDS, OutVal); 34 35 FastLED.setBrightness(OutVal); 36 FastLED.show(); 37 delay(5000); 38 39 } 40 else 41 { 42 FastLED.clear(); 43 FastLED.show(); 44 } 45 46 47 delay(100); 48} 49
Downloadable files
Schematic Diagram
Schematic Diagram

Comments
Only logged in users can leave comments