When I run the attached program the monitor prints gibberish (as shown at the bottom of the program).
The program did run correctly prior to installing a bluetooth module (which was disconnected for this demo).
Thanks for any help.
Ed
// Servo_angle-Ping_1
#include <Servo.h>
#include <NewPing.h>#define TRIGGER_PIN 12
#define ECHO_PIN 11
#define MAX_DISTANCE 200NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
Servo myservo;
int n = 0; // variable to store servo position
String readString;
void setup()
{
myservo.attach(5); // attaches servo on pin 5
myservo.write(90);
delay(200);// initalize the serial communication:
Serial.begin(57600);
Serial.flush();
Serial.println(“Servo Angle”);
}
void loop()
{
for(n = 45; n < 135; n += 1)
{
Serial.println(n);
myservo.write(n);
delay(100);
unsigned int uS = sonar.ping();
Serial.print("Ping: ");
Serial.print(uS / US_ROUNDTRIP_CM);
Serial.println(“cm”);
}for(n = 135; n >= 45; n -= 1)
{
Serial.println(n);
myservo.write(n);
delay(100);
unsigned int uS = sonar.ping();
Serial.print("Ping: ");
Serial.print(uS / US_ROUNDTRIP_CM);
Serial.println(“cm”);
}}
monitor displays:
¹%yaþx(çy©ðy)ÿy)òx(øyþx(ÿx(ÿzÿx(þy¼þy)òy)ÿy)òx(ùy