Skip to content

8. Input/Output devices

This weeks task encompasses utilizing input and output devices on our Microcontroller

Input Device

An input device is any hardware device that sends data to a computer, allowing you to interact with and control it.

Temperature Sensor

The digital temperature measures temperature changes based on the thermistor resistance. The output of this module is both analog and digital.

The following is a picture of the input temperature Sensor

These are the features of the board

This is how the sensor should be connected to the arduino board

The following is the code that was utilized to get the temperature, where the digital pins (i.e., d_pin and a_pin), analog pins and digital and analog values (i.e., d_val and aval) were defined at the beginning of the code. The digital signal checks if the temperature is above or below the sensor limits which is between -55 to 125 degrees Celsius, if the temperature is within this range the sensor will work, if not it won’t. The analog signal reads the temperature value.

int n = 13;
int d_pin = 2;
int a_pin = A0;
int d_val;
int a_val;

void setup()
{

  pinMode(d_pin, INPUT);

  Serial.begin(9600);
}

void loop()
{
  d_val = digitalRead(d_pin);
  if(d_val == HIGH)
  {
    digitalWrite(n, HIGH);
  }
  else
  {
    digitalWrite(n, LOW);
  }

  // Read the analog interface
  a_val = analogRead(a_pin);
  Serial.println(a_val);

  delay(100);
}

After running the code, the results are as follows:

Output

RGB LED output

This output device consists of a light which will glow with 3 different colors, which are red, green and blue. This output will be programmed in such a way that it will glow green if the temperature is below a certain value and will glow red if its above a certain value. This is illustrated in the gif below below.

The following is the code that has been utilized:

int n = 13;

int d_pin = 2;

int a_pin = A0;

int d_val;

int a_val;

int red_light_pin= A4;

int green_light_pin = A2;

int blue_light_pin = A3;


void setup(){
  Serial.begin(9600);


  pinMode(blue_light_pin, OUTPUT);

  pinMode(green_light_pin, OUTPUT);

  pinMode(red_light_pin, OUTPUT);
}

void loop(){
  // Read the digital interface
  d_val = digitalRead(d_pin);
  if(d_val == HIGH)
  {
    digitalWrite(n, HIGH);
  }
  else
  {
    digitalWrite(n, LOW);

  if (a_val >= 140)
  RGB_color(0, 144, 0); // green light
  else RGB_color(144, 0, 0); // red light

}
a_val = analogRead(a_pin);
  Serial.println(a_val);

  delay(100);
}
void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
 {
  analogWrite(red_light_pin, red_light_value);
  analogWrite(green_light_pin, green_light_value);
  analogWrite(blue_light_pin, blue_light_value);
}

Last update: August 25, 2021