sábado, 24 de octubre de 2015

temperatura

the following code we are going to see how to connect arduino with MatLab and how to graph the temperature in real time.

ingredientes:

  • Arduino Uno.
  • sensor LM35
  • Led
  • Protoboard
  • resistencia 220 Ohm
Connection diagram:
       

   float temperatura;
   int pinTemp=0;

   void setup() {
    Serial.begin(115200);
   }

   void loop() {
    temperatura=analogRead(pinTemp);
    temperatura=temperatura*0.48828125;  //500 grados es 5v a 10mV por 1°C
    Serial.println(temperatura);
    delay(1000);
   }

       
 
once that We Have the temperature from device, we are going to go Matlab plataform
       

  int pinTemp=0
  int pinTemp=0;
  clc;
  clear all;
  comport = serial('COM5', 'BaudRate', 115200); % setup comport
  fopen(comport);  % Open comport
  x=0;
  while(x<500)
  x=x+1;
  y1(x)=fscanf(comport, '%d'); % receive ADC1
  %y2....
  drawnow; 
  plot(y1,'r-','linewidth',1)
  grid on;
  hold on;
  title('temperature sequence');
  xlabel('Time');
  ylabel('Temperature');
  pause(30);
  end
  fclose(comport); % Close comport
  delete(comport); % Clear comport