Senior Design Project Help

hgmjr

Joined Jan 28, 2005
9,027
You logic will need to be changed.

If you think about it, the only thing that you want to do is turn the relay off only if all of the axes are within the limit at the same time. Otherwise you can turn the relay on.

hgmjr
 

hgmjr

Joined Jan 28, 2005
9,027
Your logic test will need to change.

Note that what you need to do is check that all axes are within their limits at the same time. If yes, then turn off relay. If no, turn on relay.

hgmjr
 

Thread Starter

ripcus10

Joined Apr 13, 2012
56
Ok, would i be able to put all of the pins on the same line, like this
Rich (BB code):
 if(analogRead(xpin, ypin, zpin)>607)
  { digitalWrite(relaypin, HIGH);
or would the logic have to be done a different way?
 

hgmjr

Joined Jan 28, 2005
9,027
How about this:

Rich (BB code):
if ((xpin > xmin) && (xpin < xmax)){
     if ((ypin > ymin) && (ypin < ymax)){
         if ((zpin > zmin) && (zpin < zmax)){
            ... Turn off relay ....
         }
     }
}
else
{
    ... Turn on relay ....
}
hgmjr
 

hgmjr

Joined Jan 28, 2005
9,027
You may need to alter the code as follows:

How about this:

Rich (BB code):
if ((xpin > xmin) && (xpin < xmax)){
     if ((ypin > ymin) && (ypin < ymax)){
         if ((zpin > zmin) && (zpin < zmax)){
            ... Turn off relay ....
         }
         else {
            ... Turn on relay ....
         }
     }
     else {
            ... Turn on relay ....
}
else {
    ... Turn on relay ....
}
hgmjr
 

Thread Starter

ripcus10

Joined Apr 13, 2012
56
If i program it like the example that you gave me the relay stays on the whole time. If i switch the relay positions around so that the relay is on when at the end of the if statement the relay stays on. I think that is telling me that by limits are not where they should be and need to be adjusted. Would you agree?
 

Thread Starter

ripcus10

Joined Apr 13, 2012
56
Yeah The relay stays on all the time again and no matter how hard a smack it or how long i leave it at rest it doesn't change. I think my limits might be off.

I have to go to a meeting with my other group members and i don't know how long it will take. I appreciate all your help and understand if you want to step away from it all for a while. Thanks again
 

chrisw1990

Joined Oct 22, 2011
551
honey im home.
nice one on getting the led working! dont know why i didnt think about the contention of the IO such a stupid problem to have come across.. this can obviously be overcome if a custom prototype is developed using an OR gate or two.. probably one IC anyway..
if(analogRead(xpin, ypin, zpin)>607)
{ digitalWrite(relaypin, HIGH);
in terms of this.. im not sure if the compiler will like it.. but you can use && i.e.:
Rich (BB code):
if(analogRead(xpin>512)&&analogRead(ypin>512)&&analogRead(zpin>512))
{ digitalWrite(relaypin, HIGH); }
i would assume if this is a C compiler then it should like it..
you could in fact, combine your if statements, i.e. keep to three if statements:
Rich (BB code):
if(analogRead(xpin>600)|| analogRead(xpin<600))
{ digitalWrite(etc..); }
however, when it starts to even think about this kind of route, it might be better to consider using a separate variable.. i.e.
analogX=analogRead(xpin); (after setting up the variable)
this way your always comparing the same values.. and theres no way youre comparing different values, which could occur if you are effectively asking the uC to convert the analog signal twice in one if statement.. of the same pin! unnecessary delay and overheads:)
 

hgmjr

Joined Jan 28, 2005
9,027
.... I think my limits might be off.
I believe you have hit the nail on the head.

I checked the schematic for the Arduino board you are using and it looks like the ADC's reference voltage is tied to +5V. On the other hand, the accelerometer has a maximum voltage output of 3.3V.

This means that 1.65 actually equates to

1.65/5.0 times 1023. This gives 337 as the output from the Arduino with an input of 1.65V.

hgmjr
 
Last edited:

chrisw1990

Joined Oct 22, 2011
551
ah yeh of course, didnt think about that either!
thats silly design, it should run off the same voltage, especially on a dev board...
using multiple voltages always makes things confusing:S

or it should have a jumper selection...
 

hgmjr

Joined Jan 28, 2005
9,027
ah yeh of course, didnt think about that either!
thats silly design, it should run off the same voltage, especially on a dev board...
using multiple voltages always makes things confusing:S

or it should have a jumper selection...
Yeah. I was hoping for the avialability of a jumper selectable ADC reference voltage but I quickly learned that there was no jumper available.

Maybe with a few adjustments to the ADC test limits ripcus10 is using and a correction to the programming logic to contend with the three outputs controlling a single output, the overall project will take a turn for the successful.

hgmjr
 

chrisw1990

Joined Oct 22, 2011
551
Yeah. I was hoping for the avialability of a jumper selectable ADC reference voltage but I quickly learned that there was no jumper available.

Maybe with a few adjustments to the ADC test limits ripcus10 is using and a correction to the programming logic to contend with the three outputs controlling a single output, the overall project will take a turn for the successful.

hgmjr
Absolutely! its not far off now! it took a big leap forward when you spotted the contention!!:)
 

Thread Starter

ripcus10

Joined Apr 13, 2012
56
Hey guys I'm back sorry for the long delay. If i understand what you guys were saying in the previous post 1) My limits are trulely off and if i understand what you are saying, then my middle point should be 337 and +/- 375 from there? 2) Should i change my code to the style that Chris showed or should i keep it the way you suggested and just change the values? Thanks for continuing to work while i was gone!!
 
Top