1

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 simpleanalogWrite();).

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?

Greenonline's user avatar
Greenonline
3,1527 gold badges37 silver badges49 bronze badges
askedApr 14, 2017 at 14:20
Mu3's user avatar
6
  • Request this to be moved to the arduino stackexchangeCommentedApr 14, 2017 at 14:22
  • @JorenVaes how do I do this?CommentedApr 14, 2017 at 14:25
  • No code shown. What in the world are we supposed to speculate about then?CommentedApr 14, 2017 at 14:26
  • @Bort sorry, added the code.CommentedApr 14, 2017 at 14:29
  • Try to replace #define E1 3 with #define E1 PD3 and see if that helps.CommentedApr 14, 2017 at 14:32

4 Answers4

1

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

ThePBx,PCx andPDx designations are unambiguous, so using those are pretty much a safe bet.

answeredApr 14, 2017 at 14:37
Dampmaskin's user avatar
1
  • This is absolutely wrong advice. Arduino functions take Arduino pin numbers. In this case it just happened to work becausePD3 is#defined as 3 and the Arduino pin number is also 3. Try usingPB2 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).CommentedJun 30, 2018 at 5:54
0

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

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

Seethis image:

Nano pinout

Greenonline's user avatar
Greenonline
3,1527 gold badges37 silver badges49 bronze badges
answeredAug 16, 2018 at 4:59
Carolene's user avatar
2
  • Shortened URL redirects toimages.google.co.in/… so not much point to replacing it.CommentedAug 16, 2018 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.CommentedAug 16, 2018 at 8:28
-1

Replace digitalWrite with analogWrite(pin, value)

answeredMay 5, 2018 at 20:47
Name's user avatar
1
  • I'm not sure why you think this would work. Did you read the accepted answer above or the comments under the question?CommentedMay 5, 2018 at 20:53
-1

UsepinMode(NNN, OUTPUT) atsetup()?

Greenonline's user avatar
Greenonline
3,1527 gold badges37 silver badges49 bronze badges
answeredJun 29, 2018 at 22:13
Denis Kirin's user avatar
2
  • 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 readHow do I write a good answer?CommentedJun 29, 2018 at 23:04
  • This is a good answer, the PIN MODE is missing.CommentedNov 3, 2020 at 7:39

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.