Hello,
for testing the code i have used stp16nf06l mosfet and 200R resistor to pwm pin and tested a portion of LED strip. for this i have used omniblug app.
all worked well, it works as per the code except one thing, up on powering off the strip from app green and red LED stays minorly lit.
i have tried everything but i am not being able to correct that problem.
i have also used a 10k resistor between gate and source but its not getting off.
it goes off only after turning off the power supply.
please anyone can tell me how to correct this problem.
i am attaching the code and also link to diagram i have used for wiring.
wiring diagram
code:
//librerias
#include <EEPROM.h>
int ledRed = 10;
int ledgreen=11;
int ledblue=9;
int ledRed2 = 5;
int ledgreen2=6;
int ledblue2=3;
int red;
int green;
int blue;
int action=0;
int bluetooth=2;
int port=0;
int firsttime;
int pinDefault=1234;
void setup()
{
pinMode(bluetooth,OUTPUT);
digitalWrite(bluetooth,HIGH);
Serial.begin(9600);
firsttime=EEPROM.read(0);
if(firsttime!=1){
color(0,255,255);
programer(pinDefault);
EEPROM.write(0,1);
color(255,0,255);
}
}
void loop()
{
while (Serial.available() > 0) {
action = Serial.parseInt();
if(action==1){
port=Serial.parseInt();
red = Serial.parseInt();
green = Serial.parseInt();
blue = Serial.parseInt();
}
if (Serial.read() == '\n') {
color(red,green,blue);
}
}
if(action==2){
color(0,255,255);
delay(500);
color(255,0,255);
delay(500);
color(255,255,0);
delay(500);
}
if(action==3){
int pin = Serial.parseInt();
if (Serial.read() == '\n') {
color(255,0,0);
programer(pin);
action=0;
color(0,255,0);
}
}
}
void programer(int pin){
digitalWrite(bluetooth,LOW);
delay(250);
digitalWrite(bluetooth,HIGH);
delay(5000);
Serial.print("AT");
delay(1000);
Serial.print("AT+NAMEOMNIBLUG");
delay(1000);
Serial.print("AT+PIN"+pin);
delay(1000);
digitalWrite(bluetooth,LOW);
delay(250);
digitalWrite(bluetooth,HIGH);
}
void color(int red, int green, int blue){
if(port==1){
analogWrite(ledRed, red);
analogWrite(ledgreen, green);
analogWrite(ledblue, blue);
}
if(port==2){
analogWrite(ledRed2, red);
analogWrite(ledgreen2, green);
analogWrite(ledblue2, blue);
}
if(port==3){
analogWrite(ledRed, red);
analogWrite(ledRed2, red);
analogWrite(ledgreen, green);
analogWrite(ledgreen2, green);
analogWrite(ledblue, blue);
analogWrite(ledblue2, blue);
}
}
//Fin