LDR and Servo Motor

Hello, I am trying to make a project to where I shine a laser at an LDR, which moves a servo to a different position using an if statement if the light is greater than a specific value. However, I do not know how to make the servo hold the different position, because the servo only moves if the LDR detects a constant increase in light. I need it to be where the LDR can detect an increase in light just once to move the servo and keep it there.

We can't help with code we can't see.

Don't forget the code tags.

servo.detach(); will stop it where it was in its tracks but won't "hold" anything there since it's not getting any signals. You will have to use servo.attach(); again every time you change this.

Not the most elegant solution, likely but it has worked for me in the past. Also cuts servo chatter and likely increases servo longevity by not constantly feeding it new signals.

Or you could fix the software to not constantly feed it new signals.

No doubt you could. Hard to say depending on what the servo is actually acting on. It's the method I use for the "magic" treasure chests I make that involve servos. When closed and waiting for a signal in between trick or treaters, it's what I found works reliably and keeps my money out of the local hobby shop. If you have another way, whip it out. I'm always looking for new servo control tricks, too. :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.