int Ldr = A1; int sensorValue = 0; int magnet = 0; bool cycle = true; bool geefAfstand = FALSE; double distance = 0; void setup() { pinMode(D0, OUTPUT); // D0 is de LED pinMode(D1, INPUT); // D1 is de resetknop pinMode(D4, INPUT); // D4 is de Hall Particle.variable("LDR-sv", sensorValue); Particle.variable("distance", distance); Serial.begin(9600); } void loop() { distance = 7.5 * 3.14 * magnet; sensorValue = analogRead(Ldr) ; if (sensorValue > 3700){ digitalWrite(D0, HIGH); if (geefAfstand == TRUE){ Serial.println(distance); Serial.println(geefAfstand); Particle.publish("depth", String(distance)); geefAfstand = FALSE; delay(250); } } else ( digitalWrite(D0, LOW)); if (digitalRead(D4)==HIGH){ if (cycle == FALSE){ magnet += 1; cycle = TRUE; delay(100); distance = 7.5 * 3.14 * magnet; Particle.publish("diepte",String(distance)); Particle.publish("LDR-sv", String(sensorValue)); Serial.println(distance); } } if (digitalRead(D4)==LOW){ if (cycle == TRUE){ magnet += 1; cycle = FALSE; distance = 7.5 * 3.14 * magnet; Particle.publish("diepte",String(distance)); Particle.publish("LDR-sv", String(sensorValue)); Serial.println(distance); delay(100); } } if (digitalRead(D1)==HIGH){ magnet = 0; distance = 0; Serial.println(sensorValue); delay(250); geefAfstand = TRUE; } }