Analog Read Serial

Categories: , , ,

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

HTTP Web Client

Introduction Welcome to the “HTTP Web Client” tutorial using the CONTROLLINO MICRO. In this tutorial, we will learn how to create a web client that

Scan for I2C Devices

Introduction The I2C (Inter-Integrated Circuit) protocol is a popular means of communication between various sensors and devices. In this tutorial, we will learn how to