system
February 27, 2013, 12:08pm
1
i have a problem whith coding!
i start make a security system
and i have a problem to codes!!
const int sensor1Pin = A1; //|---------|
const int sensor2Pin = A2; //|sensors |
const int sensor3Pin = A3; //|pins |
const int sensor4Pin = A4; //|_________|
const int lockPin = A0; //lock pin
const int alertPin = 8; //allert pin
const int indicatorPin = 13; //lock indicator
void setup () {
pinMode(sensor1Pin, INPUT);
pinMode(sensor2Pin, INPUT);
pinMode(sensor3Pin, INPUT);
pinMode(sensor4Pin, INPUT);
pinMode(lockPin, INPUT);
}
void loop () {
if (sensor1Pin, HIGH);
(sensor2Pin, HIGH);
(sensor3Pin, HIGH);
(sensor4Pin, HIGH);
{
digitalWrite(alertPin, LOW);
}else{
digitalWrite(alertPin, HIGH);
}
}
this is the code
and when i press the verify
it tells me an error
alarm.ino: In function 'void loop()':
alarm:25: error: 'else' without a previous 'if'
what i do wrong?PLEASE HELP ME!
system
February 27, 2013, 12:17pm
2
if (sensor1Pin, HIGH);
(sensor2Pin, HIGH);
(sensor3Pin, HIGH);
(sensor4Pin, HIGH);
{
digitalWrite(alertPin, LOW);
}else{
digitalWrite(alertPin, HIGH);
}
Ifyouquitjammingeverythingtogether, and always used curly braces after the if statements, you'd see that your code looked like:
if(sensor1Pin, HIGH);
{
(sensor2Pin, HIGH);
(sensor3Pin, HIGH);
(sensor4Pin, HIGH);
}
{
digitalWrite(alertPin, LOW);
}
else
{
digitalWrite(alertPin, HIGH);
}
And, of course, you can see that that is crap.
if statements do NOT end with a semicolon. The comma operator is being misused. The three statements in the if block don't make any sense.
Guessing at what you're trying to do, you will need to take a look at digitalRead. You appear to be making the common assumption that the Sensorpin variable holds the state of the pin. It doesn't. Also, look at the comparison operator == .Try getting it to work with one sensor only to start with.
holmes4
February 27, 2013, 12:41pm
4
Use the auto format option of the IDE. It shows up miss {}, and it helps shows you the real flow of logic in your program.
Mark
system
February 27, 2013, 2:04pm
5
i have 4 sensors
i mean this code:
"if one of the sensors stop sending votalge
then alert me else dont alert me"
to arduino code.
system
February 27, 2013, 2:07pm
6
i mean this code:
"if one of the sensors stop sending votalge
then alert me else dont alert me"
Are the sensors analog sensors or digital sensors?
system
February 27, 2013, 2:23pm
8
if(analogRead(sensor1Pin) < threshold ||
analogRead(sensor2Pin) < threshold ||
analogRead(sensor3Pin) < threshold ||
analogRead(sensor4Pin) < threshold)
{
// Low voltage on one of the pins
}
else
{
// All the pins are seeing some voltage
}
system
February 27, 2013, 2:34pm
9
yes i mean this
but it still showing this problem:
alarm.ino: In function 'void loop()':
alarm:26: error: 'else' without a previous 'if'
Arrch
February 27, 2013, 3:27pm
10
xitosman:
yes i mean this
but it still showing this problem:
alarm.ino: In function 'void loop()':
alarm:26: error: 'else' without a previous 'if'
So you've made modifications to the code. The new code now has a new error, but you're not going to show us the new code?