i wanted to share this code with you and the circuit
the code is working . but im not vary good soo it could use some clean up and you may have to tweak it to you application but im happy with the results
im using a joy stick 2 axis each one will need 3 to 2 relays and a driver built for each pot used in less some one can do this better and come up with a code that runs 2 pots at once
components im using
LM317t as to replace the variable resistor controlling the out put of a LM2596s using pwm from the arduino
one dc 12 volt motor from a hp printer
14 volt power supply
with this i can use my 2axis pot style joy stick to smoothly move my robotic self made arm around and control the dominant position and the acceleration of the motor with pwm increasing to make the LM2596s regulator incress voltage with the more pressure applied to the joy stick
const int analogPin = A0; // joy stick pot #1
const int derictPin = A1;//optianal pwm adjustment pot
// pin that the sensor is attached to
const int ledPin = 50; // pin that the LED is attached to has derction of dc motor relay
const int threshold = 600; // an arbitrary threshold level that's in the range of the analog input
int toggle = 40; // motor on / off
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(toggle, OUTPUT);
// initialize serial communications:
Serial.begin(9600);
}
void loop() {
// read the value of the potentiometer:
int analogValue = analogRead(analogPin);
// if the analog value is high enough, turn on the LED:
if (analogValue < 405) {
analogRead(analogPin);
int analogValue = analogRead(A0);//read current pot pos
analogValue = map(analogRead(A0), 440, 0, 255, 0);//map it to pwm
digitalWrite(ledPin, HIGH);//relay fwd derction
analogWrite(12,analogValue/4-60); // pwm LM chip to set Volt level
digitalWrite(toggle, HIGH);// close loop to power supply to actavate motor at cureent pwm set
// print to serial for adjusting and debugging
Serial.println(analogValue);
analogRead(derictPin);
Serial.println(derictPin);
delay(30);
}
else if (analogValue > 505)
{
analogRead(analogPin);
int analogValue = analogRead(analogPin);// read A0 pot
analogValue = map(analogRead(A0), 450, 1023, 255, 0); //map it to pwm
analogWrite(12,analogValue/4-60); //write pwm to LM317 again
digitalWrite(ledPin,LOW); // led pin toggles revers polarity of dc motor relay for now this is my rev derction
digitalWrite(toggle, HIGH);//close loop to acavaite power to motor at pwm set
// print to serial for adjusting and debugging
Serial.println(analogValue);
analogRead(derictPin);
Serial.println(derictPin);
delay(30);
}
else
{
// print the analog value:
analogRead(analogPin); //read curent pot pos
int analogValue = analogRead(analogPin);
analogValue = map(analogRead(A0), 431, 449, -1, 1);// pot resting at home postion make pwm 0
analogRead(analogPin); // print to serial for adjusting and debugging
digitalWrite(toggle,LOW);// when pot is at home postion this kills the relay to the power supply to elemanate back feed and curcit load and save on energy
// print the analog value:
Serial.println(analogValue);
analogRead(derictPin); //optianal pwm adjustment pot
Serial.println(derictPin); // print to serial for adjusting and debugging
delay(30);
}
}
im using it on my atmega right now im hoping to fit it on a attiny85 and make a all in one driver out of it use-in proto board and 3 relays and 2 LM chips will cut me down to a driver with only 7 wires 2 in 2 out and 3 pot wires ....