Hello,
I'm kind of new to Arduino, and I'm trying to do his project where I have an mlx90614 thermal sensor to detect high heat levels. When the high heat level is detected, the servo motor will move. My code has no errors and the sensor is working fine. However, the servo motor is constantly moving regardless of the if statement that I put in the code. If anyone has any suggestions please let me know.
What type of servo ?
Is it, by any chance, a "continuous rotation" servo, so not really a servo at all
Please follow the advice on posting code given in posting code
In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless
The servo just moves constantly back and forth when I run the code.
Look at your code and think what happens if the temperature is less than 100
The servo will move to 0, wait 1 second then move to 90. loop() will then end, the temperatures will be displayed and a delay of 500 milliseconds occurs
Then the servo will move to 0, wait 1 second then move to 90. loop() will then end, the temperatures will be displayed and a delay of 500 milliseconds occurs
This is what you are seeing. What do you want the servo to do if the temperature is less than 100 ?
I want my servo to remain still when it's less than 100 degrees. I tried flipping the less than sign, and the servo still movies. My goal is to have the servo move one rotation when it's above 100 degrees, but when it's less than 100 degrees, I want it to remain still.
You command a servo not to move by simply writing a value to it. If your SG90 rotates continuously when you write a value of say 0 to it then you don't have a servo at all you have a "continuous rotation servo", ie not really a servo at all, rather an electronically controlled motor. Not the same thing at all. See my question in reply #1
If that is the case then all you can do is to control its speed and direction, not its position. Writing 0 to it will rotate it at full speed in one direction whilst writing 180 to it will cause it to rotate at full speed in the opposite direction. Writing 90, or something close to 90, to it may cause it to stop rotating but you cannot control its position