Can anyone help me with led strip and distance sensor (similar concept to proximity sensor from the website)
-
Hey guys, I just found the proximity / LED ring example on the website as I am trying to do a similar project work with GPS instead of proximity sensor.
I have a small strip of 7 addressable sk6812 leds and I would like to have them turn on when certain distance has been achieved. I'm looking at the proximity LED ring example but I can't figure out which parts of that sketch could I incorporate in mine.
I would like to use the LED strip instead and have 3 criterias for 3 preset distances. For example,
- at 5m turn on led 1 and 2 in blue
- at 3m turn on led 3 4 5 in yellow
- at 1m turn all leds in red.
At the moment I only can use those clunky 5mm leds and void loop looks like this - this turns on the LED if the distance is 5m or less.
Serial.print(F("Next in range = ")); Serial.print(shortestDist, 2); Serial.println(" m"); if (shortestDist < 5) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } } if (gps.charsProcessed() < 10) Serial.println(F("No GPS data.")); last = millis(); Serial.println();
-
Try using the Neopixel library.
https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-use
https://sbaronda.com/2020/09/20/sk6812-with-arduino-using-neopixel-library/
Those should get you started. Basically, instead of having your code directly turn a pin on or off, you tell it to set a color in the library and then run the show() command and the library will do all the pin toggling needed to actually control the LEDs.
Suggested Topics
-
Day 1 - Status report
Announcements • 23 Mar 2014, 22:45 • hek 24 Mar 2014, 20:12 -
Getting system time from the controller
Troubleshooting • 27 Feb 2025, 01:39 • dpcons 3 Mar 2025, 01:00 -
Forum Search not working?
Troubleshooting • 4 Oct 2023, 23:33 • Gibber 2 Sept 2024, 20:28 -
NODs stop responding, but ping works.
Troubleshooting • 8 Mar 2025, 19:47 • Marcin 8 Mar 2025, 19:47 -
Can not compile MySensors on esp8266
Troubleshooting • 24 Aug 2024, 15:35 • TheoL 29 Aug 2024, 20:47 -
JSN-SR04T-V3.0 Coax cable extended
Troubleshooting • 19 Mar 2025, 21:00 • bocalexandru 21 Mar 2025, 12:05