I am using the serial monitor to give me data from sensors. I want my servo motor to move based on those numbers. What code should I use?
Code based on the examples in the IDE?
What am I doing wrong?
You're posting code with colour tags.
Don't do that - just paste your code inside code tags.
Edit: And now you've deleted your post.
This is what I have so far. I keep getting error messages. What am I doing wrong?
#include <Servo.h>
#include <SoftwareSerial.h>
Servo myservo; // create servo object to control a servo
void setup() {
// put your setup code here, to run once:
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.read(> 150) {
myservo.write(68);
}
if (Serial.read(> 135 gap && gap < 150) {
myservo.write(136);
}
if (Serial.read(> 120 gap && gap < 135) {
myservo.write(204);
}
if (Serial.read(< 120); {
myservo.write(270);
}a
}
if (Serial.read(> 150) {What's that?
(The compiler already asked you that, just in a different way)
I suggest you junk all that code, and have a look at Robin2's serial handling basics tutorial.
I'm expecting the serial monitor to print numbers greater than 150 from sensors. When those numbers appear, I want the servo to move to the specified position.
That's a useful working specification, but I suggest you read and act on what I wrote in reply #4.