Hello I am trying to control a servo via bluetooth module but the servo rotates very fast and I want to slow it down, I use this basic code but its not working can anyone please help
The only thing in there that has anything to do with the speed at which the servo moves, is the delay(15).
So make the delay() longer.
What do you mean it's not working? You would only be able to say that if you had two speeds, one for G and one for H say, and it runs at the same speed in spite of them having different delay()s.
With that exact code the servo will take about 3 seconds to go from one end of its travel to the other. How slow do you want it to go?
Maybe you're not using it correctly in your real code so please post that.
OTOH I would use VarSpeedServo instead of the standard Servo library because that has a Speed parameter in the write(). Saves a fair bit code, no for loops needed.
As someone already pointed out, the only way to make the servo go slower is to increase the delay.
You are:
Checking to see if one or more characters are available from the serial port.
Waiting (for some reason that baffles me) 50mS
Reading one character
Appending it to the String
Printing the String to the serial port
Checking to see if the String contains "G"
If it does, you run the servo using a delay of 15mS.
You go back and do the same thing all over again.
Note that the servo will only do one sweep, since the String will only contain "G" if it's the first character you recieve on the serial port. If you send another 'G', the String will now contain "GG".
It almost sounds like you want to control the speed with characters from the serial port. If that's the case, you will need to use the recieved data to change your delay.
HizonPastor:
This is the whole sample code I wanna slow down two servo at the same time by using this code
So the first thing to do is to add a second servo. You can't slow down two servos if your program only controls one servo.
Then you need to say what it is that you expect to slow the servo down. So far you are only looking for a "G" from Serial. And you don't do anything useful with that. So what speed should the servos go at and how are you going to tell them the speed you want?