Need help with some Radar System code

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.

servo_9 seems to be an object of type Servo.

If you look at example code for the Servo library, you'll see what it should look like.

Similarly, the other missing functions/objects.

You're waving the servo around, but doing nothing with it, it seems.

What would be the other missing functions and objects?

Would you be able to provide a list so i can go down the list to make sure i have looked at everything please.

The compiler already provided you with a list.

Hello, do yourself a favour and please read How to get the best out of this forum and modify your first post accordingly (including code tags).

What do you mean i am 'weaving the servo around?'

No, not "weaving", "waving".

You're sweeping the servo left and right (or up and down), but not doing anything while it is moving.

Maybe you intended taking range readings during the sweep.

I guess i want that but i am not sure.

Which element of that code would need to be changed in my code?

It depends what you want to do - the intent isn't clear from the comments.

Does any of the above edits that i have made to the post help? (Sorry for sounding so blunt)

You haven't said anything about what you want the code to do.

Just done the changed that you have asked for. I order for you and everyone else to have greater clarity (i am not being sarcastic).

OK, that works both ways - what is the servo for?

(As a noob, you will have a limited number of posts before the forum software slows your post rate down, so it is vitally important (for you) to provide as much information as possible, in as few posts as possible)

I am guessing the servo is to power the ultrasonic sensor

Please post the actual text of the assignment. or provide a link to it.

Explain , in detail, what it is you are trying to build, what funtionality it should have.

c) Radar System

a. Ultrasonic Sensor

b. Servo Motor

c. Buzzer

Table of contents

1. Introduction

A short, informal description of the product, its applications and an indication of the extent to which it has been implemented and any problems faced in its development

2. Design of system

Discussion and reflection on the design and development of the product, showing the structure of the system and identifying appropriate components.

Discussion of implementation logic, use code snippets, diagrams and screenshots where needed.

3. Testing the system

A set of test suite to be submitted.

A discussion on failed tests and how much of your code you think your tests cover. Do they cover every aspect?

Hi; @ldutchman
Welcome to the forum.

Have you written your code in stages?
Have you got code that JUST makes the servo sweep?
Have you got code that JUST operates the sonar unit and measures distance?
Have you got code that JUST makes the BEEPER "beep"?

Before putting all yours codes together, make sure each works.
This way you will have proven your code and hardware, combining your codes, one at a time will then have less bugs and be relatively easy to fix them.

Writing all your code then trying to compile, will give you all sorts of problems.
Where as each smaller bit of code, if it won't compile will only be a much smaller block of code to degug.

Tom... :grinning: :+1: :coffee: :australia:

I'm out LIAR!

Maybe it's a very formal friendship.