Module 10: Input Devices


Module contents:

During this week we've learned about how to use electronic input components, add them to the board and then read input data.

The assignement of this week is to measure something: add a sensor to a microcontroller board and read it.

My work:

Step 1: Selecting Board and Electronic components:

I used the satshakit scheme of my colleague Daniele Ingrassia, then I made it and soldered components and program it:

Connecting and programming my Board

Then I decided to use a potentiometer as input device and read its input data from the computer. I followed the following connection scheme of the potentiometer connection with arduino in order to connect it to my board:

Arduino Potentiometer Scheme

Step 2: Programing Input Device

In order to read data from input device, in my case potentiometer, it is pretty easy as we need to inizialize the serial port, then write a loop that continue reading the analog signal coming from the board and print the result on the screen. I decided to add a delay of half a second between each read operation as I don’t need my board to continue reading value each mille-second.

Here is the potentiometer connected to my board:

Potentiometer connection

Here is the code I wrote in order to read the input data from the potentiometer:

Code to read from Potentiometer

int potentiometerPin = 0;
int value = 0;
 
void setup()
{
    Serial.begin(9600); // Serial port initialization
}
 
void loop()
{
    value = analogRead(potentiometerPin); // Read potentiometer value on analog port
    Serial.println(value); // Write value on serial debug 
    delay(500); // Delay half second
}

And this is the video of the result printed on the screen. Obviously, the value changed each time I acted on the potentiometer:

Download Zone

The Potentiometer program file is available for downloand here: