const int photo1=A0;
const int photo2=A5;
const int led_pin1=7;
const int led_pin2=4;
// the setup routine runs once when you press reset:
void setup () {
pinMode (photo1, INPUT);
pinMode (photo2, INPUT);
pinMode (led_pin1, OUTPUT); // initialize the digital pin as an output.
pinMode (led_pin2, OUTPUT);
Serial.begin(9600);
}
void loop () {
int value1=analogRead(photo1);
int value2=analogRead(photo2);
delay (200);
Serial.println(value1);
if (value1-value2>100){
digitalWrite(led_pin1,HIGH);
digitalWrite(led_pin2,LOW);
}
else if (value2-value1>100){
digitalWrite(led_pin2,HIGH);
digitalWrite(led_pin1,LOW);
}
else {
digitalWrite(led_pin1,LOW);
digitalWrite(led_pin2,LOW);
delay(200);
}
}
Is there a problem in the code above?It is supposed to light up 2 LEDS according to the light the sensors get(If there is more light to the first sensor,and the difference with the other one is over 100,light up the first LED.Same goes for the second sensor.Else,none of the LEDS should light up).
Although I love that your post has code with colors. something this list should offer on the code boxes, all we can do is look.
please open your code, highlght the whole thing, copy it,
come back, open a new reply, past your code,
now comes the esscential part.
preview it, and on the reply box header, there is </>
with your code and only your code highlighters, hit that and it will put your code into a code box.
once you have done that and posted your reply, we can read your code and test it.
after all that, we will tell you to try to invert your values,
I would paste the line(s), but alas, since you did not paste your code, only a picture, I would have to make a picture and edit that. alas, I have unbuntu and there is virtually no software that even comes close to PAINT
but, take > and make it <
also, print value1, value2 and diff=value3
on your serial print so you can watch the values change.
UKHeliBob:
You have told us what the program is supposed to do but what does it actually do ?
Instead of having 1 LED lit, in case the light difference is over 100, the LED that should be lit is flickering,doesn't have a stable behaviour.
Code incoming.
const int photo1=A0;
const int photo2=A5;
const int led_pin1=7;
const int led_pin2=4;
// the setup routine runs once when you press reset:
void setup () {
pinMode (photo1, INPUT);
pinMode (photo2, INPUT);
pinMode (led_pin1, OUTPUT); // initialize the digital pin as an output.
pinMode (led_pin2, OUTPUT);
Serial.begin(9600);
}
void loop () {
int value1=analogRead(photo1);
int value2=analogRead(photo2);
delay (200);
Serial.println(value1);
if (value1-value2>100){
digitalWrite(led_pin1,HIGH);
digitalWrite(led_pin2,LOW);
}
else if (value2-value1>100){
digitalWrite(led_pin2,HIGH);
digitalWrite(led_pin1,LOW);
}
else {
digitalWrite(led_pin1,LOW);
digitalWrite(led_pin2,LOW);
delay(200);
}
}
Hi.
Check your protoboard, the side strips that you use for +5 and gnd, make sure they are continuous the full length of the board.
Some have an open circuit halfway along.
TomGeorge:
Check your protoboard, the side strips that you use for +5 and gnd, make sure they are continuous the full length of the board.
Good pick!
The ones you illustrate - like mine - have the read and blue lines to indicate. The one he pictured is suspicious insofar as the spacing is different - the "bus" terminals all line up with the columns but there is a two hole gap in the middle instead of the one hole gap at other places.
The MB102 design has equal gaps between each set of five.