Servo Motor controlled by inductive sensor <HELP>

I'm having trouble by programming & creating a circuit diagram by using an SG-5010 Double ball bearing servo motor & a relay module that is controlled by an inductive proximity sensor.

The flow would be;
If the inductive proximity sensor will sense a metallic waste it would give a signal to my relay to my servo motor that would rotate so that the waste would drop into its METALLIC bin instead of NON metallic.

Could anyone help me? thank you Aduino staff's and members as well.

My components used;
Arduino Uno
SG-5010 3 pins Servo Motor
SRD-05VDC-SL-C Relay Module
Inductive Proximity Sensor

THANK YOU & SORRY FOR MY BAD ENGLISH :<

Post your code. Read the forum guidelines to see how to properly post code and some information on how to get the most from this forum.

Describe what the code actually does and how that differs from what you want.

Post a schematic. Include all parts and their part numbers and/or values and all power supplies. Hand drawn, photographed and posted is OK.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

THE CODE I USED;

int motor=13; //

int inpin=2; // proximity sensor connected with the pin 2

int val=0; // this variable will read the value from the sensor

void setup() {

// put your setup code here, to run once:

pinMode(motor,OUTPUT);

pinMode(inpin,INPUT);

}

void loop() {

// put your main code here, to run repeatedly:

val=digitalRead(inpin);

if(val==HIGH)

{

digitalWrite(motor,LOW);

delay(1000);

}

else

{

digitalWrite(motor,HIGH);

delay(1000);

}

}

THE DIAGRAM

Did you get EACH individual piece of your puzzle working by itself before you began to put them together?

yes our servo works properly and as well as our inductive proximity sensor and also the relay, i think i had a problem on my program? i can't determine what the exact problem is :<

We changed the DC MOTOR into SERVO MOTOR, i think it would ruin the program? but i don't know what to change.

Use the Servo library to control a servo motor.

Post photos of your project so that we can see what you actually have.

i kinda have problems with it because it always says error :< can you suggest something that can edit the dc motor into servo motor?

When your code has an error that you want help with you should post the code. Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

The Servo library has example code that will show how to use the library.

Here is your code with the Servo library (untested):

#include <Servo.h>

const byte servoPin = 7; //
const byte ledPin = 13;
const byte inpin = 2; // proximity sensor connected with the pin 2

Servo servo;

int val = 0; // this variable will read the value from the sensor

void setup()
{ 
   pinMode(ledPin, OUTPUT);   
   servo.write(90);  // initial position
   servo.attach(servoPin);
}

void loop()
{
   val = digitalRead(inpin);

   if (val == HIGH)
   {
      servo.write(10);
      delay(1000);
   }
   else
   {
      servo.write(90);
      delay(1000);
   }
}

@keimplox

Your post was MOVED to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.

It will help you get the best out of the forum in the future.

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