Output Devices

Pablo, Andrea and Daphne have offered to do an online session and help us with the deliveries of Fab Academy input and output devices. The truth is that it has helped us a lot to resolve doubts and detect the small errors that generate frustration.

Once we have understood the input devices it has been easier to apply the knowledge to output devices.

First we have been looking the example of “If Conditional Statement” inside Arduino > Files > 05 Control > IfStatementConditional.

If Conditional Statement Arduino Example

Example of code “If Conditional Statement” inside Arduino Files.

Tempearture Sensor LM35 and LED connected to a Keystudio UNO board (similar to Arduino UNO).

Details of the components Tempearture Sensor LM35 and LED.

Datasheet: LM35

Below there are the two links to datasheet that we have been consulting to understand better the functionalities of the temperature sensors:


Conditional: LM35 + Led

Screenshot of the conditional code with the temperature value configurated at 26ºC.

Code Description
In the beginning of the code is necessary to declare the constants pins. The temperature sensor is connected to pin 0, the led to pin 13 and the value of the conditional is set at 26ºC. The value of 26 is the inflection point, so if the sensor detects a value under or higher 26 is going to be true or false, depending the definition of the code. In this case is the temperature is higher than 26ºC the led will turn on and if it's lower than 26ºC the led will turn off.

The next part of the code is to declare the "void set up" initializing the led as an output and defining the "serial.begin" at 9.600 bps, which means bits per bauds. It is important that this value is the same that in the "serial monitor" of the computer.

Inside the “void loop” it is declared two variable type of integer: data (dat) and value (val).

Then it is declared that the variable “val” is the same value as the analog reading of “analogpin” which is the value readed by the sensor LM35 connected to pin 0.

For the variable “dat” it is applyed a conversion (500 x val) / 1024 to obtain the exact value of temperature in celsius (ºC).

Nex it is declared the “serial.print” of the word temperature “Temp”, the value “dat” which means the temperature and finally the word “ºCª. The delay is defined in 1000 milliseconds.

Finally it is declared the conditional statement. If data “dat” is higher than the inflection point “threshold=26ºC” the led turns on and if “dat” is lower than 26ºC the led turns off.

When the temperature sensor detects a higher value than 26ºC the Led turns on.

If the temperature sensor detects a lower value than 26ºC the Led turns off.

Here you can find the files:
If Statement Conditional Arduino


Future Learning Unit Team




Fab Academy