I'm currently in the development of a project where I need to have the servo to move based on the values gathered by a color sensor. I am fairly new to coding and I'm struggling a bit.
Specifically, I want the servo to move 90 degrees clockwise if the color red is detected. If there is no red detected, I want the servo to either stay at 0 degrees if it is already there or move back counterclockwise 90 degrees back to 0 degrees.
So far, the servo just moves continuously if the color red is detected. I have been trying to figure this out for a while and I've run out of ideas. Any and all help is appreciated.
The code you posted doesn't seem to read any sensor. Post a link to the product page for the sensor you have.
Start by learning how to use the sensor. You will probably need to download a library, which will have some example code. Connect the sensor as instructed and run the example code to test it.
The standard MG996R servo is not continuous, and you will need a separate power supply for it, because the Arduino cannot be used to power servos. A fresh 4xAA battery pack will work to power one MG996R servo.
The posted code does not read the TCS3200 sensor. This tutorial might help you get started.