Advertisement
justhrun

LM35_Temperature.ino

Sep 25th, 2014
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #define LM351PIN  0      // PORTC0 / D14 / Fisik pin23 328p
  2. #define LM352PIN  1      // PORTC1 / D15 / Fisik pin24 328p
  3. #define REPLYSIZE  100
  4.  
  5. char reply[REPLYSIZE];
  6.  
  7. void setup() {
  8.   Serial.begin(9600);
  9.   Serial.println();
  10.   analogReference(EXTERNAL);
  11. };
  12.  
  13. void loop() {
  14.   memset(reply,0,REPLYSIZE);
  15.   strcat(reply,"Temperatur");
  16.   Suhu(reply);
  17.   Serial.println(reply);
  18.   delay(3000);  
  19. };
  20.  
  21. void Suhu(char *buff) {
  22.   static float constC = 4.096*10.0;
  23.   int analog1Val = 0;
  24.   int analog2Val = 0;
  25.   float tempC = 0.0;
  26.   char buffer[5];
  27.   strcat(buff," TempA:");
  28.  
  29.   for(byte i=0;i<10;i++) {
  30.     analog1Val += analogRead(LM351PIN);
  31.     analog2Val += analogRead(LM352PIN);
  32.     delay(5);
  33.   }
  34.   tempC = analog1Val/constC;
  35.   dtostrf(tempC,5,2,buffer);
  36.   strcat(buff,buffer);
  37.   strcat(buff," TempB:");
  38.  
  39.   tempC = analog2Val/constC;
  40.   dtostrf(tempC,5,2,buffer);
  41.   strcat(buff,buffer);
  42. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement