hi, is there any known bug with this command? I don't receive any voltage at the pins I used it on. I used a very simple code:
void setup() {
// put your setup code here, to run once:
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
analogWrite(9, 800);
tried using all different values instead of 800. tried serial monitor and also checked with voltmeter but no voltage, the command "analogWrite" just doesn't seem to work at all.
Do you know the function of the 'analogWrite(arg1, arg2);' instruction?
The instruction produces known frequency PWM (Pulse Width Modulated) signals at the specified DPins of Arduino UNO as depicted in the following figure. arg1 of the instruction refers to DPin and arg2 refers to 8-bit value (0x00 - 0xFF) which determines the on-period of the resultant signal of the DPin.
Upload the following sketch in your UNO. Place a AVM/DVM/OSC at DPin-3 and observe that the reading of the meter changes indicating the changing on-period of the wave.
byte arg2 = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
ananlogWrite(3, arg2); //wave is automatically generated at DPin-3
arg2 = arg2 + 0x20; //pulse width (on-period) being changed by a quanta of 32
delay(1000); //on period changes at 1-sec interval
}
You haven't said what Arduino you're using. They don't all have the same PWM pins but on most I can think of pin 9 is o.k.
Try a basic analogWrite(9,255), just that. If you still see constant 0V at pin 9 then your wiring is wrong and you are shorting out the pin. Either that or something you did earlier has killed that PWM pin, so try a different pin (when you have fixed the wiring).
StrikEagle:
I get a constant value of 0 V at pin enA(pin 9), and I can't get the dc motor to rotate because of this.
How is the motor wired to the Arduino?
Unless it's powered separately and the Arduino PWM is controlling it through a transistor of some sort, it is no surprise that it isn't working. The Arduino can only provide 40mA from an output pin and I can't think of any motor that would be sufficient to drive.
Unless it's powered separately and the Arduino PWM is controlling it through a transistor of some sort, it is no surprise that it isn't working. The Arduino can only provide 40mA from an output pin and I can't think of any motor that would be sufficient to drive.
I use the L298N H bridge to control the dc motors, it has transistors.
UKHeliBob:
What do you see if you print potValue and pwmOutput ?
just a blank white screen. doesn't even show 0.. just blank like if I didn't type any code.
slipstick:
You haven't said what Arduino you're using. They don't all have the same PWM pins but on most I can think of pin 9 is o.k.
Try a basic analogWrite(9,255), just that. If you still see constant 0V at pin 9 then your wiring is wrong and you are shorting out the pin. Either that or something you did earlier has killed that PWM pin, so try a different pin (when you have fixed the wiring).
Steve
tried this, got the 5V, but with my code it doesn't work for some reason..
Post your code containing the Serial.prints that you say don't print anything, If you can't tell what values you're getting it's difficult to know what is going on.
And post a circuit diagram of your setup, particularly showing how everything is powered.
slipstick:
Post your code containing the Serial.prints that you say don't print anything, If you can't tell what values you're getting it's difficult to know what is going on.
And post a circuit diagram of your setup, particularly showing how everything is powered.
Steve
this is the code:
#define enA 9 #define in3 6 #define in4 7 #define button 4
int rotDirection= 0;
int pressed=false;
int pwmOutput=0;
int potValue=0;
void setup() {
// put your setup code here, to run once:
pinMode(enA, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(button, INPUT);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
potValue=analogRead(0);
pwmOutput=map(potValue, 0, 1023, 0 , 255);
analogWrite(enA, pwmOutput);
Serial.println(potValue);
if(digitalRead(button)==true){
pressed=!pressed;
}
while(digitalRead(button)==true);
delay(20);
if(pressed==true&rotDirection==0){
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
rotDirection=1;
delay(20);
}
if(pressed==false&rotDirection==1){
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
rotDirection=0;
delay(20);
}
}
do you have an idea how can I post my circuit diagram? I connected a lot of wires and there is the L298N module, how can I make a diagram of it? sorry it is my first time using arduino I'm really new at this
just a blank white screen. doesn't even show 0.. just blank like if I didn't type any code.
In the serial monitor, there are three pull down menus at the lower right of the sceen. Make sure that the monitor is set to the baud rate specified in the sketch.
cattledog:
In the serial monitor, there are three pull down menus at the lower right of the sceen. Make sure that the monitor is set to the baud rate specified in the sketch.
Serial.begin(9600);
it happends only with this code. not when I use simple codes to test. also when I delete all the "if" commands , then the monitor works fine. when I put all the "if" commands back, it gets blank again. I don't understand why