Arduino Nano and Ultrasonic Trouble

Hi there!

So at the moment I’m pulling my hair out over this issue. So I’m making this project comprised of 6 LED strips that activate different colours based on the distance the viewer is from the ultrasonic. 4 out of the 6 programs are working great but for some reason I can’t get two of them to work. Unfortunately I cant upload a schematic but I can explain I have a 10uF Capacitor across 5V and ground, 330 Ohm resistor to the DI of the LED strip which is going to pin D6, the ultrasonic is hooked up with trigger pin on D2 and echo pin on D3, of course both are hooked up to the 5V and ground.

The sensor is reading distance fine, but it freezes up as soon as something is within range and the LED does not light. I’ve tested the strip using a test program and it is functional. I’m just so confused as to why the signal won’t go through or why it won’t work when the wiring is fine and program seems sound? I’ll insert the program I’m using below here, any ideas on how I should tackle this?

Program:

#include <Adafruit_NeoPixel.h>
#define LEDPIN 6 // connect the Data from the strip to this pin on the Arduino
#define NUMBER_PIEXELS 144// the number of pixels in your LED strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMBER_PIEXELS, LEDPIN, NEO_GRB + NEO_KHZ800);
const int TrigPin = 2;
const int EchoPin = 3;
float cm;
int delayTime = 20;
int wait = 20;
int i = 0;
long duration;
long distance;

void setup()
{
Serial.begin(9600);
pinMode(TrigPin, OUTPUT);
pinMode(EchoPin, INPUT);
strip.begin();

}
void loop()
{

digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);
cm = pulseIn(EchoPin, HIGH) / 58.0; //The echo time is converted into cm
cm = (int(cm * 100.0)) / 100.0; //Keep two decimal places
Serial.print(“Distance\t=\t”);
Serial.print(cm);
Serial.print(“cm”);
Serial.println();

if (cm <=50 && cm>0){

for (int i=0; i<strip.numPixels()-1; i++) {
// starting at i, draw the 7 color rainbow}
// a seven segment rainbow with red on the highest pixel
void rainbow7(uint16_t i, uint16_t wait) ;
int np = strip.numPixels(); // we use the modulo function with this
strip.setPixelColor(i % np, 0, 0, 0); // off
strip.setPixelColor((i+1) % np, 0, 150, 0); //
strip.setPixelColor((i+2) % np, 0, 150, 0); //
strip.setPixelColor((i+3) % np, 0, 150, 0); //
strip.setPixelColor((i+4) % np, 0, 150, 0); //
strip.setPixelColor((i+5) % np, 0, 150, 0); //
strip.setPixelColor((i+6) % np, 0, 150, 0); //
strip.setPixelColor((i+7) % np, 0, 150, 0); //
strip.show();
delay(wait);
strip.clear();
strip.show();}}

if (cm <=100 && cm>50){

for (int i=0; i<strip.numPixels()-1; i++) {
// starting at i, draw the 7 color rainbow}
// a seven segment rainbow with red on the highest pixel
void rainbow7(uint16_t i, uint16_t wait) ;
int np = strip.numPixels(); // we use the modulo function with this
strip.setPixelColor(i % np, 0, 0, 0); // off// end, palest red
strip.setPixelColor((i+2) % np, 0, 250, 30);
strip.setPixelColor((i+3) % np, 0, 250, 30);
strip.setPixelColor((i+4) % np, 0, 250, 30);
strip.setPixelColor((i+5) % np, 0, 250, 30);
strip.setPixelColor((i+6) % np, 0, 250, 30);
strip.setPixelColor((i+7) % np, 0, 250, 30);
strip.show();
delay(wait);
strip.clear();
strip.show();}}
{
strip.clear();
//strip.show();

if (cm<0)
strip.clear();
}

}

// Based on Neopixel Motion Activated Night Light - Arduino Project Hub

Check how to attache code properly, using code tags. Your way is not what we want to see.

How are you powering your 144 LEDs? I'm guessing you have a power issue.

SunBall:
Unfortunately I cant upload a schematic

Why can't you upload the schematic?

void rainbow7(uint16_t i, uint16_t wait) ; That’s a function prototype, not a call to the function.