#define B_sensor A0
const float Tmin = -10;
const float Tmax = 65;
const float Bmin = 0;
const float Bmax = 3000;
const float adcMax = 1023; // 2^10 -1
// uint8_t = variable type stays the same no matter what architecture you compile for / Source: https://arduino.stackexchange.com/questions/30749/int-vs-uint8-t-vs-uint16-t
uint8_t T_sensor[3] = {A1, A2, A3};
int Beschattung_OFF = 2; // pin 2
int Beschattung_ON = 3; // pin 3
float T_avg = 0;
float T_limit = 28;
bool istAusgefahren = false; // garantiert, dass ein pin nur einmal laeuft und nicht unendlich bis der andere pin aktiviert wird.
void setup(){
Serial.begin(9600);
pinMode(Beschattung_OFF, OUTPUT);
pinMode(Beschattung_ON, OUTPUT);
}
void loop(){
// b) Serielles Einstellen
if (Serial.available())
{
float n = Serial.parseFloat();
if (n > 0 && n < 60) T_limit = n;
}
// a) Sensor-Auswertung
float B_adcWert = analogRead(B_sensor);
float B_Wert = Bmax / adcMax * B_adcWert;
float T_Wert = 0;
for(int i = 0; i < 3; i++)
{
T_Wert = T_Wert + (Tmax - Tmin) / adcMax * analogRead(T_sensor[i]) + (Tmin);
}
T_avg = T_Wert / 3;
if((B_Wert > 1400) && (T_avg >= T_limit) && !istAusgefahren)
{
digitalWrite(Beschattung_OFF, HIGH);
Serial.print("Beleuchtungssensor: ");
Serial.print(B_Wert);
Serial.println(" lx");// Lux (lx) is the standard unit of illuminance (light spread across a room)
Serial.print("AVG Temperatur: ");
Serial.print(T_avg);
Serial.println("°C");
Serial.print("T_Limit: ");
Serial.println(T_limit);
delay(10000);
digitalWrite(Beschattung_OFF, LOW);
istAusgefahren = true;
}
else if(((B_Wert < 700) || (T_avg < T_limit)) && istAusgefahren)
{
digitalWrite(Beschattung_ON, HIGH);
Serial.print("Beleuchtungssensor: ");
Serial.print(B_Wert);
Serial.println(" lx");// Lux (lx) is the standard unit of illuminance (light spread across a room)
Serial.print("AVG Temperatur: ");
Serial.print(T_avg);
Serial.println("°C");
Serial.print("T_Limit: ");
Serial.println(T_limit);
delay(10000);
digitalWrite(Beschattung_ON, LOW);
istAusgefahren = false;
}
}
////////////// Aus Musterloesung /////////////////////////////
/* * c) Formel-Anpassung: temp = (raw / 552.4) * 75.0 - 10.0;
Klasse:
INF21
* Begründung: 2,7V entsprechen bei 5V Referenz nur 552,4 Digits
(2,7 / 5 * 1023).
* Der Skalierungsfaktor muss auf den neuen Maximalwert angepasst
werden.
*
* d) Alternative: 'analogReference(EXTERNAL);' nutzen und 2,7V an
den AREF-Pin anlegen.
* Dadurch entsprechen 2,7V wieder 1023 Digits, die alte Formel bleibt
korrekt.
*
* e) Speicherplatz: NEIN. 500 Floats * 4 Byte = 2000 Byte.
* Der Uno hat nur 1024 Byte EEPROM.
*
* f) Adresse 6. Float: 0x0014 (dezimal 20).
Name:
Klasse:
INF21
* Begründung: 5 Werte liegen davor (Index 0-4). 5 Werte * 4 Byte =
20 Byte Offset.
20 / 16(HEX) = 1 | 4
1 / 16(HEX) = 0 | 1
= 14 HEX (0x0014)
*/ Beleuchtungs Sensor