Currently I am working on an Arduino based project. My project require interfacing 6 servo motors and an SD card module to my Arduino UNO. The problem is that I need all the six PWM pins for six servos (Including pin 10) which happen to be the default Slave Select Pin for SPI communication. I don't want to use software based PWM on a digital pin. I could not find any resource on how to change the default SS pin to any other pin. Any help in this regard will be highly appreciated. Thanks!

  • 3
    Other than passing a different argument to SD::begin()? Commented Aug 3, 2018 at 13:01
  • Hmm, I though any GPIO pins could be used for slave selecting.
    – Long Pham
    Commented Aug 3, 2018 at 13:53
  • pin 10 is CS if Atmega 328 is a SPI slave. if Atmega is master pin 10 must be output otherwise the chip switches to slave. pwm is output
    – Juraj
    Commented Aug 3, 2018 at 16:37

1 Answer 1


Just declare it and use it:

byte ssPin = 7; // or any other pin, stay away from 0,1, leave those for Serial()
byte defaultSS = 10; // 53 on a 2560

pinMode (ssPin, OUTPUT);
digitalWrite (ssPIN, HIGH); // typical slave select OFF state
pinMode (defaultSS, OUTPUT);  // 10 MUST be an output for device to be SPI master (328P)
SPI.begin(); // default is 4 MHz speed, MSBFIRST
// takes care of SCK, MISO, MOSI, don't need define/declare those

digitalWrite (ssPin, LOW);
SPI.transfer (ledData, 0xAA); // example data going to a device
digitalWrite (ssPin,  HIGH);
  • 1
    " The problem is that I need all the six PWM pins for six servos" The Servo.h library can drive 12 Servos on an Uno, and on any pin,not just PWM pins. Check it out. Servos need a 1-2mS (1000 to 2000 uS) wide pulse occurring every 20mS (50 Hz), which is not really PWM. (1mS = full turn one direction, 1.5mS = centered, 2mS = full turn the other direction, give or take a few uS). I bet that could be created using Blink without Delay technique even, 50 Hz is pretty slow.
    – CrossRoads
    Commented Aug 3, 2018 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.