Hi everyone! I'm a new user for my cocktail machine school project.
My question is how to write the code which use 2 IR sensors for detecting and responding.
If 1 IR sensor detect something, servo motor turn clockwise 90°.
If 2 IR sensor detect something, servo motor turn anti-clockwise 120°
The first thing to do is to sort out what you actually want to happen. Servos go to a specific position,they don't go so many degrees clockwise or anti-clockwise. And where should the servo be when neither IR sensor detects anything?
There are several examples in the IDE showing you how to use a servo. And there are others showing you how to read an IR sensor though there are several different types of those so you'll have to be more specific about exactly what sensors you have.
Terencellh:
for my cocktail machine school project.
Terencellh:
Anyone can help me to write the code?
That would be cheating.
Split your project in two or more parts. Start with only ONE IR sensor.
Let the sketch print something to the serial monitor when the sensor is detecting something and print something else when the sensor is not detecting. You might want to Google "Arduino state machine" for that.
When you have successfully detected the states of the two IR sensors, then you could use if() statements to make the servos move.
Post your coding attempts and a diagram if you want help with that.
Leo..