An Arduino project for controlling multiple servos on a PCA9685 with two leds to display on your control panel.



The Sketch

To use this sketch you must have the Adafruit servo driver installed.  To install it, in your Arduino IDE, go to tools, manage libraries and type in adafruit pwm.  Install it.


This code is for one servo.  Add as many servos as yo wish.


#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

int buttonPin0 = 2;
int ledPin0C = 3;
int ledPin0T = 4;
int buttonState0 = 0;

void setup() {
Serial.println(“Steaminfo Turnouts”);

pinMode(ledPin0C, OUTPUT);
pinMode(ledPin0T, OUTPUT);
pinMode(buttonPin0, INPUT);

void loop() {
buttonState0 = digitalRead(buttonPin0);
if (buttonState0 == HIGH) {
digitalWrite(ledPin0T, LOW);
digitalWrite(ledPin0C, HIGH);
else {
pwm.setPWM(0, 0, 285);
digitalWrite(ledPin0C, LOW);
digitalWrite(ledPin0T, HIGH);




The Fritzing Diagram

Fritzing diagram for pca9685 turnout control
Fritzing diagram for pca9685 turnout control

This shows two turnouts.   Follow the sequence to control more turnouts.









This is part of our Arduino Projects series.  You are invited to look there to see what is available.

The sketch and diagram are from Toms Trains And Things.

We hope that you found the information in this page useful. The internet is all about getting and giving. And giving back is the best. Please donate $1 or more to aid us in our continuing quest to add to and polish the information in our site.

Scroll to top