I am an absolute beginner with arduino duemilanova.
For exercise i created a sketch to run a steppermotor.
I did it on purpose in a strange way by writing a very simple wave going to an array of 4 outputs.
Using an uln2003a driver, the thing works.
The motor is attached to a potentiometer (5 turns) which returns the position of the motor.
A second identical potentiometer i can change position.
The motor searches now the same position.
int sensorPin1=0;
int sensorPin2=1;
void setup(){
//initialize pins for output
for (int thisPin=2;thisPin<6; thisPin++)
pinMode(thisPin,OUTPUT);
pinMode(sensorPin1,INPUT);
pinMode(sensorPin2,INPUT);}
void loop (){
int val=analogRead(0);
int var=analogRead(1);
if (val<var-50)//motor forward "to" var
{//forward loop
digitalWrite(2,HIGH);
delay(50);
digitalWrite(2,LOW);
digitalWrite(3,HIGH);
delay(50);
digitalWrite(3,LOW);
digitalWrite(4,HIGH);
delay(50);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
delay(50);
digitalWrite(5,LOW);
}
if (val>var+50)//reverse going
{digitalWrite(5,HIGH);
delay(50);
digitalWrite(5,LOW);
digitalWrite(4,HIGH);
delay(50);
digitalWrite(4,LOW);
digitalWrite(3,HIGH);
delay(50);
digitalWrite(3,LOW);
digitalWrite(2,HIGH);
delay(50);
digitalWrite(2,LOW);
}
if (val=var)//must stop
{
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
}
}
This stuff works, but not if sensorpins are 1 and 2 instead of 0 and 1.
If i define them as 1 and 2, the !output! number 2 works if nothing is connected(no load at all) 0/5volts.
But if it drives a led or even simply informs the uln2003 input, it gives no more than 1,5volts (off course to little).
Question: Should i do defining in another way, because it should be possible to use inputs with the same id than the outputs.
ps: i know that the idea of running a steppermotor with this kind of sketch is unusual and not prferable, but it is only a way of learning to see if things work out.