Hi!
I'm new to Arduino and this is my first real project. I'm trying to make a solar lamp that turns its head (solar panel) when it doesn't detect any light. I've managed to get my servo motor to turn one way when light disappears and stop (and stay in that positions) if it detects light (in order to charge the battery). The main issue is that when the servo motor reaches 180 degrees it stops and makes this buzzing noise. I want it to go back to 0 degrees when it has done a 180 degrees turn.
(I've tried if statements with two conditions, light and servo positions, as well as light and time. None have worked correctly).
Here's the code I've made (I know it's messy but I did my best ; ) )
Welcome to the forums! Good job posting your code with code tags.
You do not typically attach/detach your servo every time though loop(). Attach it one time in setup() and then just command it to go where you want inside of loop(). Not sure what pin 3 is supposed to do?
I've tried to attach it in setup() but it doesn't work, as if the servo was not connected. And for detach, it is just a simple (probably not really practical) to make the servo stop in that position (and not making any noise).
(Also the pin 3 is for the LED I'm using as a lamp).
Do you know any other way to make the servo silent?
If I do that then, whenever it detects light, it will go back to 0 degrees, my intention is for it to stay in that position until light goes away, then finish the 180 degree turn, in an attempt of finding again some light and, if it doesn't, go back to 0 degrees.