I have got problems with the eletrical part of my project...

I have got a project of doing a dorlock controlled by a pusshbutton and a servo motor.
But while I was doing it I saw some problems that I do not know how to solve:

1- My code looks fine in the simulations that I have done in the internet but in real life… It just does not work. Could you guys give it a look to see if there is any kind of mistake on it?

2- In the simulations the servo motor reacted just fine to the push button comands but actually when I tried in the board it started spinning madly and I think it is some kind of problem in to the eletrical part of the project, not in the code.

Could any body help me please?

Servo servo_3;

void setup()
pinMode(2, INPUT);


void loop()
while (!(digitalRead(2) == LOW)) {
while (digitalRead(2) == HIGH) {
delay(10); // Delay a little bit to improve simulation performance

*Diagram and photo atachhed

while (!(digitalRead(2) == LOW)) {

Why the not (!)?

started spinning madly

Are you sure the servo is a regular servo and not a "continuous" servo. A regular servo would go to one end of travel and hit an end stop.

Read “How To Use This Forum”

This is what happens when you do not


Servo servo_3;

not seeing:

#include <Servo.h>

There are very few proper uses of a while loop for an Arduino - they are blocking and make your program less responsive. This is an improper use. Use if statements instead.

Also, before posting code, do some formatting (the autoformat function of the IDE does a great job). Makes it more readable. Then make sure to add code tags (or use the "copy for forum" option of the IDE), makes it even more readable. Making sure your code compiles before posting (the lack of a Servo.h include means it doesn't) is also a good practice.