Hello, this is my first time here and i was wondering if anyone can help. You see i am currently building a project for my programming assignment for university and i am bit lost of how to fix it and have contacted my lecture, former programming tutor and various other people that my mum and dad have said that could help. But none to avail. This isn't the area i want to go in for a job and its just one of those things i need to do in order to avoid getting a reassessment if i don't get above a certain grade. I have written it but i am currently experiencing a myriad of errors in being able to execute it. I am using a Uno R3 board, breadboard, Piezo, Ultrasonic Distance Sensor and Micro Servo in the positional type. It needs to be sorted today as i will be showing him this evening. I want the circuit to do is being able to detect objects within in its vicinity when the Ultrasonic sensor is active. But when the object is out of its line of sight the buzzer should be activated and sound to alert the user that there is nothing in front of it and when it is active. Anyway here is the code, errors i have been experiencing and the image of the circuit i have built :
#include <Servo.h>
int pos = 0;
const int buzzer = 9; //buzzer to arduino pin 9
const int pingPin = 7; // Trigger Pin of Ultrasonic Sensor
const int echoPin = 6; // Echo Pin of Ultrasonic Sensor
const int servo = 9;
void setup()
{
pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output
pinMode(13, OUTPUT);
pinMode(12, INPUT);
servo_9.attach(9, 500, 2500);
srv.attach(7);
Serial.begin(9600); // Starting Serial Terminal
}
void loop()
{
// sweep the servo from 0 to 180 degrees in steps
// of 1 degrees
for (pos = 0; pos <= 180; pos += 1) {
// tell servo to go to position in variable 'pos'
servo_9.write(pos);
// wait 15 ms for servo to reach the position
delay(15); // Wait for 15 millisecond(s)
}
for (pos = 180; pos >= 0; pos -= 1) {
// tell servo to go to position in variable 'pos'
servo_9.write(pos);
// wait 15 ms for servo to reach the position
delay(15); // Wait for 15 millisecond(s)
}
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(1000); // ...for 1sec
long duration, inches, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
{
digitalWrite(13, LOW);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(13, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(13, LOW);
int d=pulseIn(12,HIGH);
d=d/29/2; Serial.println(d);
if(d<=maxdistance) { srv.write(90); delay(1000); } else { delay(1000); srv.write(0);
}
Errors:
In function 'void setup()': 16:3: error: 'servo_9' was not declared in this scope 16:3: note: suggested alternative: 'servo_t' 17:3: error: 'srv' was not declared in this scope 17:3: note: suggested alternative: 'servo' In function 'void loop()': 26:5: error: 'servo_9' was not declared in this scope 26:5: note: suggested alternative: 'servo_t' 32:5: error: 'servo_9' was not declared in this scope 32:5: note: suggested alternative: 'servo_t' 49:13: error: 'microsecondsToInches' was not declared in this scope 49:13: note: suggested alternative: 'microsecondsToClockCycles' 50:9: error: 'microsecondsToCentimeters' was not declared in this scope 50:9: note: suggested alternative: 'microsecondsToClockCycles' 65:7: error: 'maxdistance' was not declared in this scope 65:22: error: 'srv' was not declared in this scope 65:22: note: suggested alternative: 'servo' 65:72: error: 'srv' was not declared in this scope 65:72: note: suggested alternative: 'servo' 66:1: error: expected '}' at end of input 66:1: error: expected '}' at end of input exit status 1
Thank you for any help you can provide.
