0 - 5V to 0 - 10V PWM signal converter for Arduino

Many control devices require a 0 to 10 volt pulse-width modulation (PWM) signal. The Arduino boards digital output pins provide 0 to 5 volt PWM signal. This post shows how a simple PWM signal converter can be built on an Arduino proto shield.


Design


Converter (top)


Converter (bottom)


Components

  • Arduino proto shield with connectors
  • BC639 transistor
  • TO-220 7810 10V voltage regulator
  • 1 kohm resistor
  • 10 kohm resistor
  • 2 terminal blocks
  • connecting wires


Signal

The converter inverses the PWM signal ie. high becomes low and vice versa.


Arduino app for PWM signal handling

const int SERIAL_SPEED = 9600;
const int ANALOG = 512;
const byte analogInCount = 6;
const byte pinCount = 14; 
const byte pins[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
const bool pwmPin[] = { false, false, false, true, false, true, true, false, false, true, true, true, false, false };

bool activePin[14]; 
byte pinValue[14];

byte ArduinoID = 0;

void handleRead() {
    char buffer[80];
    int length = Serial.readBytes(buffer, 80);

    if ( length > 0 ) {
        buffer[length] = 0;
        String buf(buffer);

        int loc1 = buf.indexOf(';');
        if ( loc1 < 1 || loc1 == (buf.length()-1) ) return;
        int loc2 = buf.indexOf(',');
        if ( loc2 < 1 || loc2 == (buf.length()-1) ) return;

        if ( loc1 > loc2-1 ) return;

        String id = buf.substring(0,loc1);
        String pp = buf.substring(loc1+1,loc2);
        String vv = buf.substring(loc2+1,buf.length());

        if ( id.toInt() != ArduinoID ) return;

        int p = pp.toInt();
        int v = vv.toInt();
        if ( p<0 || p>=pinCount ) return;
        if ( v<0 || v>255 ) return;

        activePin[p] = true;
        pinValue[p] = v; 
    }
}

void setup() {
    Serial.begin(SERIAL_SPEED);

    for ( byte i=0; i<analogInCount; i++ ) {
        if ( analogRead(i) > ANALOG ) {
            ArduinoID = i;
            break;
        }
    }
    for ( byte i=0; i<pinCount; i++ ) {
        pinMode(pins[i],OUTPUT);
        activePin[i] = false;  
    }
    String ID;
    ID.concat(ArduinoID);
    Serial.print(ID);
    Serial.print("\n");
}

void loop() {
    if ( Serial.available() ) {
        handleRead();
        delay(100); 
    }
    for ( byte i=0; i<pinCount; i++ ) {
        if ( activePin[i] ) {
            if ( pwmPin[i] ) {
                analogWrite(pins[i],pinValue[i]);
            }
            else {
                digitalWrite(pins[i], pinValue[i]==0 ? LOW : HIGH);
            }
        }
    }
}