Magnetically triggered servo

Hi. Complete newbie here although I do have a background in SQL, VBA and Javascript, so not coming in absolutely blind :slight_smile:

I have sketched out a project in tinkercad for a magnetically triggered servo using a reed switch. I've had to use a standard hobby servo and push button in tinkercad as the continuous servo and reed switches that I am using in the real world are not available in that virtual environment. I've also had to bring the voltage supply to the servo down with a diode which I won't need to do in reality. Other than that, it's a faithful replica of what I want to create and runs fine.

When uploading to my board, things just aren't running >:( .

Potential issues are the connections as the breadboard seems of dubious quality to me. I also am unsure if which is the correct signal connection on my feetech fs5106r It has red, which I assume is power, brown, which I assume is negative / ground, and orange, which I would imagine is the signal.

I've tried hooking the servo up on the 5v pin instead of the battery pack, but that didn't work??!!

I'm getting a voltmeter tomorrow to ensure that all my connections check out, but I thought it would be a good idea to post my code and ensure that I'm not missing something! Any feedback would be greatly appreciated.

Example sketch for SparkFun's Reed Switch
Jim Lindblom @ SparkFun Electronics
May 3, 2016

The reed switch is a two-terminal, magnetically-actuated, normally-open switch.
Connect one end of the switch to ground, and the other to Arduino's D2 pin.

The D2 pin's internal pull-up resistor is used to bias the pin high. When the
switch closes, the pin should go low.

Development environment specifics:
Arduino 1.6.7
const int REED_PIN = 2; // Pin connected to reed switch
const int LED_PIN = 13; // LED pin - active-high

#include <Servo.h>
Servo myservo;  // create servo object to control a servo

void setup() 
  // Since the other end of the reed switch is connected to ground, we need
  // to pull-up the reed switch pin internally.
  pinMode(LED_PIN, OUTPUT);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object

void loop() 
  int proximity = digitalRead(REED_PIN); // Read the state of the switch
  if (proximity == LOW) // If the pin reads low, the switch is closed.
    //Serial.println("Switch closed");
    //digitalWrite(LED_PIN, HIGH); // Turn the LED on
    myservo.write(135);                 // rotate clockwise full speed
    myservo.write(90);// stop
    digitalWrite(LED_PIN, LOW); // Turn the LED off

image link

Forget to mention...I have turned off some of the pin 13 code as I this was for early testing purposes and was working fine. I'll probably turn it back on again to very the on signal is getting through and at least rule that out!

What happens if you bypass your reed switch with a piece of wire?

Connect the wires to that sort of switch in your image to diagonally opposed terminals, rather than same side terminal pins.

Can you post a picture of your project so we can see you component layout?

Tom.. :slight_smile:

@JamesBrede yes, uncomment those other lines of code. The first thing you need to establish is if the problem is with the reed switch Vs the servo.


Tom, the OP said that in reality, that button is a reed switch, so will probably have only two leads.

I've had to use a standard hobby servo and push button in tinkercad

Tom... :slight_smile: :o :slight_smile:

Your servo wiring colours are correct, red +Ve, brown ground, orange signal. I'd do a write(90) in setup just before the attach so you know the initial state of the servo.

Direct power connection to the servo is more or less essential. On initial startup that servo/motor is likely to draw over 2A for a short time. Connecting through a breadboard is a bad idea and drawing that sort of current from the Arduino 5V pin is even worse.

What "battery pack" are you using? For relatively high currents rechargeable batteries are usually best.


Based on the image you drawn... it would be helpful if the Arduino also receives power.

Why is there a diode between the battery + and the servo?

Hi everyone.

Really sorry I haven't replied to your comments. My 3 year old has been sick and I've not been able to get online until now. Thankfully he's running around like a lunatic again so back to full health.

I'm pleased to say that after using a voltmeter, it was obvious the breadboard was the culprit. I've cut out the breadboard and everything works perfectly ; )

In answer to some of the questions above...

I will definitely use an external power supply, but for quick testing to confirm the concept works, the 5v pin sufficed.

The diode in the diagram was due to the servo on tinkercad being set to 5v max. Oddly, 3 batteries wasn't enough juice whilst 4 produced an amusing simulated explosion. The diode just brought it down to safe operating levels. Annoyed the hell out of me for ages!

Thanks again for your help and I'm sure I will be posting again in the future.

Kind regards,