Go Down

Topic: First project, not working, can I get a check on my programming? (Read 382 times) previous topic - next topic

kranic3

So im working on a project that uses photo diodes to detect edges.

The arduino (mega) uses 5 digital outputs (20,22,24,26,28) to control my multiplexer. Right now i am just trying to get two photodiodes to be used.

Essentially the arduino is supposed to read the analog input of the photodiode, set it to a variable, switch the multiplexer so the circuit is connected to the other photodiode, again read the value and set it to a variable, then compare the two values.

IF the difference between the two photodiodes is greater than 100 (which is a value that will be changed to tune the device). The arduino will then set pin 53, which is connected to an LED high. If the diffrerence is less than 100, the LED remains off.



int var1;
int var2;

void setup()
{
pinMode( 24 , OUTPUT);
pinMode( 20 , OUTPUT);
var1 = 0;
pinMode( 22 , OUTPUT);
pinMode( 28 , OUTPUT);
pinMode( 26 , OUTPUT);
var2 = 0;
pinMode( 53 , OUTPUT);
}

void loop()
{
digitalWrite( 22 , LOW );
digitalWrite( 24 , LOW );
digitalWrite( 26 , LOW );
digitalWrite( 28 , LOW );
digitalWrite( 20 , LOW );
var1 = analogRead(12) ;
digitalWrite( 28 , HIGH );
var2 = analogRead(12) ;
if (( ( 100 ) < ( abs( ( var1 - var2 ) ) ) ))
{
digitalWrite( 53 , HIGH );
}
else
{
digitalWrite( 53 , LOW );
}
}


Thanks for your help

AWOL

What does your debug output tell you is happening?

Please use code tags when posting code.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

kranic3

I'm very sorry, I don't fully understand what you're asking, This is my first coding project

kranic3

Right now, the LED is in a flicker (barely on) and the photodiodes seem to have zero effect after shielding one from the light

AWOL

Your sketch will be much easier to debug if you get it to tell you exactly what it sees, rather than trying to infer what it sees.
Put some debug prints in your code.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

kranic3

Does that just involve printing the values to serial?
(sorry I know this must be like talking to a toddler )

AWOL

Yes, just that, though it's useful to add a simple label, to tell you which value it is.
e.g.
Code: [Select]
var1 = analogRead(12) ;
Serial.print (F("var1="));
Serial.println (var1);
digitalWrite( 28 , HIGH );
var2 = analogRead(12) ;
Serial.print (F("var2="));
Serial.println (var2);
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

Code: [Select]
if (( ( 100 ) < ( abs( ( var1 - var2 ) ) ) ))
(((((Way (too (damned (many (parentheses) (in) this) statement)))

Go Up