I made a robot with 2 motors. When i start motors, they produce noise. I try to get rid of it but I fail.
Could you help me?
#define SPEED_2 6
#define DIR_2 7
#define SPEED_1 5
#define DIR_1 4
void setup() {
//TCCR0B = TCCR0B & B11111000 | B00000010;
//TCCR0B = TCCR0B & B11111000 | B00000001;
// put your setup code here, to run once:
pinMode(SPEED_1, OUTPUT);
pinMode(SPEED_2, OUTPUT);
pinMode(DIR_1, OUTPUT);
pinMode(DIR_2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(DIR_1, LOW);
analogWrite(SPEED_1, 75);
digitalWrite(DIR_2, LOW);
analogWrite(SPEED_2, 75);
delay(1500);
digitalWrite(DIR_1, HIGH);
analogWrite(SPEED_1, 0);
digitalWrite(DIR_2, HIGH);
analogWrite(SPEED_2, 0);
delay(1000);
}
If you mean change PWM frequency look here. Or do a Google search for "arduino change pwm frequency" for many pages.
For Arduino Uno, Nano, YourDuino RoboRED, Mini Driver, Lilly Pad and any other board using ATmega 8, 168 or 328
Set PWM frequency for D5 & D6
TCCR0B = TCCR0B & B11111000 | B00000001; // set timer 0 divisor to 1 for PWM frequency of 62500.00 Hz
I write this line in setup function. but motors run non stop?
How can I handle pwm frequency for 5 & 6 pins?
I write this line in setup function. but motors run non stop?
You think that I can troubleshoot your code based on a one line snippet of the code? I am flattered but I am not that good.
Post the whole code. Read the how to use this forum-please read sticky to see how to properly post code and some advice on how to ask a good question. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.
All I need is to increase PWM frequency for motor.
I put this line in setup() for arduino Uno.
TCCR0B = TCCR0B & B11111000 | B00000010;
But motor spins at high speed and doesnt stop.
How to solve it? Any idea?
What are you using to drive the motors, what kind of motors are they, how are you powering them, and how is everything connected together?
I use yellow chiness motors, motor driver and lopo battery 7.4 volt and NANO.