Go Down

Topic: New with Arduino (Read 1 time) previous topic - next topic

cavalier90

I am new to Arduino and programming itself.  I am working on a project for work and am having trouble getting it to work.  I have to 12v .3A lights that i have and i need them to be blinking them go to steady on.  I am using a photoelectric resistor with a laser beam to control the circuit.  when the laser beam is hitting the sensor i need it to be blinking and when the beam is broke i need it to go steady.  I would eventually probally be able to figure it out but i am running up against a deadline and havent been able to figure it out.  If there is anyone that would be able to help that would be great.

pylon

Show us the code you currently have. We try to help you but we won't do your work.

xolroc

The arduino can in NO circumstances power those lights directly.  Use a transistor.

cavalier90

Here is the code that i have so far like i said i am still very new to programming maybe i am close maybe i am way off i dont really know but i greatly welcomed you wont hurt my feelings if you tell me i am no where close.

Code: [Select]
int sensePin =0;
int ledPin = 9;

void setup(){
  analogReference(DEFAULT); //isn't nessary
 
  pinMode(ledPin, OUTPUT);
 
  Serial.begin(9600);
 
}

void loop() {
  int val = analogRead(sensePin);

if(val > 25) digitalWrite(ledPin, HIGH);

else digitalWrite(ledPin, LOW);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);

Serial.println(analogRead(sensePin));
delay(500);

}

cavalier90

I know there are two LOWs in there i have already fixed that part i just noticed it after i posted it. ;)

Arrch

#5
Jul 03, 2012, 04:21 pm Last Edit: Jul 03, 2012, 04:23 pm by Arrch Reason: 1
Code: [Select]

else digitalWrite(ledPin, LOW);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);


Are you aware that only the first line is run if val is less than or equal to 25? The remaining three lines will run no matter the the value of val.

If you want multiple statements to be executed based on a selection statement, you need to surround them with curly brackets.

hoff70

"NEW TO ARDUINO" and "DEADLINE" don't seem to go together well  :P

Did you consider LED's for the lights?  It'll simplify things a bit where the Arduino is concerned and flatten out the learning curve a little.

cavalier90

Yes I know that new to Arduino and deadline don't mix very well it is driving me nuts but my boss told me I need to get it done.  I feel like i am starting to pick up the basics pretty quick but just missing a few things one of those being time.  I am not sure as to where the curly brackest need to be in the code.  Also replaced the lights with LED lights lower voltage required.

Code: [Select]
int sensePin =0;
int ledPin = 9;

void setup(){
  analogReference(DEFAULT); //isn't nessary
 
  pinMode(ledPin, OUTPUT);
 
  Serial.begin(9600);
 
}

void loop() {
  int val = analogRead(sensePin);

if(val > 25) digitalWrite(ledPin, HIGH);

else digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);

Serial.println(analogRead(sensePin));
delay(500);

}


If someone could possibly point out where the brackets need to be that would be awsome.  Also is the only thing i need the curly brackets?  I am a little surprised that i even got that close.

Arrch

Try looking at some of the example code that came with the Arduino, there are plenty of examples that show you how to use them.


Go Up