Go Down

Topic: Sound sensor acting weird (Read 71 times) previous topic - next topic

lasse93

Hi!

I am trying to make a sound sensor work, and i have a bit of trouble. Im using an analog sound sensor, and it seems to be working fine when its just connected alone to the arduino. But when i hook up som ws2812b that i want to control via an arduino output the sensor starts acting up. It will turn on, and it will then stay on, blinking rapidly. Looking at the serial monitor, i can see that when the lights turn on, it returns the values 0 and 70-something, over and over again. Any idea why this is happening?

Here is my code:

Code: [Select]
#include <Adafruit_NeoPixel.h>

int LEDpin_a = 3;   //Setting the output pin for the LED's in the voice group
int LEDnum_a = 81;    //Number of LED's in string for voice group

int LEDpin_b = 5;   //Setting the output pin for the LED's in the ring group
int LEDnum_b = 36;    //Number of LED's in string for the ring group

int openPin = 7;   //Pin used for open/close sensor
int handlePin = A1;    //Pin used for the sensor in the handle
int umbrellaPin = A3;    //Pin used for sensor in umbrella

unsigned long previousMillis = 0;
const long interval = 100;

Adafruit_NeoPixel strip_a = Adafruit_NeoPixel(LEDnum_a, LEDpin_a);   //This line defines the "object" that is the LED's. The two parameters are the number of LED's in the sequence, and the output pin earlier defined. There are more arguments that can be added, see tutorial for those ;)
Adafruit_NeoPixel strip_b = Adafruit_NeoPixel(LEDnum_b, LEDpin_b);

void setup() {

  Serial.begin(9600);

  pinMode(handlePin, INPUT);
  pinMode(umbrellaPin, INPUT);
  pinMode(openPin, INPUT);

  strip_a.begin();   //Calling the begin function to prepare the LED's for NeoPixel output
  strip_b.begin();

  strip_a.show();   //Sets initial LED's to off, just to be sure
  strip_b.show();

}

void loop() {

  int val = analogRead(umbrellaPin);
  val = map(val, 0, 1023, 0, 100);

  if(val > 50){
    strip_a.setPixelColor(1, 255, 255, 255);
    strip_a.setPixelColor(2, 255, 255, 255);
    strip_a.setPixelColor(3, 255, 255, 255);
    strip_a.show();
  }
  else{
    strip_a.setPixelColor(1, 0, 0, 0);
    strip_a.setPixelColor(2, 0, 0, 0);
    strip_a.setPixelColor(3, 0, 0, 0);
    strip_a.show();
  }
  Serial.println(val);
}



sdturner

How are you powering the Arduino, Sensor and Neopixels? My best guess is that when you turn on the LEDs it is drawing too much current and the Arduino resets or the power supply is dipping and disturbing the sensor.

What sensor are you using?

How many Neopixels are you trying to drive?

Go Up