Code working and now not working Servo + inductive sensor( newbie)

Hi All ,

Im having trouble with some code, It was working and now its not I have a video of it working and went to test it again today and its not, the code was to use a Servo and a inductive sensor to sort steel from plastic. the code was written so the servo would rotate 90 deg >> 45 deg >>0 deg then back to 90 deg then continue in a loop until the inductive sensor was activated ( its state changed from low to high ) it was to rotate 90 >> 135 >> 180 >> 90 and do this as long as it detected steel or just revert back to the previous loop. now it just goes around in a 180 degree cycle stopping at each individual 45 degree interval. I don’t know what to do and I’m in kinda of a rush to get this done asap for a college project . I had it working and i don’t know what went wrong so any help would be greatly appreciated. attached is the code and if you need i can send the video of it working if it helps

Thank you in advanced
David

Servo_with_inductive_sensor.ino (1.46 KB)

Code looks good, so it seems that you messed something up in hardware. Maybe a wire became unplugged (etc.)

Assuming the code in the Arduino is the right one, and you didn’t accidentally upload an old version, then as P_B says check the wiring. Check the wires aren’t loose in their own crimped-on end thingies. Also check the parts in isolation of the system: is the sensor giving the right value under the plastic /metal circumstances for example. If there’s battery power, is it still at a good voltage? (Servo “funnies” are often power related.)

Put another serial print in at the top of loop just after you read the sensor, to make sure it’s reading right.

void loop(){
      // read the state of the pushbutton value:
      sensorState = digitalRead(SENSORPIN);
//add serial print here <<<<<<<<<<<<<<<<<<

ardy_guy:
Assuming the code in the Arduino is the right one, and you didn’t accidentally upload an old version, then as P_B says check the wiring. Check the wires aren’t loose in their own crimped-on end thingies. Also check the parts in isolation of the system: is the sensor giving the right value under the plastic /metal circumstances for example. If there’s battery power, is it still at a good voltage? (Servo “funnies” are often power related.)

Put another serial print in at the top of loop just after you read the sensor, to make sure it’s reading right.

void loop(){

// read the state of the pushbutton value:
      sensorState = digitalRead(SENSORPIN);
//add serial print here <<<<<<<<<<<<<<<<<<






I think you might be right it might be a hardware issue or the board itself. the inductive sensor seems to trip for no reason and stay on for a while then turn itself off. also th "TX" light comes on does this suggest a error ?

No everything is wired correctly ill try source another inductive sensor tomorrow in college and try again with that.