So I'm trying to set up the following circuit to make the led strip change colors when sound levels change. I'm using 3 2N551 transistors instead of the ones in the picture. A 12 adaptor powers up the breadboard and I'm using 4 resistors in a potential divider circuit to supply the arduino with a 9V supply from the breadboard.
My problem is that the led strip does not change colors. When I plug it in directly to the 12V supply,all 3 colors light up and when I connect it the potential divider circuit it only shows red. It is supposed to change colors as sound detected by the sensor changes (I'm using the KY038 Module), but so far nothing happens. I can see the detected sound changing on the serial monitor and a previous circuit for a rgb bulb was working fine. Any suggestions?
This is the sketch I'm trying to run:
int red_light_pin= 11;
int green_light_pin = 10;
int blue_light_pin = 9;
int soundSensorPin = A0; // Sound Sensor is connected to
int analogValue = 0;
int minVal = 1000;
int maxVal = 0;
void setup() {
pinMode(red_light_pin, OUTPUT);
pinMode(green_light_pin, OUTPUT);
pinMode(blue_light_pin, OUTPUT);
Serial.begin(9600);
}
void loop(){
int diff = 472 - analogValue;
analogValue = analogRead(soundSensorPin);
if(abs(diff) <= 2){
RGB_color(0, 255, 0); //Green
}
else if(abs(diff) <= 5 ){
RGB_color(255, 255, 0); // Yellow
}
else{ //522
RGB_color(255, 0, 0); //Red
}
delay(400);
}
void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
{
analogWrite(red_light_pin, red_light_value);
analogWrite(green_light_pin, green_light_value);
analogWrite(blue_light_pin, blue_light_value);
}
