Thursday, April 30, 2015

Arduino Serial communication and Proteus ISIS simulation

 

The serial communication on most devices is a transmission of data between the microcontroller to a computer or even to another microcontroller.

The Arduino serial port (also known as a UART or USART) that stands for Universal Synchronous/Asynchronous Receiver/Transmitter and provides the interface necessary for communication with modems and other serial devices.

For this type of communication you’ll need three cables (TX, RX, GND) and they stand for:

TX: Transmit pin

RX: Receive pin

Take into account that it is different with I2C and SPI where the labels and the pins are connected with each other, in serial communication the pins should be inverted and connected that way.

Devices

In the following picture you can see the schematic of the exercise.

Schematics

The components used in this exercise were:

1 x LM35 Temperature sensor

1 x Arduino board

1 x Terminal debugger

I uploaded the code on the “Source Code” window, here you can see the window:

Code

The code I uploaded was this:

/*
/////////////////////////////////////////////////////////////////////////////////////
AUTOR: JUAN BIONDI FECHA: FEBRERO/2014
PROGRAMA: TERMOMETRO (LM35) VERSION: 1.0
DISPOSITIVO: ATMEL 328 COMPILADOR: AVR
ENTORNO: PROTEUS SIMULADOR: VSM
TARJETA DE PROGRAMACION: DEBUGGER:
/////////////////////////////////////////////////////////////////////////////////////
The LM35 is a temperature sensor with a calibrated precision of 1ºC. It can measure from -55 C to 150 C.

The output is that one grade is equal to 10mV
150ºC = 1500mV
-55ºC = -550mV1
0ºC = 0mV

/////////////////////////////////////////////////////////////////////////////////////
*/


/////////////////////////////////////////////////////////////////////////////////////
// LIBRERIAS //
/////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////
// VARIABLES GLOBALES //
/////////////////////////////////////////////////////////////////////////////////////

//Declare the variables
#define pinA0 0
int valor_leido;
float Temperatura;
float Temp2;

/////////////////////////////////////////////////////////////////////////////////////
// FUNCIONES //
/////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////
// CONFIGURACION //
/////////////////////////////////////////////////////////////////////////////////////

void setup()
{
analogReference(INTERNAL); // Used for setting the analog reference to 1.1V
Serial.begin(9600); //Start the serial communication
}


/////////////////////////////////////////////////////////////////////////////////////
// PRINCIPAL //
// //
/////////////////////////////////////////////////////////////////////////////////////

void loop()
{
valor_leido = analogRead(pinA0); //Read the value of the analog pin

Temperatura = (valor_leido*1.1*100) / 1024; //Convert that value to temperature

Serial.print("Temperatura: "); //Print the information to the terminal window
Serial.print(Temperatura);
Serial.print("C ");

Temp2 = map(valor_leido,0,1023,0,11000); //This is another conversion using the map function

Serial.print("Temperatura por map: ");
Serial.print(Temp2/100);
Serial.print(" Lectura digital: ");
Serial.println(valor_leido);

delay(1000); //Set a delay so we can see each second the temperature we are measuring

}

I n the next picture you can see the information on the terminal debugger once we click on the play button.


Code_running


You can download the file on the following link:


https://drive.google.com/folderview?id=0B7dtMeeMPK5rfnJCSVlRVTkxRzdSeHBMWDJ6THVPWmdHdm1kZ3NwNTYzSEJ5b0ZmdlFoMG8&usp=sharing


File name: Termometro.zip


Version of Proteus 8.1

No comments:

Post a Comment