I'm stuck with my first Sensor project! eep!

Hi everyone,

I have this sensor project that's due for school tomorrow but I am having issues with programming. I am very new to learning about Arduino and pretty much this is my first time working with it (just learned it last week in school).

This is what I'm having problems with it and if anyone see the error that I'm making please point it out to me (thanks in advance).

Ok so this is my sketch code on Arduino and it won't upload:

/* * LilyPad tutorial: sensing (sensors) * * Reads data from a LilyPad light sensor module * and then sends that data to the computer * so that you can see the sensor values */

int ledPin = 13; // LED is connected to digital pin 13 int sensorPin = 0; // light sensor is connected to analog pin 0 int sensorValue; // variable to store the value coming from the sensor

// this part i have added by looking at the make: projects getting started with arduino book page 44

define BUTTON 7 // the input pin where the

// pushbutton is connected int val = 0; // val will be used to store the state // of the input pin

// from page 44 arduino book^

void setup() { pinMode(ledPin, OUTPUT); // sets the ledPin to be an output Serial.begin(9600); //initialize the serial port digitalWrite(ledPin, 1); // turn the LED on } // this part is what i have added

{ // <---this part gets highlighted and the issue starts from here

pinMode (LED, OUTPUT); // tell Arduino LED is an output pinMode (BUTTON, INPUT); // and BUTTON is an input }

// from page 44 arduino book^

void loop() // run over and over again { sensorValue = analogRead(sensorPin); // read the value from the sensor Serial.println(sensorValue); // send that value to the computer delay(100); // delay for 1/10 of a second }

// command code below is what i have added from page 44

Val = digitalRead(BUTTON); // read input value and store it

// check whether the input is HIGH (button pressed) if (val == HIGH) { digitalWrite (LED, HIGH); // turn LED ON } else { digitalWrite (LED, LOW); } }

All code needs to be defined in a function.

void setup()      
[glow]{ // <-- The setup function starts here[/glow]
        pinMode(ledPin, OUTPUT);      // sets the ledPin to be an output
        Serial.begin(9600);      //initialize the serial port
        digitalWrite(ledPin, 1);      // turn the LED on
[glow]} // <-- The setup function ends here [/glow]
   // this part is what i have added [glow] that is not inside a function[/glow]

{             // <---this part gets highlighted and the issue starts from here

        pinMode (LED, OUTPUT);       // tell Arduino LED is an output
        pinMode (BUTTON, INPUT);      // and BUTTON is an input
}

The same holds true for the code you tried to add to loop.

I have this sensor project that's due for school tomorrow

Got started with plenty of time to spare, huh? ;D

If any sketch won't upload (eg blink), the sketch is immaterial, what would be a lot more use is the type of board, the operating system and the error message when you try to upload

Have you been though this ?

http://arduino.cc/en/Guide/Troubleshooting

I’m still confused :-/

do I have to put “void setup()”

everytime I want to add a different functioning code?

ok this is what I’m doing for this project (and yess I have pushed the programming part last because this part makes me feel nervous), I have a photo resistor that can pick up even the littlest light and get my LED to come on but at the same time, I’m putting a pushbutton (switch for on/ off) if I want the LED to come on or off manually.

I'm pretty sure I have all the physical components wired properly but the programming part.... uhhh I feel like such a deer in the headlight.

I don't know how to put all these commands together and that's why I can definitely use your help.

I don't think I have to do the troubleshooting because I'm pretty sure my arduino lilypad works with my computer through the usb cord.

The setup() function defines stuff that happens once. If you want more stuff to happen once, like this stuff:

      pinMode (LED, OUTPUT);     // tell Arduino LED is an output
      pinMode (BUTTON, INPUT);    // and BUTTON is an input

put it in the setup function - BEFORE the } that defines the end of setup.

The loop() function defines stuff that happens over and over. If you want more stuff to happen over and over, like this stuff:

         Val = digitalRead(BUTTON); // read input value and store it

         // check whether the input is HIGH (button pressed)
         if (val == HIGH) {
           digitalWrite (LED, HIGH); // turn LED ON
         } else {
           digitalWrite (LED, LOW);
         }

put it in the loop function - BEFORE the } that defines the end of loop.

@pluggy

If any sketch won't upload (eg blink), the sketch is immaterial

Bulls**t. If a sketch can't be uploaded, and it is because of a compilation error, the sketch most certainly is relevant. The board type may be a factor, but the operating system almost certainly isn't.

Paul, will you be online for another 30 minutes? I'm gonna put all my code in now and then I will copy and paste it on to here. Will you check it for me to see if I got the hang of it? - p.s: dude you are awesome. thanks.

ok no, I still don't get it. I'm just going to wait outside my profs office until she shows up :|

thanks for trying you guys

and it is because of a compilation error

He said upload, not compile, it it compiles there's no reason it shouldn't upload and the contents of the sketch is immaterial. I always verify before trying to upload, there's no way the 2nd will work if the 1st doesn't.

I know that there are two buttons - one for compiling and one for uploading (that also compiles). You know that. Not everyone else seems to, though. The body of the original post did say that the failure to upload was a result of a compilation error.

I'd much rather see people post code when they didn't need to than to seem them not post code when they needed to.

Well, then there's the "ledPin"/ "LED" and "val"/"Val" problems.

Sort out the spelling and the braces, and it isn't a million miles away. Watch out for floating inputs though.

I figured it out!!! This super nice girl from class showed me how it all worked and ya know what. I basically needed the whole thing explained because it was like asking an infant to run through the alphabet only being taught once.

so my prof first put it in this metaphor for me:

int_whateverwhatever int Whateverwhatever

is like the ingredients

anything below void setup is like the preparation

and anything below void loop is the instructions when cooking/ baking.

and then all the little bits and pieces that I wanted for my project, I just had to find all 2-3 codes and cut and paste them into one, just of the ones I want!

although.... the brackets { } thing still confuse me but I've just been doing it by trial and error.

ok cool. thanks you guys!!!