Hi, I'm working on a project to control a 12V fuel gauge with an Arduino mega and a transistor. The gauge uses a double coil like this:

I've already made it work, it's not complicated, but now what bothers me is the buzzing it makes due to rapidly open and close the transistor.
I think I could solve that easily by increasing the pwm frequency.
What frequency should I use? Or should I try several frequencies to see which one works best?
Can you help me out with the code to change the frequency? My test sketch uses pin 2 or 3, but I can use any.
Thank you
?
Please post schematics.
How to change PWM frequency. (among 268,000 hits with a search for "arduino mega change pwm frequency tutorial").
Frequencies above 20KHz should be inaudible.
So you say, "here is a schematic that is somewhat similar, but completely different from what I really have". How is that helpful?
Why not draw the schematic of YOUR project on paper, photograph the schematic and post the image.
Yes, I've gone through a lot of articles before posting the question, but it gets a bit confusing for me as it's quite more advanced for my knowledge.
The 20KHz value is a piece that's going to be helpful, now at least I have a starting point.
Regarding the schematics, I wouldn't say it's completely diferent. How is it a different schematic using a PN2222, instead of a BC547? They are bothe npn transistors, and both very similar, aren't they?
What is so hard or confusing about reviewing the actual circuit, confirming the values, and showing it to us? You intend to build it, right? Wouldn't you have to do that, just to build it correctly?
Thanks. That saved us from useless guesses and posting.
Come on guys, why are you giving me such a hard time? it's really not that difficult, I'm just a noob asking for some help. I already gave you the schematics, there's not that much to guess.
Ok, let's do this again. I've built it in a breadboard with several iterations. Right now, at this point, what I have built and seems to be working is this:
Before that I had:
Both circuits seem to do the same, so I'm not sure what the difference in the resistor values does.
The test sketch I have loaded in the Mega is:
int fuel = 3;
void setup() {
TCCR3B = TCCR3B & B11111000 | B00000001;
pinmode(fuel, OUTPUT);
}
void loop() {
analogWrite(fuel, 127);
}
This code stops the circuit from working, the needle doesn't move. If I remove the timer code, it works, but with the buzzin.


