I'm trying to get 100Hz PWM out of pin9 to drive a DC motor, and vary the duty cycle via a Pot.
Here is the code i have so far. I'm VERY new to this.
Any Help would be appreciated
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
int outputValue = 0;
void setup(){
Serial.begin(19200);
pinMode(9, OUTPUT);
TCCR2B = TCCR2B & 0b11111000 | 0x06;
}
void loop(){
sensorValue = analogRead(sensorPin);
outputValue = map(sensorValue, 0, 1023, 0, 255);
analogWrite(9, outputValue);
Serial.println(outputValue);
}
Pins 9 and 10: controlled by timer 1
Setting Divisor Frequency
0x01 1 31250
0x02 8 3906.25
0x03 64 488.28125
0x04 256 122.0703125
0x05 1024 30.517578125
to yield 122 Hz.
awesome, thanks. I'll give that a try.
i'm trying to switch a 12V load, and when i hook up 12V to the fet, it powers up the arduino. I fear i may need a diode or something on the emitter pin of the fet. Any ideas?
Sounds like you have the FET wired wrong.
Should look like this as example (from a prior discussion - right hand regulator was meant to be 7805), with a Logic Level FET.