I am trying to make sevo motor move by pulse sensor using the code below.
The led light works but the servo motor does not work, I think I did something wrong with batteries on the board but don't know what. What seems wrong?
Please post your sketch, using code tags when you do
Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination
In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.
9V "box" battery through voltage regulator might not be sufficient power (current) supply for your servo. Feel free to post specs of your servo to have more precise opinions.
But voltage is only half the story. It also likely takes at least 650mA of current every time it tries to start moving. Possibly more. A full amp would not be out of the question.
Your PP3 9V battery is designed to supply roughly 15mA on a constant basis.
Your Arduino alone will be asking it to supply 45mA.
The LED, another 20mA.
And if that TO-220 package is a 78xx regulator, it will want another 5-8mA.
Quite simply, you have the wrong battery for the job. It's designed for smoke alarms and old fashioned transistor radios. Low current applications. Not for things like servos that need a lot of current on demand.
I followed the baisc library example pulse sensor tutorial provided for using it with servo motor and the prototype had 9v battery. Do I need to change it to bigger one then?
5 x AA battery in series through 5V voltage regulator would be better choice. Datasheet of that servo gives 800mA stall current and 250mA no load current.
If you are powering arduino separately from USB or power plug, better option is to power just servo directly with 4 x AA (6V) and skip the voltage regulator. Common GND of course.