To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum
Your code is too long for me to study quickly without copying to a text editor.
Also please use the AutoFormat tool to indent your code for easier reading.
It sounds as if you are using a continuous rotation servo - is that correct? Have you figured out what value for Servo.write() or Servo.writeMicroseconds() is necessary to make the motor stop?
It will be close to 90deg or 1500 microsecs but it will vary slightly for different servos.
That code is a bit of a mess. You include SPI.h and then never use SPI. You set pinMode() for pin 6 to output and then never use pin 6.
And it's very odd doing an analogRead() and then only checking the result for zero and not zero. If you have a digital sensor you should be using digitalRead() and if it's an analog sensor the output will almost never be exactly zero.
So basics...exactly what "water sensor" and "servo motor" are you using and what is the program supposed to be doing with them?
void serm(int count) // this bit does ....
{
if (count != 0) // count is set to 1 in order to reach this point
{
int pos = 45;
digitalWrite(9, LOW);
ser1(pos, count);
delay(500);
}
else
{
delay(1000);
}
return;
}
slipstick:
That code is a bit of a mess. You include SPI.h and then never use SPI. You set pinMode() for pin 6 to output and then never use pin 6.
And it's very odd doing an analogRead() and then only checking the result for zero and not zero. If you have a digital sensor you should be using digitalRead() and if it's an analog sensor the output will almost never be exactly zero.
So basics...exactly what "water sensor" and "servo motor" are you using and what is the program supposed to be doing with them?
Steve
Um actually I made this template for something else, but changed it mid way, so didn't really check the header files, also the water sensor is an analog type and I have a habit of checking stuff midway, if they're working or not, so this isn't the complete sketch.... sorry about that.
About the analog and digital read, something is wrong with my sensor module, the reading doesn't go beyond 330 for what-so-ever reason. That's why I tried taking the value as non- zero.
Your code is too long for me to study quickly without copying to a text editor.
Also please use the AutoFormat tool to indent your code for easier reading.
It sounds as if you are using a continuous rotation servo - is that correct? Have you figured out what value for Servo.write() or Servo.writeMicroseconds() is necessary to make the motor stop?
It will be close to 90deg or 1500 microsecs but it will vary slightly for different servos.
...R
Sorry for the trouble Robin.
Yes, I'm having a continuous rotation problem, and when I tried debugging, its struck in this line
if (count != 0) // count is set to 1 in order to reach this point
{
int pos = 45;
digitalWrite(9, LOW);
ser1(pos, count);
delay(500);
}
else
{
delay(1000);
}
return;
}
Sorry for the trouble, i'll keep that in mind
And as of now, I'm not with my arduino, so once I'm back, ill do it.
Yes, I'm having a continuous rotation problem, and when I tried debugging, its struck in this line
Serial.println("servo--");
So, where did I go wrong?
you closed the bracket for
void ser1(int pos, int count) {
and then started with a new } bracket that has no starting bracket
your other mistake is that you did not post the error message you got when trying to validate your sketch.
dave-in-nj:
you closed the bracket for
void ser1(int pos, int count) {
and then started with a new } bracket that has no starting bracket
your other mistake is that you did not post the error message you got when trying to validate your sketch.
Hello, I'm not sure where you're pointing, like i checked the whole ser1() function, as all the braces are properly opened and closed. And about the error message, I never got one so i didn't post it.