Newbie question

Okay apologies but I’m a complete beginner I bought the arduino project book and am already stuck I just cannot work out whats wrong with the code in projects 2 and 3 your expertise would be greatly appreciated thank you :confused:

Project 2

int switchState = 0;

void setup() {
pinMode (3,OUTPUT);
pinMode (4,OUTPUT);
pinMode (5,OUTPUT);
pinMode (2,INPUT);
}
void loop() {
switchState = digitalRead(2);
if (switchState == LOW {
// the button is not pressed
digitalWrite (3,HIGH); //yellow LED
digitalWrite (4,LOW); //green LED
digitalWrite (5,HIGH); //red LED
}
else { //Button is pressed
digitalWrite (3,LOW); //yellow LED
digitalWrite (4,LOW); //green LED
digitalWrite (5,HIGH); //red LED
delay(250);
//hold LED pattern 250 (circa 1/4 second)
//now toggle the lights

digitalWrite (4,HIGH); //green LED
digitalWrite (5,LOW); //red LED
delay(250); //hold LED pattern 250 (circa 1/4 second)
}
}
//loopback to start

Error Messages

Arduino: 1.7.6 (Mac OS X), Board: “Arduino Uno”

Build options changed, rebuilding all
LLprogresspg.ino: In function ‘void loop()’:
LLprogresspg.ino:11:25: error: expected ‘)’ before ‘{’ token
LLprogresspg.ino:29:1: error: expected primary-expression before ‘}’ token
LLprogresspg.ino:29:1: error: expected ‘;’ before ‘}’ token
Error compiling.

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.

Project 3

const int sensorPin = A0;
const float baselineTemp = 20.0;
void setup() {
Serial.begin(9600); // open the serial point
for(int pinNumber = 2; pinNumber<5;pinNumber++){
pinMode(pinNumber,OUTPUT);
digitalWrite(pinNumber,LOW);
}
}
void loop() {
int sensorVal = analogRead(sensorPin);
Serial.print("Sensor Value: “);
Serial.print(sensor.Val);
// convert sensor reading to a voltage
float voltage = (sensorVal/1024.0) * 5.0;
Serial.print(”, Volts: “);
Serial.print(voltage);
Serial.print(”, degrees C: ")
//convert the voltage to temperature in degrees
float temperature = (voltage - .5) * 100;
Serial.print(temperature);
if temperature < baselineTemp){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}else if(temperature >= baselineTemp+2 &&
temperature < baselineTemp+4){
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}else if(temperature >= baselineTemp+4 &&
temperature < baselineTemp+6){
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}else if(temperature >= baselineTemp+6 &&
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
delay(1);
}

Error message

Arduino: 1.7.6 (Mac OS X), Board: “Arduino Uno”

loveometer.ino: In function ‘void loop()’:
loveometer.ino:13:16: error: ‘sensor’ was not declared in this scope
loveometer.ino:20:3: error: expected ‘;’ before ‘float’
loveometer.ino:21:16: error: ‘temperature’ was not declared in this scope
loveometer.ino:22:6: error: expected ‘(’ before ‘temperature’
loveometer.ino:26:4: error: ‘else’ without a previous ‘if’
loveometer.ino:37:26: error: expected ‘)’ before ‘;’ token
loveometer.ino: At global scope:
loveometer.ino:41:8: error: expected constructor, destructor, or type conversion before ‘(’ token
loveometer.ino:42:1: error: expected declaration before ‘}’ token
Error compiling.

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.

Take this line for instance.

LLprogresspg.ino:11:25: error: expected ‘)’ before ‘{’ token

On line 11, 25th character, an error occurs. The compiler expected a ‘)’ before ‘}’ but did not see one.

If we count down 11 lines we get

if (switchState == LOW {

25 over you can see the ‘{’ character over there.

So what is missing? a ‘)’ bracket.

It is missing from (switchState == LOW)

since all brackets need to be closed.

Try looking at the other error messages and seeing if you can spot what it wants you to change.

In project 3 you shouldn't have a period between sensor and Val, It should be sensorVal not sensor.Val

Serial.print(sensorVal);

You have several other parentheses errors in project 3 that I'll let you find on your own.

Please put your code in its own window as seen in other posts. This can be done by placing     [code]  and [/code]  around the code or use the </> icon. This makes it easier for others to read.

How to use this forum

Weedpharma

It can be confusing for a newcomer. Try to get familiar with the programming language. When you get a compile error message, try to determine which line it is telling you has a problem, then review that line in detail.

There is a "display line numbers" tickbox in "File > Preferences". Leo..

Thanks for the help and tips guys and not just telling me (wheres the fun in that) going to give i another go tonight :)

all fixed thanks again ;)