Pages: [1]   Go Down
Author Topic: Max photoResistor  (Read 792 times)
0 Members and 1 Guest are viewing this topic.
WV
Offline Offline
Full Member
***
Karma: 0
Posts: 160
Arduino, Helps With the ADD
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

im controlling a Stepper with a photoResistor set, But if the values run to high it doesnt run the code like there is no difference between the sensors,,,, See if any on can see where my codeing is creatign the failer,, any suggestions would be greatly appreciated smiley
Code:

/*
Thomas Wood
PhotoCell Controlled Stepper Motor Left and Right
Feb 15,2012
 */

#include <Stepper.h>

const int stepsPerRevolution = 200;  // Turns of the motor
int inputPhotoLeft = 0; // photresistors pin
int inputPhotoRight = 1; // photresistors pin
int Left = 0; // Store readings from the photoresistors.
int Right = 0; // Store readings from the photoresistors.

int threshhold = 450;
// this is here from reading the serial monitors valued to get a ruff Idea of value to set A
                      //And how dark you Want your motor to stop moving at

int difSence = 20; // differenace tolarance between sensors

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9,10,11);
void setup() {
 
  myStepper.setSpeed(150);
 
  Serial.begin(9600);
 
   pinMode(13, OUTPUT); //led doesnt need to be on
}
void loop() {
 Left = analogRead(inputPhotoLeft); // sets the photcells position left - right
 Right = analogRead(inputPhotoRight);
 //Lines for debugging ,analog display of sensor values
Serial.print(" Left \t");
Serial.print(Left);
Serial.print("  Right \t");
Serial.println(Right);
delay(1000);

(13 == LOW);
if ((Left > threshhold) > (Right + difSence > threshhold ))
{
 
  Serial.print("clockwise \t");
  Serial.println(Left);
    myStepper.step(-stepsPerRevolution);
 
 
  }
if  ((Right > threshhold) > (Left + difSence > threshhold ))
{
 
  Serial.print("counterclockwise \t");
  Serial.println(Right);
   myStepper.step(stepsPerRevolution);
 
 
}

if ((Left < threshhold) && (Right < threshhold))
{
  // this is to limit the after dark operation -
  //no need in a plane,train,street light or automobil to make the panel move :)
  Serial.println("Lower threshhold Reached - hopefully we have stopped");
  Serial.print("Left Sensor \t");
  Serial.print(Left);
  Serial.print("   Right Sensor \t");
  Serial.println(Right);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
delay(5000);
}
 
{
 // these are here to disengage the coils as not to hold ,and in turn over heat the motor
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);

}
}

Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8689
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
(13 == LOW);
Doesn't do anything.  Perhaps you meant "digitalWrite(13, LOW);" to turn the LED off?

Code:
if ((Left > threshhold) > (Right + difSence > threshhold ))

If Left is greater than threshold) is greater than (Right  plus difSence is greater then threshold) make very little sense.  I think you are trying to do too much in one comparison.  (Left > threshold) results in a value that is 0 (false) or 1 (true). (Right + difSence > threshold ) similarly results in a 0 or 1.  By comparing for the first one being greater then the second you are saying:

If (Left > threshold) is true (1) and (Right + difSence > threshold) is false (0).

I think what you intended was:
Code:
if (((Left > threshhold) || (Right > threshhold)) && (Left > Right + difSense))

That means: "If either is above the threshold and Left is far enough above Right to make a difference"
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

WV
Offline Offline
Full Member
***
Karma: 0
Posts: 160
Arduino, Helps With the ADD
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

awsome more info to work with smiley time for new symble research, I'll see how this works and post my results smiley
Logged

WV
Offline Offline
Full Member
***
Karma: 0
Posts: 160
Arduino, Helps With the ADD
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

also would you think with the possable error of syntax , would it make it when the photoresistors are at there max light the the left and right section not operate . or not operate from the threshold section ?
Logged

WV
Offline Offline
Full Member
***
Karma: 0
Posts: 160
Arduino, Helps With the ADD
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if (((Left > threshhold) || (Right > threshhold)) && (Left > Right + difSense))

wouldn't that read - if left is greater than threshhold - or - right is greater than threshhold -- AND -- left greater than right plus differance...

 would that make the code if eather sensor was above threshhold?

is this better
Code:
if (((Left > threshhold) && (Right > threshhold)) && (Left > Right + difSense))

wouldn't work smoother with the compairitor of && (and) to make sure both are below tolarance ?
Logged

WV
Offline Offline
Full Member
***
Karma: 0
Posts: 160
Arduino, Helps With the ADD
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok - lol i was mistaken ,, || or works better ,, Thank you smiley
Logged

Pages: [1]   Go Up
Jump to: