Project Help

Dear Sirs:

I would like some help with combining a hall sensor for RPM, lcd shield for display and 8 block relay for activation for electric linear and rotary actuators and pots for feedback. I understand Arduino at a beginner's level but when I try to combine all three well documented programs together I mainly get lockups.

Sadly, since this project is on the line I do not have time to fully learn the language that I really love right now.

I would love to offer a small stipend for help on collaboration on this project in order to get it done within the next few weeks. You would have the opportunity to help on the beginning of a stealth VR motion startup as well. I suspect it would take very little time.

Thank you,

Curtis :slight_smile:

What do you have so far?

I suspect it will take far longer than you think, but that's just instinct talking :slight_smile:

Instead of saying what parts you have, give a brief description of what you want to accomplish and more people will be able to see if and how they can help you.

Thank you!!! :slight_smile:

I have a variable geometry bike frame that is expanded or contracted by a linear actuator. A rotary actuator then adjusts the brake tension to match the frame position. The actuators have potentiometers on them to give feedback position. The actuators are controlled by a 4blockrelay. My program works well.

When I try to add a Hall Sensor to measure RPM and a LCD shield to display RPM, frame position and brake tension the program will not run but locks up. I believe I am having issues with timing integration of all three programs.

I would like to have someone take my core program and add a RPM and LCD shield routine to it.

geo_bikeV1.0.ino (5.1 KB)

//pin 2 reserved for interrupt for hall sensor
const byte RELAY1=3; //linear actuator expand
const byte RELAY2=4; //linear actuator contract
const byte RELAY3=5; //rotary actuator clockwise
const byte RELAY4=6; //rotary actuator counter clockwise
const int actPot = A2;  // actuator pot pin
const int brkPot = A3; // brake pot pin

Do you plan, at some point, to move the actuator and brake to other pins, such as maybe putting the actuator pot on analog pin 12478 and the brake pot on analog pin -25639?

int tgtValue = 0; //target value you want frame's linear actuator to be at
int tgt2Value = 0;//target value you want brake's rotary actuator to be at

Is it that difficult to use meaningful names? Why would I want to have to go back and look at the comments to see what the variable is used for? tgtActValue and tgtBrkValue mean that I don't need to.

      tgt2Value=int (776.769 - (.5152 * actValue));    
      actValue=analogRead(actPot);       //value of linear actuator's yo-yo pots  390  457  525  577  650 (-10 degree down to +10degree up)

So, the target brake value depends on the actuator value, so after we calculate the target, let's see what the actuator value IS Hmmm.

      while(actValue < 300 && actValue > 750){Serial.print("TILT1");//if the values are out of bound the pot or something else broke
      }

If something went wrong, there is no opportunity to correct the problem without resetting the Arduino. Is that what you really want? Perhaps there was simply an electrical spike causing an out-of-band reading. Take another reading, and everything might be OK.

That is NOT a good test for the potentiometer having become disconnected, as the comment implies.

      if (diff1 <= 5 && diff1 >= -5) {
      digitalWrite(RELAY3, HIGH);
      digitalWrite(RELAY4, HIGH);
      }

Do you really think that way? Personally, when checking that a value is in range, I check that it is above the low end first.

      if (diff1 <= 5 && diff1 >= -5) {
      digitalWrite(RELAY3, HIGH);
      digitalWrite(RELAY4, HIGH);
      }
      if (diff1 >5 ) {
      digitalWrite(RELAY3, LOW);
      digitalWrite(RELAY4, HIGH);
      }
      if (diff1 <-5){
      digitalWrite(RELAY3, HIGH);
      digitalWrite(RELAY4, LOW);
      }

How many of these if statements will evaluate to true on any given pass through loop()? When the answer is "never more than one", if/else if/else is more appropriate than if/if/if

      while(brkValue < 350 && brkValue > 650){Serial.print("TILT2"); //if the pot is out of bounds the pot probably broke
      }

While the number is less than 350 and greater than 650, do this. Just how many values, in the real world, satisfy that criteria?

There is nothing in your code to write to an LCD or to read from a hall effect sensor, so it is difficult to imagine what issues you are having using them.

I CAN imagine that all those delay()s are going to take a bite out of your posterior eventually. Make them go away now.

PaulS you had me in tears with your sarcasm. LOL. I am also really embarrassed for my mistakes as a beginner. I will correct all your suggestions and re-post with my attempt to add the Hall Sensor in a few hours.
Thank you. :slight_smile:

Paul S I made the suggested corrections to first clean up my code. Thank you I learned a lot. I owe you a couple of beers if I ever meet you in Cali.

