I've been trying to work on a project that includes arduino uno with inductive sensor. What I want to happen is if the inductive sensor senses that it's a metal in front of the sensor, the servo will be triggered and it will sweep to a certain angle I've check any codes that I can find connected on my project but the sensor is the one working, the servo didn't work. can anyone please help me? I'm new to arduino Been trying to let this code work. I appreciate the help
I connected pin of my servo on digital pin 9 and my inductive sensor on analog pin 0
Specifications of the sensor is this.
Operating Voltage : DC 6-36V range within Universal
Output Type : NPN normally open three-line
Detection object : metal objects
Detection distance : 4 mm
Output Current : 300 mA
Response Frequency : 0.5KH
Temperature range : -25℃ to + 60℃ within + (-) 10% detection distance
Dimensions : 12 mm screw diameter
Cable length : about 115 cm
Material : Metal and plastic
#include <Servo.h>Â //add '<' and '>' before and after servo.h
float metalDetected;
int proximitySensorValue;
int proximitySensorPin = A1;
int servoPin = 9;
int servoAngle = 0;Â // servo position in degrees
Servo servo;
const int trigPin = 2;
const int echoPin = 3;
long duration;
int distance;
void setup() {
 // put your setup code here, to run once:
 Serial.begin(9600);
 servo.attach(servoPin);
 pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
 pinMode(echoPin, INPUT); // Sets the echoPin as an Input
}
void loop() {
 // put your main code here, to run repeatedly:
 proximitySensorValue = analogRead(proximitySensorPin);
 metalDetected = (float) proximitySensorValue*100/1024.0;
 Serial.print("Object detected: ");
 Serial.print(metalDetected);
 Serial.println("%");
}
if (metalDetected >=95 & metalDetected <=100){
 a = 1
So at least make an effort to do something with a servo and get the program to compile. Then load it and try it. Then tell us what it does and then tell us what you wanted it to do that was different.
Just posting some code that makes no effort to do what you claim you want it to isn't helpful.
The sensor has an open-collector (NPN) output so it needs a pull-up resistor. It is also a DIGITAL output so you would read it with a digital (INPUT_PULLUP) pin, not an analog pin.
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html . Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Does your code compile and load to your controller?
What model controller do you have?
Have you got code that just uses the servo?
Have you got code that just uses the inductive sensor?
If not I suggest you start that way.
This way you will be coding for each device and making sure that your codes work, BEFORE, combining them.
The code you are posting has Ultrasonic code in it as well.
Are you writing the code or cutting and pasting bits and pieces?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Your sensor is NPN open collector output, so you will need to have a pull up resistor, either an external resistor or turn on the internal pullup in your code.
But what may be the bigger problem is that it is designed for 6V to 36V supply, so it may not work reliably with 5V.