Howdy nerds (I have the utmost respect for everyone in this forum. You are all smarter than me)
I am an absolute beginner with this stuff. I've been paying a nice Indian chap on Fiverr to help me out with a project and only recently have I lost some confidence.
I am at a point where I am unable to progress due to some issues with my application. I am somewhat locked on hardware because it was already designed an manufactured with pcbway (probably a mistake, but I trusted that ample testing was done by said Fiverr friend)
Anyway... I'm trying to create a small board that will take a 12V power input and a 12V signal. When no signal is present (resting state), it needs to read a potentiometer to output a PWM to a mosfet (to covert the 5v back to 12) powering some LEDs.
When a signal IS present, it will simply set pwm to 100% duty then go back to resting state when signal is no longer present. (with some delay built in to ignore some noise in the signal)
So here is where I am with the code. I'm sure it isn't the most elegant, but it seems simple to me. The LED I am powering is capable of drawing 3A. Even with the pot at the lowest setting, I'm not able to have it draw less than 2A... for whatever reason, the combo of the attiny85, the mosfet, and the pot is not doing the same thing as my Wokwi simulation. Measuring the pot with my multimeter it is clearly 0-5v. I have tried ignoring the pot all together, manually setting the pwm output to a low value like 5 or 10 (out of 255 theoretically unless I've missed something) with no change to the floor. Can't get it to draw any less power aka use a lower duty cycle. I would really like to figure out how to get that 0-100% range.
I'm leaning toward something about the clock settings/time/frequency/duty of the attiny pwm to mosfet relation is not correct. I'm already so over my head on this though. Everything I've typed above (and below) I've literally learned in the last 3 hours of googling. I have no experience with any other Arduino.
// Board : Attiny85
#define sig 3
#define pot A2
#define out 1
int count = 0;
void setup() {
pinMode(sig, INPUT);
pinMode(pot, INPUT);
pinMode(out, OUTPUT);
}
void loop() {
delay(100);
bool signal = digitalRead(sig);
if(signal){
count++;
}else{
count = 0;
}
if (signal && count >= 10) {
count = 10;
digitalWrite(out, 1);
} else {
int pwm = map(analogRead(pot), 0, 1023, 1, 255);
analogWrite(out, pwm);
}
}
Thanks for looking! -Chris