int transistorLine = 0; int voltageSens = 3; boolean dynamoOn= false; byte testruns = 15; int thres = 680; void setup() { . pinMode(transistorLine, OUTPUT); pinMode(voltageSens, INPUT); } void loop() { if (dynamoOn = IsDynamoRunning() ) digitalWrite(transistorLine, LOW); else digitalWrite(transistorLine, HIGH); } boolean IsDynamoRunning() { byte test= 0; for (byte i = 0; i < testruns; i++ ) { if (analogRead(voltageSens) >= thres ) test++; delay(1); } if (test == testruns) { return true; } else if (test == 0){ return false; } else return dynamoOn; }