TUTORIAL: Analog Read Serial

Intro

This example shows you how to read analog input from your Controllino device over serial communication. In order to do this, you have to connect a potentiometer to one analog input and establish serial communication between your Controllino board and your computer running the Arduino Software (IDE).

IMPORTANT INFORMATION! Please select the proper target board in Tools->Board->Controllino MINI/MAXI/MEGA before uploading to your CONTROLLINO. (Please refer to https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library if you do not see the CONTROLLINOs in the Arduino IDE menu Tools->Board.)

Hardware Required

  • Controllino MINI/MAXI/MEGA
  • 10k ohm potentiometer

Code

#include <Controllino.h> 
/* Usage of CONTROLLINO library allows you to use CONTROLLINO_xx aliases in your sketch. */

// the setup routine runs once when you press reset:
void setup() {
    // initialize the necessary pin as an input pin
    pinMode(CONTROLLINO_A0, INPUT);
 
    // initialize serial communication at 9600 bits per second:
    Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
    // read the input on analog pin 0:
    int sensorValue = analogRead(CONTROLLINO_A0);
    // print out the value you read:
    Serial.println(sensorValue);
    delay(1); // delay in between reads for stability
}

Note: The pin header is working on 5V TTL levels. Voltage levels over 5.5V can damage the Controllino permanently.

Share This Post

More Tutorials to explore

Board & Library Setup with Platform.io

Intro Platform.io together with VS Code is the current de-facto standard for advanced programmers to develop on Arduino boards. CONTROLLINO is natively compatible with Platform.io

Using a 16×2 LCD

Intro The LiquidCrystal library allows you to control LCD displays that are compatible with the Hitachi HD44780 driver. These are the LCDs that are usually connected over a