Ok, so I'm not quit sure what's wrong here...
If someone could point out all my errors
int normalDistance = 200;
boolean triggered = false;
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(piezoPin, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
void setup()
{
Serial.begin (9600);
long duration, distance;
digitalWrite(redLed, HIGH);
digitalWrite(greenPin);
digitalWrite(piezoPin, HIGH);
while(millis() < 5000) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;
if (distance < normalDistance) {
}
}
digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW);
digitalWrite(greenPin, LOW);
}
void loop() {
if (triggered) {
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW;
tone(piezoPin, 635);
delay(500);
digitalWrite(redLed, LOW);
digitalWrite(green, HIGH);
tone(piezoPin, 912);
delay(500);
} else {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < normalDistance - 10) {
trigggered = true;
}
delay(20);
}
}
The pinMode statements belong in setup(). You can't use variables until after they are declared. The pins need numbers, too (const byte echoPin = 3). That is a start. In the future, please include the full text of the error message(s).
Kudos for using code tags on your first post.
There are a lot of other errors. You have a greenLed variable then use greenPin or green.
digitalWrite(greenPin);
Is there something missing there?
int normalDistance = 200;
boolean triggered = false;
void setup()
{
Serial.begin (9600);
pinMode(trigPin, OUTPUT) = 13;
pinMode (echoPin, INPUT) = 12;
pinMode(piezoPin, OUTPUT) = 11;
pinMode(redLed, OUTPUT) = 10;
pinMode(greenLed, OUTPUT) = 8;
long duration, distance;
digitalWrite(redLed, HIGH);
digitalWrite(greenPin);
digitalWrite(piezoPin, HIGH);
while(millis() < 5000) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;
if (distance < normalDistance) {
}
}
digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW);
digitalWrite(greenPin, LOW);
}
void loop() {
if (triggered) {
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW;
tone(piezoPin, 635);
delay(500);
digitalWrite(redLed, LOW);
digitalWrite(green, HIGH);
tone(piezoPin, 912);
delay(500);
} else {
long duration, distance;
digitalWrite( trigPin, LOW);
delayMicroseconds(2);
digitalWrite( trigPin, HIGH
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < normalDistance - 10) {
trigggered = true;
}
delay(20);
}
}
Hey I applied what you said in to the code. But there are still some errors
exit status 1
'trigPin' was not declared in this scope
You must declare a variable before you use it so the compiler knows how much memory to set aside. In the case of variables that name pins, a pin number needs to be assigned. Put the declaration and initialization in the space above setup(), like so, for all of your variables.
const byte trigPin = 13; // or the pin number of your choice
pinMode(trigPin, OUTPUT) = 13;
Is just wrong. You can't make up your own syntax. Here for setting up pins.
There are still a lot of errors related to using variable that are not declared (grren, greenLed) and missing parameters from function calls. Add to that list missing punctuation and typos.
Like this????
//trigPin 13
//define echoPin 12
//define redLed 11
//define blueLed 10
//define piezoPin 8
int normalDistance = 200;
boolean triggered = false;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(redLed, OUTPUT);
pinMode(blueLed, OUTPUT);
pinMode(piezoPin, OUTPUT);
long duration, distance;
digitalWrite(redLed, HIGH); // to indicate that the calibration is in process
digitalWrite(blueLed, HIGH);
digitalWrite(piezoPin, HIGH);
while (millis() < 5000) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;
if (distance < normalDistance) {
normalDistance = distance;
}
}
digitalWrite(redLed, LOW); // finish calibration
digitalWrite(blueLed, LOW);
digitalWrite(piezoPin, LOW);
}
void loop() {
if (triggered) {
digitalWrite(redLed, HIGH);
digitalWrite(blueLed, LOW);
tone(piezoPin, 635);
delay(500);
digitalWrite(redLed, LOW);
digitalWrite(blueLed, HIGH);
tone(piezoPin, 912);
delay(500);
} else {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < normalDistance - 10) {
triggered = true;
}
delay(20);
}
}
//trigPin 13
//define echoPin 12
//define redLed 11
//define blueLed 10
//define piezoPin 8
Not even close.
const byte trigPin = 13;
const byte echoPin = 12;
const byte piezoPin = 8;
const byte redLed = 11;
const byte blueLed = 10;
Is how to declare and initialize pin variables. Or you can use #define , but look up the syntax before you do.
Fix the pin declarations like I showed and the code will compile. Good job fixing the variable, typo and punctuation problems.
I feel suuuper stupid right now!
Save me!
int trigPin 13
int echoPin 12
int redLed 11
int blueLed 10
int piezoPin 8
int normalDistance = 200;
boolean triggered = false;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(redLed, OUTPUT);
pinMode(blueLed, OUTPUT);
pinMode(piezoPin, OUTPUT);
long duration, distance;
digitalWrite(redLed, HIGH); // to indicate that the calibration is in process
digitalWrite(blueLed, HIGH);
digitalWrite(piezoPin, HIGH);
while (millis() < 5000) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;
if (distance < normalDistance) {
normalDistance = distance;
}
}
digitalWrite(redLed, LOW); // finish calibration
digitalWrite(blueLed, LOW);
digitalWrite(piezoPin, LOW);
}
void loop() {
if (triggered) {
digitalWrite(redLed, HIGH);
digitalWrite(blueLed, LOW);
tone(piezoPin, 635);
delay(500);
digitalWrite(redLed, LOW);
digitalWrite(blueLed, HIGH);
tone(piezoPin, 912);
delay(500);
} else {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < normalDistance - 10) {
triggered = true;
}
delay(20);
}
}
exit status 1
expected initializer before numeric constant
system
September 13, 2017, 4:14pm
8
int trigPin 13
int echoPin 12
int redLed 11
int blueLed 10
int piezoPin 8
Semicolons.
Assignments.
const byte trigPin = 13;
const byte echoPin = 12;
const byte piezoPin = 8;
const byte redLed = 11;
const byte blueLed = 10;
int normalDistance = 200;
boolean triggered = false;
I showed how to declare and initialize the pins in reply #5 .
I have some problems with getting my door alarm to work.
const byte trigPin 13;
const byte echoPin 12;
const byte redLed 11;
const byte greenLed 10;
1const byte piezoPin 8;
int normalDistance = 200;
boolean triggered = false;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(redLed, OUTPUT);
pinMode(blueLed, OUTPUT);
pinMode(piezoPin, OUTPUT);
long duration, distance;
digitalWrite(redLed, HIGH); // to indicate that the calibration is in process
digitalWrite(blueLed, HIGH);
digitalWrite(piezoPin, HIGH);
while (millis() < 5000) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;
if (distance < normalDistance) {
normalDistance = distance;
}
}
digitalWrite(redLed, LOW); // finish calibration
digitalWrite(blueLed, LOW);
digitalWrite(piezoPin, LOW);
}
void loop() {
if (triggered) {
digitalWrite(redLed, HIGH);
digitalWrite(blueLed, LOW);
tone(piezoPin, 635);
delay(500);
digitalWrite(redLed, LOW);
digitalWrite(blueLed, HIGH);
tone(piezoPin, 912);
delay(500);
} else {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < normalDistance - 10) {
triggered = true;
}
delay(20);
}
}
I get these errors:
exit status 1
expected initializer before numeric constant,
exit status 1
'trigPin' was not declared in this scope
Lines like this need an =
const byte trigPin 13; //wrong
const byte trigPin=13; //right
thank!
It works, but when i tried to upload it this happend
Problemer ved opplasting til kortet. Se http://www.arduino.cc/en/Guide/Troubleshooting#upload for forslag.
is this normal?
system
September 14, 2017, 9:03am
13
is this normal?
Yes, but starting THREE threads on the same topic isn't.
system
September 14, 2017, 9:22am
14
Se http://www.arduino.cc/en/Guide/Troubleshooting#upload for forslag.
Why didn't you? "Whine on the wrong part of the forum" is NOT one of the recommendations on that site.
Hi,
Is this associated with this
https://forum.arduino.cc/index.php?topic=499978.0
What Arduino board are you using and have you got the correct com port selected?
Tom...