0

I am building a project using an Arduino Nano. In it, I am using pin 3 as PWM output. However, If I supply values lower than 255 to it, the pin does not output any voltage at all.

According to this diagram, pin 3 is PWM:

NANO pinout

I have tested it on two boards, it doesn't function on either one. It's not my sketch, either (I tested it with a simple analogWrite();).

This is the code:

void setup() {
  // put your setup code here, to run once:
  #define E1 3  // Enable Pin for motor 1
  #define E2 10  // Enable Pin for motor 2
  #define I1 4  // Control pin 1 for motor 1
  #define I2 2  // Control pin 2 for motor 1
  #define I3 A1  // Control pin 1 for motor 2
  #define I4 A0  // Control pin 2 for motor 2
}

void loop() {
  // put your main code here, to run repeatedly:
  // I use differential steering, speed is important
  analogWrite(E1, 100); // Run in full speed
  analogWrite(E2, 100); // Run in full speed

  // always go forward
  digitalWrite(I1, LOW);
  digitalWrite(I2, HIGH);
  digitalWrite(I3, LOW);
  digitalWrite(I4, HIGH);
}

What could be the reason of this?

  • Request this to be moved to the arduino stackexchange – Joren Vaes Apr 14 '17 at 14:22
  • @JorenVaes how do I do this? – Egor Tamarin Apr 14 '17 at 14:25
  • No code shown. What in the world are we supposed to speculate about then? – Bort Apr 14 '17 at 14:26
  • @Bort sorry, added the code. – Egor Tamarin Apr 14 '17 at 14:29
  • Try to replace #define E1 3 with #define E1 PD3 and see if that helps. – Dampmaskin Apr 14 '17 at 14:32
1

Try to replace #define E1 3 with #define E1 PD3 and see if that helps.

The PBx, PCx and PDx designations are unambiguous, so using those are pretty much a safe bet.

  • This is absolutely wrong advice. Arduino functions take Arduino pin numbers. In this case it just happened to work because PD3 is #defined as 3 and the Arduino pin number is also 3. Try using PB2 instead of the Arduino pin number 10 if you don't believe me. They are not even unambiguous. Those designators are just defined as the bit numbers (e.g. PB3 is also 3). – per1234 Jun 30 '18 at 5:54
0

The third pin (pin 3) is not a PWM pin, it is the RESET pin.

The PWM pins are 6, 8, 9, 12, 13 and 14 (for Arduino Nano).

See this image:

Nano pinout

  • Shortened URL redirects to images.google.co.in/… so not much point to replacing it. – tripleee Aug 16 '18 at 5:52
  • @Carolene according to the schematic given by the OP, pin 3 means digital pin 3 = PORTD 3. The part of your answer "The PWM pins are 6, 8, 9, 12, 13 and 14 (for Arduino Nano)" is completely misleading. – MichaelT Aug 16 '18 at 8:28
-1

Replace digitalWrite with analogWrite(pin, value)

  • I'm not sure why you think this would work. Did you read the accepted answer above or the comments under the question? – sempaiscuba May 5 '18 at 20:53
-2

Use pinMode(NNN, OUTPUT) at setup()?

  • Hi Denis, and welcome to Stack Exchange! Whilst you may be correct, please expand upon your answer, because as it stands it would be more suited as a comment. Please read How do I write a good answer? – Greenonline Jun 29 '18 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.