const byte Relay = 3;const byte LDRa = 1;const byte LDRb = 2;const byte LDR1 = 0;boolean A = LOW;int stateLDRa;int lastStateLDRa = LOW;int stateLDRb;int lastStateLDRb = LOW;int stateLDR1;int lastStateLDR1 = LOW;unsigned long lastDebounceTimeLDRa = 0;unsigned long lastDebounceTimeLDRb = 0;unsigned long lastDebounceTimeLDR1 = 0;unsigned debounceDelay = 1000;void setup() { pinMode(Relay, OUTPUT); //setting the pin mode to Output digitalWrite(Relay, LOW);}void loop() { // read LDRa and debounce int readingLDRa = digitalRead(LDRa); //digitalWrite(ledPin, readingLDRa); if (readingLDRa != lastStateLDRa) { lastDebounceTimeLDRa = millis(); } if ((millis() - lastDebounceTimeLDRa) > debounceDelay) { if (readingLDRa != stateLDRa) { stateLDRa = readingLDRa; } }lastStateLDRa = readingLDRa; // read LDRb and debounce int readingLDRb = digitalRead(LDRb); if (readingLDRb != lastStateLDRb) { lastDebounceTimeLDRb = millis(); } if ((millis() - lastDebounceTimeLDRb) > debounceDelay) { if (readingLDRb != stateLDRb) { stateLDRb = readingLDRb; } }lastStateLDRb = readingLDRb; // read LDR1 and debounce int readingLDR1 = digitalRead(LDR1); if (readingLDR1 != lastStateLDR1) { lastDebounceTimeLDR1 = millis(); } if ((millis() - lastDebounceTimeLDR1) > debounceDelay) { if (readingLDR1 != stateLDR1) { stateLDR1 = readingLDR1; } }lastStateLDR1 = readingLDR1; if (stateLDRa == HIGH && stateLDR1 == LOW && stateLDRb == LOW) //condition 1; clockwise { digitalWrite(Relay, HIGH); A = HIGH; } if (stateLDRa == LOW && stateLDR1 == HIGH && stateLDRb == LOW && A == HIGH) //condition 2; clockwise { digitalWrite(Relay, LOW); } if (stateLDRa == LOW && stateLDR1 == LOW && stateLDRb == HIGH) //condition 3; clockwise and counterclockwise: set relay low { digitalWrite(Relay, LOW); A = LOW; } if (stateLDRa == LOW && stateLDR1 == HIGH && stateLDRb == LOW && A == LOW) //condition 4; counterclockwise: set relay high { digitalWrite(Relay, HIGH); }}
Duitstalig heeft ook wel wat: kehrschleifeb.v. http://k.f.geering.info/modellbahn/technik/kehrschleife.htm
Een volledig uitgekauwd aansluitschema zou wel fijn zijn. Dus waarin de arduino etc te zien is, waar en hoe sluit je daar het relais op aan, hoe en waar sluit ik de boel aan op mijn detectie? Ik vind het een beetje summier zo.
Maar effecteif en voor een zelfverklaarde 'elektroleek' als Joke misschien toch handiger. Of een gewone Lenz.Het lijkt wel of met het voortschrijden der techniek de keerlusautomaten steeds ingewikkelder worden. Oh ja, dat heet hobby.
oei, plots zijn mijn berichten heel breed uitgesmeerd: hoe los ik dat op?
Dat komt waarschijnlijk door het code blok. Dat gebruikt de hele breedte die je erin stopt. Dus die commentaren aan het eind van een paar regels zijn de dader.Soms komt het ook door een lange link. Edit: ja, het was een link. In dit bericht heb ik de ellenlange aliexpress url vervangen door het woordje "link" Reinout