This example demonstrates the use of M5S analogue input modules to read 0-20 mA / 0-10 V signals. It uses the analogRead function to read an analogue input pin, which results in a value between 0 and 1023. Also prints the value to the Serial Monitor.
The circuit
- External: M5S analogue input module connected to a 0-20 mA / 0-10 V signal.
- Internal: M5S analogue input module connected to Arduino analogue pin A4.
Characteristics of different output modules
- M5S-AIA05020B3
M5S input 0 mA -> Arduino pin voltage 0 V -> Arduino value 0
M5S input 20 mA -> Arduino pin voltage 5 V -> Arduino value 1023 - M5S-AIV05010B3
M5S input 0 V -> Arduino pin voltage 0 V -> Arduino value 0
M5S input 10 V -> Arduino pin voltage 5 V -> Arduino value 1023
Code
const int analogInPin = A4; // analogue input pin
void setup() {
Serial.begin(9600); // start serial connection
}
void loop() {
int sensorValue = analogRead(analogInPin); // read the value of analogInPin into a variable
Serial.println(sensorValue); // print the value to the Serial Monitor
// wait 2 milliseconds before the next loop for the analogue-to-digital
// converter to settle after the last reading
delay(2);
}
This example code is based on the Arduino standard sample:
http://www.arduino.cc/en/Tutorial/AnalogInOutSerial