Arduino to Intercept Signal Between IP Camera and Stepper Motors

If I get A=1 B=0 C=0 D=0 ..........

Only if the pins are changing slower that the time it takes to do several Serial.print() commands.

Well I can set the speed of the camera. So if I set it to the slowest setting, and set the baud rate of the serial monitor pretty high, should that give me a more accurate reading?

It will be better but still don't know if it will be fast enough. Best bet is to record four changes and then print them out all at once.

And how do I do that?

Well we are back to your coding skills aren't we.

Read the inputs, compare to what they were last time, if they are the same go back and read them again. If they are different record them in variables.
Do that four times with different variables and then print out all the variables.

Okay. I think I can manage that.

I apologize for my programming skills. Programming is still VERY new to me. I have a lot more knowledge of electronics, but programming is still coming very slowly.

That's OK doing this will improve it. It's just that you have started with too complex a project to learn on.

Ok, so this was the code I used.
/*
MultipleDigitalReadSerial
Reads a digital input on pin A0, A1, A2, and A3. It then prints the result to the serial monitor.
*/

void setup() {
Serial.begin(9600);
}

void loop() {
int sensorValueA = digitalRead(A0);
int sensorValueB = digitalRead(A1);
int sensorValueC = digitalRead(A2);
int sensorValueD = digitalRead(A3);
Serial.print("A");
Serial.print("= ");
Serial.print(sensorValueA, DEC);
Serial.print("B");
Serial.print("= ");
Serial.print(sensorValueB, DEC);
Serial.print("C");
Serial.print("= ");
Serial.print(sensorValueC, DEC);
Serial.print("D");
Serial.print("= ");
Serial.print(sensorValueD, DEC);
Serial.println();
}

I set the baud rate slower and it wouldn't refresh quick enough to give me a good pattern. I set it faster and it confirmed the pattern I was receiving at 9600, but it gave me way too much data. I believe 9600 was the best baud rate. What I determined was that ABCD= Right and DCBA= Left.

I don't quite know what to think of the wave pattern because the pulses overlap by two carriage returns. So what I got was

A=0 B=1 C=1 D=1
A=0 B=1 C=1 D=1
A=0 B=1 C=1 D=1
A=0 B=1 C=1 D=1
A=0 B=1 C=1 D=1
A=0 B=0 C=1 D=1--
A=0 B=0 C=1 D=1--/It overlaps two carriage returns here
A=1 B=0 C=1 D=1
A=1 B=0 C=1 D=1
A=1 B=0 C=1 D=1
A=1 B=0 C=1 D=1
A=1 B=0 C=1 D=1
A=1 B=0 C=0 D=1--
A=1 B=0 C=0 D=1--/And here...
A=1 B=1 C=0 D=1
A=1 B=1 C=0 D=1
A=1 B=1 C=0 D=1
A=1 B=1 C=0 D=1
A=1 B=1 C=0 D=1
A=1 B=1 C=0 D=0--
A=1 B=1 C=0 D=0--/And here...
A=1 B=1 C=1 D=0
A=1 B=1 C=1 D=0
A=1 B=1 C=1 D=0
A=1 B=1 C=1 D=0
A=1 B=1 C=1 D=0
A=0 B=1 C=1 D=0---
A=0 B=1 C=1 D=0---->This is where it overlaps three carriage returns.
A=0 B=1 C=1 D=0---/
A=0 B=1 C=1 D=1
And then it repeats...

Okay. I think I can manage that.

So why have you not written the code like that?

What does this mean?

because the pulses overlap by two carriage returns.

I wrote it like that to give me the values of all the pins at all points in time, instead of just when the pins change. I just used this code to figure out the pattern of the pins. and whether the pulses overlap or not when the signal goes from pin to pin.

What I mean by overlapping by two carriage returns, is that when A is low, and the low signal goes from pin A to pin B, both are low for two Serial.println();'s before only B is low.

  1. You must ignore duplicate values because Arduino may be scanning the lines faster than the motor is turning.
    1.5) To be able to ignore duplicate values, you must store each value so the next time through the loop, you can compare it with the current value to decide duplicate/new.
  2. After you have those down and you can tell which way the motor is turning, you must have some sort of time-out to know when the motor has stopped. So you must decide" "x milliseconds after the pattern stops changing, I will decide that the motor isn't turning anymore".

This is very helpful information, and I completely understand what the code is supposed to do now. But my programming knowledge is lacking too much for me to do this on my own. I understand that this forum is all about support and learning, and I really like that, but this project is becoming a very LONG learning process.

By the time I learn how to program this myself, I will have possibly ripped out all my hair. Is there any possible way you could provide annotated code? Or atleast teach me the functions that I will use and tell me how to use and how to program them so that I will have a perfect understanding of what they do? Thank you.

