please help with my project since i do not want to fail

int DO = 6; //Pin for Digital Output - DO
int DA = A0; // Pin for Analog Output - AO
int threshold = 12; //Set minimum threshold for LED lit
int sensorvalue = 0;
int duration = 11;
int trig = 12;

#include <Servo.h>

Servo lock; // create servo object to control a servo
Servo gate; // a maximum of eight servo objects can be created

void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT);
lock.attach(6); // attaches the servo on pin 9 to the servo object
gate.attach(8);
Serial.begin(9600);
pinMode(12, OUTPUT);
pinMode(11, INPUT);
}

void loop()
{
sensorvalue = analogRead(DA); //Read the analog value
Serial.print("Analog: ");
Serial.print(sensorvalue); //Print the analog value
Serial.print(" ");
Serial.print("Digital: ");
Serial.println(digitalRead(DO)); //Print the digital value

if (sensorvalue >= threshold){ //Compare analog value with threshold
lock.write(0); //unlocked angle
delay(1500);
gate.write(90); //open angle
delay(10000);

gate.write(0); //closed angle
delay(2000);
lock.write(90);
delay(1500); //locked angle
long duration, inches;
}

if (trig < 17){
}

digitalWrite(12, LOW);
delayMicroseconds (2);
digitalWrite(12, HIGH);
delayMicroseconds(5);
digitalWrite(12, LOW);
duration = pulseIn (11, HIGH);
duration = inches / 74 / 2;

Serial.print("in ");
Serial.println();
}

This is my project. the point of this is that if the decibels are above 12, the servo will unlock, and if less than 17 inches on an ping))) then it will not open. It keeps on saying that inches are not declared. Please help me with this since i dont want to fail. Preferably give me instructions on what to do for my whole project (i only have 3 left)

It keeps on saying that inches are not declared.

It's quite correct, in fact, it goes further, and gives you a clue, but you didn't post that bit of the error message.

What happened to the code tags?

Failing is learning. Don't be afraid of it.

You have started by failing to read the How to Use This Forum.

...R

Sorry its just kind of urgent, and it continues to say inches is not declared

pbjmaster:
Sorry its just kind of urgent,

So read the how to use the forum sticky quickly.

and it continues to say inches is not declared

It will until you do something about it like declaring it.

first i read the forum, and my line for inches is

inches = duration / 74 / 2;

why does it say that i did not declare it?

first i read the forum

But you didn't read the guidelines, or thought they didn't apply to you?

why does it say that i did not declare it?

Read the error message again. As I said, it gives a clue

And, you didn't say 'inches = duration / 74 /2 ;'

Slow down and do as you are told. If you want help from these guys, you gotta follow the rules and show that you are willing to help yourself......

first i read the forum,

Then modify that first post and post the code correctly if you want to prove it.

why does it say that i did not declare it?

Because that is not a variable declaration is it?

You have other variables you have declared successfully haven't you?

Your Arduino was made in Italy. It doesn't understand inches.... :slight_smile: :slight_smile: :slight_smile: :slight_smile:

I'll just add you shouldn't be afraid to fail. I've found I always learn more and better from my failures then from my successes.

by fail i mean fail a high school class

pbjmaster:
by fail i mean fail a high school class

Keep in mind that you are one who may or may not fail as such you should do what others have asked of you instead of ignoring them. You need to do something to pass the course we do not.

Look up what it means to declare a variable in C, Google is your friend.

im building a baby gate in class. The idea is that a clap or snap that is higher than 20 decibels will turn it on. But if there is something in front of the ultrasonic sensor within 20 inches, the gate will not open. There is one servo to open/lock our lock, and one to open/close the gate. The sensors wont work, so can someone tell me how to fix my code.?

int threshold = 13; //Set minimum threshold for LED lit
int sensorvalue = 0;

long duration, inches;

#include <Servo.h>
Servo lock; // create servo object to control a servo
Servo gate; // a maximum of eight servo objects can be created

void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT);
lock.attach(6); // attaches the servo on pin 9 to the servo object
gate.attach(8);
pinMode(12, OUTPUT);
pinMode(11, INPUT);
}

void loop()
{

gate.write(90); // alosed and locked angles
lock.write(90);

sensorvalue = analogRead(A0); //Read the analog value
Serial.print("Analog: ");
Serial.println(sensorvalue); //Print the analog value
//Serial.print(" ");
//Serial.print("Digital: ");
//Serial.println(digitalRead(DO)); //Print the digital value

digitalWrite(12, LOW);

delayMicroseconds(2);

digitalWrite(12, HIGH);

delayMicroseconds(5);

digitalWrite(12, LOW);
duration = pulseIn(11, HIGH); // measure the time of flight of sound wave
inches = duration / 74 / 2; // 1130 ft/s * 12in/ft * 1s/1,000,000us = 74 // factor of 2 since sound travels out and back
Serial.print(inches);
Serial.println(" inches");

if ((sensorvalue >= threshold) && (inches < 20))
{
lock.write(0); //unlocked angle
delay(1500);
gate.write(90); //open angle
delay(10000);
gate.write(0); //closed angle
delay(2000);
lock.write(90);
delay(1500); //locked angle
}

}

The sensors wont work, so can someone tell me how to fix my code.?

Perhaps the mysterious sensors just need a good motivational speech. If you expect us to help, you need to tell us something about the sensors, AND show your serial output.

I don't think I've ever seen a servo attached to the smiley face pin. Perhaps that pin doesn't support a servo.

pbjmaster:
by fail i mean fail a high school class

Read #7 below for a better start with your questions.

http://forum.arduino.cc/index.php/topic,148850.0.html