Hier wäre ein Beispiel für den ensprechenden Arduino Code:
`// Using an attiny85 to control a relay by an IR sensor with programmable hysteresis
// code for digicomp attiny85 and IR TCRT5000 Breakout Modul
// attiny85 pins: pin P0 input from sensor D0; pin P2 digital output for LED,relay
// The attiny85 builtin LED is on pin P1
// cr 23.09.2020
int count ;
int delay ;
void setup() {
// put your setup code here, to run once:
pinMode (0,INPUT); // digital input from IR-sensor Breakout Modul D0
pinMode (1, OUTPUT); // output to LED or relay
delay = 5; // delay in seconds (programmable hysteresis)
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(1,HIGH);
if (digitalRead(0)== false)
{ count = seconds ; }
while (count > 0) // leave loop only after IR-sensor has been switched off for count seconds
{ digitalWrite(1,LOW);
delay (1000);
if (digitalRead(0) == false) {count = seconds; } // reset counter
count --;
}
}`