This example demonstrates the use of M5S analogue output modules to output 0-20 mA / 0-10 V signals. It uses the analogWrite function to set the pulse width modulation (PWM) of a digital output pin. The value has to be between 0 and 255. Also prints the value to the Serial Monitor.


The circuit

  • External: M5S analogue output module outputs 0-10 mA / 0-10 V signal.
  • Internal: M5S analogue output module connected to Arduino digital pin 5.

Ausgeben eines Analogsignals 0 - 20 mA mit Spannungsversorgung 24 V DC. M5S 4 verbunden mit Arduino Digital-Pin 5.


Characteristics of different output modules

  • M5S-AOA05020D3Ab
    Arduino value 0   -> Arduino pin voltage always 0 V -> M5S ON  -> M5S output 20 mA
    Arduino value 255 -> Arduino pin voltage always 5 V -> M5S OFF -> M5S output 0 mA
  • M5S-AOV05010D3Ab
    Arduino value 0   -> Arduino pin voltage always 0 V -> M5S ON  -> M5S output 10 V
    Arduino value 255 -> Arduino pin voltage always 5 V -> M5S OFF -> M5S output 0 V


Code

const int analogOutPin = 5; // analogue output pin

void setup() {
  Serial.begin(9600); // start serial connection  
}

void loop() {
  writeAndPrint(0);
  delay(1000); // wait 1 second
  writeAndPrint(127);
  delay(1000); // wait 1 second
  writeAndPrint(255);
  delay(3000); // wait 3 seconds
}

void writeAndPrint(int value) {
  analogWrite(analogOutPin, value); // change the value of analogOutPin
  Serial.println(value);            // print the value to the Serial Monitor
}

This example code is based on the Arduino standard sample:
http://www.arduino.cc/en/Tutorial/AnalogInOutSerial