Categories

Archive

Disclaimer

De meningen ge-uit door medewerkers en studenten van de TU Delft en de commentaren die zijn gegeven reflecteren niet perse de mening(en) van de TU Delft. De TU Delft is dan ook niet verantwoordelijk voor de inhoud van hetgeen op de TU Delft weblogs zichtbaar is. Wel vindt de TU Delft het belangrijk - en ook waarde toevoegend - dat medewerkers en studenten op deze, door de TU Delft gefaciliteerde, omgeving hun mening kunnen geven.

Code for Arduino to get LEDs working according to temperature

On the 6th and 7th of october this code was made. The code explores the possibility to give output in steps (in this case LEDs) by measuring temperature via a temperature sensor. Now LEDs are used so the steps are visible. Later the steps should be used to vary the output of an electro motor (see also post "Programming; 1 sensor, 3 outputs" on the 7th of october). Code is in black and comments are in grey.  

 

/*Code adapted by Simone, Renée and Ester on 10/7/2011
The values of the temperature sensor are being monitored by using the Serial Monitor. From here on a default value (standard temperature) is set: x.
LEDs are illuminated according to the change in temperature (e.g. current temperature <= default temperature + variable)
A green (pin 13), on orange (pin 12) and a red (pin 11) LED are illuminated with respect to "laag","middel" or "warm!!".
*/

const int tempAnalogInPin = A0; // Analog input pin that the potentiometer is attached to

int tempIn = 0; // value read from the pot
int heartIn = 0;
int outputValue = 0; // value output to the PWM (analog out)
int x = 500; // x = default value temperature

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); 
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
}

void loop() {
  // read the analog in value:
  tempIn = analogRead(tempAnalogInPin); 
  // map it to the range of the analog out:
  // outputValue = map(tempValue, 750000, 1090000, 0, 255);  
  // change the analog out value:
  // analogWrite(analogOutPin, outputValue);  

  if ((tempIn < (x + 30))) {
      Serial.print(tempIn);
      Serial.println("laag" );
      digitalWrite(13, HIGH);
      digitalWrite(12, LOW);
      digitalWrite(11, LOW);
  }
  if ((tempIn > (x + 30)) && (tempIn < (x + 70))) {
      Serial.print(tempIn);
      Serial.println("middel" );
      digitalWrite(13, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(11, LOW);
  }
  if ((tempIn >= (x + 70))) {
      Serial.print(tempIn);
      Serial.println("warm!!" );
      digitalWrite(13, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(11, HIGH);
  }
  delay(1000);  

Be Sociable, Share!

Leave a Reply

© 2011 TU Delft