I know this project is way over my head. But I started the project to accomplish the project and I wasted to learn about the arduino along the way. It has been over six months of trial and error learning.

I really want to get this project finished so I can enjoy what I have put so much effort over the past six months into doing. Can you please provide a step by step on how to code this? I don't like just jumping into writing a program without having any idea of how to accomplish what I want to do.

Would you be willing to give me any other guidance besides just telling me that I need to write the code for it?

My words are not meant to sound frustrated. I'm sorry if they do. I have been reading every Arduino reference book I can get my hands on for the past week and haven't found anything helpful.

Can you please provide a step by step on how to code this?

You have no idea what you are asking.

This is a complex project, you have been told many times before.

Because only you have the hardware, only you can write the code, debugging and get it working.

We can tell you what to do but you appear not to want to do it.
If we could write code that involved and get it working first time (because you will not be able to debug it) we would be much better programmers than we are.

It has been over six months of trial and error learning.

If you would have spent six months actually learning about the arduino and programming, that is completing tutorial examples, debugging them, getting them working and then doing minor modifications and tweaks, you may have learn considerably more than you appear to have learn.

I have completed all of the trivial examples that are available to do. None of those prepared me for needing to use code to determine sequence and deal with wrap arounds. If I somehow missed these examples then please tell me where I can find them and I would be happy to do them.

The hardware I am using is not code specific. To make the tracks move forward all you have to do is write two pins high. Move backward = two other pins high. Left= one pin high. Right= the other pin high.

Give me any amount of code and I would be more than happy to busy myself for weeks trying to debug it to work for what I need.

I can figure things out if they are right in front of me by going through the code and figuring out what each piece does. It would be much better than continuing to google for things that I have no idea what I am looking for.

Please?

Thank you. I'll start programming tonight and upload whatever I have done tomorrow afternoon to make sure I am doing it right. I appreciate the detailed answer.

void setup();{
int motorPinA = 0;
int motorPinB = 0;
int motorPinC = 0;
int motorPinD = 0;
int currentValue = 0;
int lastValue = 0;
pinMode (12, INPUT);
pinMode (11, INPUT);
pinMode (10, INPUT);
pinMode (9, INPUT);
}
void loop(); {
int motorPinA = digitalRead(12);
int motorPinB = digitalRead(11);
int motorPinC = digitalRead(10);
int motorPinD = digitalRead(9);

if (motorPinA == LOW) {
currentValue = 1;
}
else if (motorPinB == LOW) {
currentValue = 2;
}
else if (motorPinC == LOW) {
currentValue = 3;
}
else if (motorPinD == LOW) {
currentValue = 4;
}
else {
currentValue = 0;
}

So this is what I have so far. I'm having trouble figuring out how to put the previous value into action. I know that I need to compare the currentValue to the lastValue. But I don't know how to keep the previous pin that was LOW into a variable so that it changes, but it is always one behind the currentValue.

When you say "int", you are defining a variable. You need to do that only ONCE up in the setup() section. Take out the "int"s

NO! Don't take out the int type. The (poorly named) variables motorPinA, motorPinB, motorPinC, andmotorPinD do not need to be global variables. The local variables defined in setup are not in scope in loop (and, therefore are a waste of time).

So this is the newest code :

void setup() {
int motorPinA = 0;
int motorPinB = 0;
int motorPinC = 0;
int motorPinD = 0;

pinMode (11, INPUT);
pinMode (10, INPUT);
pinMode (9, INPUT);
pinMode (8, INPUT);
Serial.begin(9600);
}
void loop() {
int currentVal = 0;
int lastVal = 0;
int val = 0;
int motorPinA = digitalRead(11);
int motorPinB = digitalRead(10);
int motorPinC = digitalRead(19);
int motorPinD = digitalRead(8);

if (motorPinA == LOW) {
currentVal = 1;
}
else if (motorPinB == LOW) {
currentVal = 2;
}
else if (motorPinC == LOW) {
currentVal = 3;
}
else if (motorPinD == LOW) {
currentVal = 4;
}
else {
currentVal = 0;
}
if (currentVal > lastVal) {
val = 1;
lastVal = currentVal;
}
else if (currentVal < lastVal) {
val = 2;
lastVal = currentVal;
}
else if (currentVal == lastVal) {
val = 3;
lastVal = currentVal;
}
Serial.println(val, DEC);
}

It serial prints 3 when it is supposed to(when the motor is not moving), but it serial prints 1 when it is spinning in either direction. Can you see any obvious mistakes in the code or something that I need to fix?
Any advice is helpful. Thanks in advance.