Skip to content

Instantly share code, notes, and snippets.

@houmei
Created November 30, 2012 14:32
Show Gist options
  • Save houmei/4176111 to your computer and use it in GitHub Desktop.
Save houmei/4176111 to your computer and use it in GitHub Desktop.
Arduino LM35DZ x6 logger
// LM35DZ x6 Thermal Logger
// 2012.11.30 K.Takesita
//
// http://arduino.cc/en/Reference/AnalogReference
unsigned int t,c;
float sc;
// unsigned long time;
#define NUM_LM35 6
int LM35[NUM_LM35] = {A0,A1,A2,A3,A4,A5}; // Analog port
int Adj[NUM_LM35] = {1,0,0,0,0,-1}; // Adjust LM35DZ scatter
int Avalue[NUM_LM35] ; // A0~A5 value register
int led = 13; // HeartBeat
int trig = 8; // for OSC.SCOPE
long int NR = 1 ; // Number of Records
// initialize the library with the numbers of the interface pins
///LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// analogReadEx()
// http://avr.paslog.jp/article/2553893.html
//
int analogReadEx( uint8_t adPort ) {
#define ADC_DUMMY_READ_COUNT 4
uint32_t adc;
for( int i = 0; i < ADC_DUMMY_READ_COUNT; i++ ){
adc = analogRead( adPort ); /* 読み捨てる */
}
adc = analogRead( adPort );
return adc ;
}
float temp5v(int ain) { // analog 0-1023 10mV/Celsius ,5V*100/1024
return ain*5.0*100/1024;
}
float temp3v3(int ain) { // analog 0-1023 10mV/Celsius,3.3V*100/1024
return ain*3.3*100/1024;
}
float temp2v56(int ain) { // analog 0-1023 10mV/Celsius,2.56V*100/1024
return ain*2.56*100/1024;
}
float temp1v1(int ain) { // analog 0-1023 10mV/Celsius,1.1V*100/1024
return ain*1.1*100/1024;
}
void setup() {
pinMode(led, OUTPUT);
pinMode(trig, OUTPUT); //trigger for DSO
// set up the LCD's number of columns and rows:
// lcd.begin(16, 2);
Serial.begin(9600);
// External Aref(3.3V)
// analogReference(EXTERNAL);//3.3V
// Internal Aref(1.1V) ATmega328
analogReference(INTERNAL);
delay(5000); // wait for 5sec
}
void loop() {
digitalWrite(led, LOW);
// Read Analog port
for(int i=0;i<NUM_LM35;i++) {
Avalue[i]=analogReadEx(LM35[i]); // (0...1023)
delay(1000);
}
// Send Report
Serial.print(NR);Serial.print(" ");
for(int i=0;i<NUM_LM35;i++) {
t=Avalue[i]+Adj[i]; // Adjust LM35DZ Variation
// sc=temp1v1(t); // Selcius
sc=temp3v3(t); // Selcius
Serial.print(sc);
if (i<NUM_LM35-1) Serial.print(" ");
}
Serial.print(" : ");
for(int i=0;i<NUM_LM35;i++) { // raw data
Serial.print(Avalue[i]);
if (i<NUM_LM35-1) Serial.print(" ");
}
Serial.println("");
digitalWrite(led, HIGH);
NR++;
// delay(94000-7); // (1000+a)*6+delay=100,000
delay(5000); // for debug
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment