Skip to content

Instantly share code, notes, and snippets.

@zach-c-d
Created February 3, 2016 00:10
Show Gist options
  • Save zach-c-d/30438e18b2ae62f000bc to your computer and use it in GitHub Desktop.
Save zach-c-d/30438e18b2ae62f000bc to your computer and use it in GitHub Desktop.
//Take analogue readings from four temperature sensors (LM35). When temperature increases sufficiently (hand touches
//sensor), light up one LED. Each sensor has it's own LED.
//variables for storing the reading, then converting reading to celsius
int reading0;
int reading1;
int reading2;
int reading3;
float tempC0;
float tempC1;
float tempC2;
float tempC3;
//variables for the delta_tempData values
float old_tempC0;
float old_tempC1;
float old_tempC2;
float old_tempC3;
//compares the difference between current tempData and old_tempData
float delta_tempC0;
float delta_tempC1;
float delta_tempC2;
float delta_tempC3;
//store the previous delta value for use in average
float old_delta0;
float old_delta1;
float old_delta2;
float old_delta3;
//averages the last 2 delta values
float av_delta0;
float av_delta1;
float av_delta2;
float av_delta3;
//initialize the tempSensor Pins
int tempPin0 = 0;
int tempPin1 = 1;
int tempPin2 = 2;
int tempPin3 = 3;
//assign the LED pins
int LED0 = 13;
int LED1 = 12;
int LED2 = 8;
int LED3 = 7;
void setup()
{
analogReference(INTERNAL);
Serial.begin(9600);
//initialize LED pins
pinMode(LED0, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
}
void loop()
{
//store tempData as old data for delta values
old_tempC0 = tempC0;
old_tempC1 = tempC1;
old_tempC2 = tempC2;
old_tempC3 = tempC3;
//store old delta values for delta average
old_delta0 = delta_tempC0;
old_delta0 = delta_tempC1;
old_delta0 = delta_tempC2;
old_delta0 = delta_tempC3;
//read data for pin0
reading0 = analogRead(tempPin0);
tempC0 = reading0 / 9.31;
//read data for pin1
reading1 = analogRead(tempPin1);
tempC1 = reading1 / 9.31;
//read data for pin2
reading2 = analogRead(tempPin2);
tempC2 = reading2 / 9.31;
//read data for pin3
reading3 = analogRead(tempPin3);
tempC3 = reading3 / 9.31;
//delta values of tempData and old_tempData
delta_tempC0 = tempC0 - old_tempC0;
delta_tempC1 = tempC1 - old_tempC1;
delta_tempC2 = tempC2 - old_tempC2;
delta_tempC3 = tempC3 - old_tempC3;
//average the current delta and the previous delta
av_delta0 = (delta_tempC0 + old_delta0)/2;
av_delta1 = (delta_tempC1 + old_delta1)/2;
av_delta2 = (delta_tempC2 + old_delta2)/2;
av_delta3 = (delta_tempC3 + old_delta3)/2;
//print all results
Serial.println("results");
Serial.println(tempC0);
Serial.println(tempC1);
Serial.println(tempC2);
Serial.println(tempC3);
Serial.println(""); //empty line to neatin the print
//print all changes (delta values)
Serial.println("changes");
Serial.println(delta_tempC0);
Serial.println(delta_tempC1);
Serial.println(delta_tempC2);
Serial.println(delta_tempC3);
Serial.println("");
//print all delta averages
Serial.println("avearges");
Serial.println(av_delta0);
Serial.println(av_delta1);
Serial.println(av_delta2);
Serial.println(av_delta3);
Serial.println("");
//delay to make serial communication easier to read
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment