Pages: [1] 2   Go Down
Author Topic: I need assistance with a project.  (Read 1004 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 2
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am brand new to the Arduino. I literally bought my board about a half hour ago and I need a starting point. The gist of m project is when I open up my trunk, I'm going to want an led to slowly turn on and then slowly turn back off when the trunk is closed. I have the bored, some led's, and a large momentary push button. I know it's going to be using an if then statement, but how exactly would I set up the code, and how exactly should I set up the button on the board? Thank you for any help you guys can provide in advance.
Logged

Offline Offline
God Member
*****
Karma: 7
Posts: 647
"In this house, we obey the Laws of Thermodynamics" Homer J. Simpson
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try getting an LED to blink first.
http://www.arduino.cc/en/Tutorial/BlinkingLED

Then look around the other tutorials, add a switch and so on.
Logged

Indiana, US
Offline Offline
Full Member
***
Karma: 12
Posts: 204
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Frank, and welcome to the wonderful world of Arduino.

I suggest that you start off by looking through some of the code examples on this site and build up some sketches and circuits.  There are a lot of good books, too, that you should buy or borrow.

I caution you from jumping in too quickly and asking the members on the forum to draw your circuits and write your code for you.  The fun is in the learning!

Try some things and ask for help when something doesn't work. You'll find a lot of help here!

Pat.
Logged

There are 10 types of people in the world, those that understand binary, and those that don't.

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2277
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

After playing with the blink example (and a few others) look at "blink without delay" . You can't really combine blink with a button but you can combine a button with "blink without delay". You will also need to look at "de-bouncing". Look in the "playground" section of the main site.

Good luck

Mark
Logged

Offline Offline
Newbie
*
Karma: 2
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks guys! I'll definitely mess around with it for a little while. I'm actually in school now for programming and have some past knowledge on C++. I'm not an expert, but I know some. I'll ask some questions as they come. This already seems to be a pretty helpful forum.
Logged

Offline Offline
Newbie
*
Karma: 2
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Alright, i've got the LED blinking an i've been messing with it. I have that down, now I need to ask a few questions. Is it possible to accomplish what I want without a bread board? and if so, what ports would I connect the push button too and how exactly would that be coded? This is the example i'm using.
Code:
const int ledPin =  13;     

int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 50;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);     
}

void loop()
{
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12631
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

when I open up my trunk, I'm going to want an led to slowly turn on and then slowly turn back off when the trunk is closed.

This reminds me of the age-old question about fridge lights. If the light only fades off when the trunk is closed, how will you know? This might make more sense as a way to control the car's interior light based on door switches.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 2
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, yeah :p I just want it to slowly come on. I don't really need it to fade out. The issue is, my trunk doesn't have a light. I'd like to set it up with a switch because there are no sensors in my trunk to indicate when It's open and the odds are when I am opening my trunk, the rest of the door will be closed therefore the light would not come on. Is there a simple way to lets just say I hooked my led up to point a and b and my switch to c and d and the code would say if c and d= 1 (connected) then a +b =1(led on) Or is that not possible?
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, yeah :p I just want it to slowly come on. I don't really need it to fade out. The issue is, my trunk doesn't have a light. I'd like to set it up with a switch because there are no sensors in my trunk to indicate when It's open and the odds are when I am opening my trunk, the rest of the door will be closed therefore the light would not come on. Is there a simple way to lets just say I hooked my led up to point a and b and my switch to c and d and the code would say if c and d= 1 (connected) then a +b =1(led on) Or is that not possible?

But what value does the arduino bring to the party? Why not a simple tilt switch mounted to the trunk lid wired to the lamp and on to +12vdc. Seems a waste of an arduino board if that is all the application requires.

Lefty

https://www.sparkfun.com/products/10289?
Logged

Offline Offline
Newbie
*
Karma: 2
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The reason i'm doing this in the first place is because there is NO lamp in my trunk. Instead of installing a plain light, I wanted to make an aesthetically pleasing LED arrangement to complement my subs. This is where I am. I think this should be working. I've got the LED hooked up to the GND and 13. I have a mommentary push button hooked up one end on the 5 volt spot, and the other on the #2 spot. This is what the code looks like.
Code:
const int buttonPin = 2;    
const int ledPin =  13;      


int buttonState = 0;        

void setup() {
  pinMode(ledPin, OUTPUT);      
  pinMode(buttonPin, INPUT);    
}

void loop(){
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {        
    digitalWrite(ledPin, HIGH);  
  }
  else {
    digitalWrite(ledPin, LOW);
  }
}

It's really unpredictable now. It will work sometimes, and others it flicker or stay on and the button won't turn it off. Should the button be grounded? What's going on?
Logged

Saskatchewan
Offline Offline
Sr. Member
****
Karma: 19
Posts: 364
When the going gets weird, the weird turn pro. - Hunter S. Thompson
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you have resistors wired in?

You can use the LED on board at pin 13 without resistors, others need resistors wired along with the lamp.

If you don't have any resistors with your switch you're doing it wrong. You can use a switch without resistors by wiring it between a digital pin and ground then turning on the internal pullup resistors. Then HIGH is off and LOW is on.

Without resistors you could be damaging your Arduino.
Logged

Offline Offline
Newbie
*
Karma: 2
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the heads up! So, how exactly would I wire the button and use the built in resistor?
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I have a mommentary push button hooked up one end on the 5 volt spot, and the other on the #2 spot.

That is probably the root of your problem. You will have a 'floating input pin' condition when you release the switch. This causes the pin 2 digitalRead() statements to return random bad values when not being pressed. Possible fixes:

1. You need to wire a pull-down resistor say 10k ohms from pin 2 to ground which will force an electrical low onto the pin when you release the switch.

Or
2. Wire one end of the switch to an arduino ground pin and the other end to pin 2. Then in your setup code add the statement digitalWrite(buttonPin, HIGH); right after your existing pinMode(buttonPin, INPUT); That will turn on the internal pull-up resistor for pin 2. Then in your code make any change needed because now a digitalRead() = LOW means the switch is being pushed and = HIGH means the switch is not being pressed.

Lefty
Logged

Offline Offline
Newbie
*
Karma: 2
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you so much man! God, this is really one of the most helpful communities I've been a part of already! Now to make it slowly turn on. I'll post again if I run into anymore trouble.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you so much man! God, this is really one of the most helpful communities I've been a part of already! Now to make it slowly turn on. I'll post again if I run into anymore trouble.


Well I'd actually like you to see also post when you have good things to report not just your problems.  smiley-grin

Lefty
Logged

Pages: [1] 2   Go Up
Jump to: