edge lab LIVE! starts Tuesday in Munich. Grab a workshop seat and take home the board you build on. Code FRIEND-HACKSTER saves 20%. () Learn more!
willyerburgh
Published © GPL3+

Digital Controlled Ram Depth

A simple method of controlling solenoids to ensure two rams are equal length, and the ability to digitally set that depth.

BeginnerShowcase (no instructions)2 hours861
Digital Controlled Ram Depth

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Resistor 221 ohm
Resistor 221 ohm
×8
LED (generic)
LED (generic)
×8
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×3

Story

Read more

Schematics

Hydraulic Schematic

This is to show what the different solenoids are doing.

Electrical Schematic

See how it is wired up

Code

Depth Control Code

C/C++
Below is the code needed to create the circuit that has been discussed.

The number of cylinders that can be used is dependent on the user, to add or remove cylinder just add them 'inSol[]' array, and make sure to add a potentiometer reading for it in 'axlePot'.
//pins
int depthSet = A5; //depth set pot pin
int axlePot[] = {A0, A1}; //ram pot pins
int sol1 = 2; // solenoid 1 pin
int inSol[] = {3, 4}; //solenoid 2 - 3
int liftRam = 7 ; // button for transport solenoid
int ledPins[] = {9, 10, 11, 12, 13}; //display pins

//variables
int readSet; //value of setting pot
int readAxle[3]; //number of ram pots to read
const int ledCount = 6;    // the number of LEDs in the display

void setup() {
  for (byte i = 0; i < 3; i++) { //setting the ram potentimeters
    pinMode(axlePot[i], INPUT);
  }
  for (byte i = 0; i < 3; i++) { //setting the ram solenoids
    pinMode(inSol[i], OUTPUT);
  }
  for (int thisLed = 0; thisLed < ledCount; thisLed++) { //setting the depth display
    pinMode(ledPins[thisLed], OUTPUT);
  }
  pinMode(depthSet, INPUT); // setting the depth potenimeter
  pinMode(liftRam, INPUT_PULLUP); //reading the ramLift pin
  pinMode(sol1, OUTPUT); // setting solenoid 1
}

void loop() {
  
  readSet = analogRead(depthSet);

  int ledLevel = map(readSet, 0, 1023, 0, ledCount); //shows a depth value on the led display
   for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    if (thisLed < ledLevel) {
      digitalWrite(ledPins[thisLed], HIGH);}
      else {
        digitalWrite(ledPins[thisLed], LOW);
      }
    }
  for (int i = 0; i < 3; i++) { //read axle pins
    readAxle[i] = analogRead(axlePot[i]);
  
  for (int i = 0; i < 3; i++) {
     if(readAxle[i] < 0.9*readSet) {
        digitalWrite(inSol[i], HIGH);
        digitalWrite(sol1, HIGH);
      }
      if (readAxle[i] > 0.9*readSet && readAxle[i] < 1.1*readSet) {
        digitalWrite(inSol[i], LOW);
        digitalWrite(sol1, LOW);
      }
      if (readAxle[i] > 1.1*readSet) {
        digitalWrite(inSol[i], HIGH);
        digitalWrite(sol1, LOW);
      }
    }
  }
}

Credits

willyerburgh
2 projects • 1 follower

Comments