/*

  • This Arduino Uno program runs a special bicycle with change-on-the-fly frame geometry
  • and braking. The bike has a linear actuator for increasing or decreasing frame geometry
  • and rotary actuator for brake tension each with pots for positional feedback of the two
  • actuators .
  • A block of 4 relay modules control the two actuators. (5V 4 Channel Relay Shield Module
  • optocoupler Arduino) For the following program if you change the target value (tgtactValue)
  • the bike frame will move to that value and at the same time change the brake tension to
  • match a desired setting. The existing program works well.
  • I want to be able to add an Hall sensor (Sunfounder Hall Switch
  • SunFounder Switch Hall Sensor Module for Arduino and Raspberry Pi) on the front wheel to monitor
  • front wheel RPM and a LCD display (Sunfounder IIC/I2C/TWI Serial 2004/20x4 LCD Module
  • Shield for Arduino Uno/Mega2560) that displays bicycle wheel rpm, frame geometry and
  • brake tension settings. When I try to add a Hall Switch Routine, LCD Shield Routine
  • and my program they interfere with each other in a way I am not able to debug.
  • Thank you for your consideration!!!!
  • Curtis Platt projecteinsteinvr@att.net
    */

//pin 2 reserved for interrupt for hall sensor
const byte RELAY1=3; //linear actuator expand
const byte RELAY2=4; //linear actuator contract
const byte RELAY3=5; //rotary actuator clockwise
const byte RELAY4=6; //rotary actuator counter clockwise
const byte actPot = A2; // actuator pot pin
const byte brkPot = A3; // brake pot pin

int tgtActValue = 0; //target value you want frame's linear actuator to be at
int tgtBrkValue = 0;//target value you want brake's rotary actuator to be at
int actValue = 0; //actual value of frame's linear actuator from pot
int brkValue= 0; //actual value of brake's rotary actuator from pot
int Actdiff = 0; //difference of actual and target value of linear actuator
int Brkdiff = 0;//difference of actual and target value of rotary actuator

void setup()
{
Serial.begin(9600); //needed to display on serial monitor

// Initialise the Arduino data pins for OUTPUT
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);
//turn them all off
digitalWrite(RELAY1,HIGH);
digitalWrite(RELAY2,HIGH);
digitalWrite(RELAY3,HIGH);
digitalWrite(RELAY4,HIGH);
}
void loop(){
//user inputs tgtactValue here between 390 and 630 and the programs computes a second
//tgtactValue and also finds the two pot's outputs

tgtActValue=525; //midway of frame geometry
tgtBrkValue=int (776.769 - (.5152 * actValue));
actValue=analogRead(actPot); //value of linear actuator's yo-yo pots 390 457 525 577 650 (-10 degree down to +10degree up)
delay(5);
brkValue=analogRead(brkPot); // value of brake rotary actuator's pot 575 540 510 480 450 (fully to openfully closed)

/*we run a simple linear regression analysis of the corresponding pot's

  • points so when frame is -10 degrees down the brake is fully open, when
  • the frame is neutral the brake is at neutral or when the frame is 10 degrees up
  • the brake is fully closed or any proportion in between.
  • frame, brake
  • x, y
  • 390,575
  • 457,540
  • 525,510
  • 577,480
  • 630,450
  • //www.alcula.com/calculators/statistics/linear-regression/
  • using the above 5 plot points we come up with a very close approximation of y(brake tension)
  • whenever you input x(frame position) with the simple linear Regression y=776.769 - .5152x .
    */

//this routine compares target values (one input from user and one calculated) and actual pot feedback
//values and activates the relays and thus the actuators accordingly.

delay(5);
Actdiff=(tgtActValue-actValue);

while(actValue < 300 || actValue > 750){Serial.print("TILT1");//if the values are out of bound the pot or something else broke
delay(500);
actValue=analogRead(actPot);
}

if (Actdiff <-5){
digitalWrite(RELAY3, HIGH);
digitalWrite(RELAY4, LOW);
}
else if (Actdiff >5 ) {
digitalWrite(RELAY3, LOW);
digitalWrite(RELAY4, HIGH);
}
else{
digitalWrite(RELAY3, HIGH);
digitalWrite(RELAY4, HIGH);
}

Brkdiff=(brkValue-tgtBrkValue);

while(brkValue < 350 || brkValue > 650){Serial.print("TILT2"); //if the pot is out of bounds the pot probably broke
delay(500);
brkValue=analogRead(brkPot);
}

if (Brkdiff <-15){
digitalWrite(RELAY1, HIGH);
digitalWrite(RELAY2, LOW);
}
else if (Brkdiff >15 ) {
digitalWrite(RELAY1, LOW);
digitalWrite(RELAY2, HIGH);
}
else{digitalWrite(RELAY1, HIGH);
digitalWrite(RELAY2, HIGH);
}