recently picked up an arduino uno and sparkfun experimenters kit for my son. we are both pretty much total newbs when it comes to writing code in "c" and also fairly new to electronics too.
We have used the attached circuit line drawing, except we are using off the shelf IR sensors (configured the same as the diagram). The sketch we are using is attached too.
We are using 9v to power motors and the motor circuit via a bread board, IR sensors are using 5v through the Uno.
So far we have control of servo motors using transistors to switch the servos.
we have been able to determine the analogue sensor value with an analogue read/ serial print sketch. this value has been used to trigger the motor control circuit (attempted too).
at this point, we have IR sensors returning a change in value when passed over a black tape line, we have motor circuit working when tested independently of the arduino, but as yet, we cannot get motors to respond to IR sensors
any help with code, or circuit trouble shooting would be great.
Also, keep it simple. We've learnt a stack, and have done a lot of systematic trouble shooting, but at the moment we're stumped.
Start slowly kpking. If you do not yet have a circuit that makes the motor respond to the light sensor, dial it back. The fact that your sensors respond as expected is a great start!
Now make a circuit that changes the motor speed and direction respond to a change in voltage. In fact work out each part of your project independently, then combine them. This way you will always have a baseline that you can go back to when he next step of complexity does not work as expected. When you start with too many variables, it's difficult to isolate what works from what doesn't.
Baby steps lead to big strides slowly, but surely.
Trying to learn, and teach my 13yr old at the same time while keeping him keen to persevere with baby steps is a lot to juggle.
Troubleshooting is something I do a lot of with my work.
Electronics, not so much.
I'm fairly confident the physical hardware is correct and working as expected.
IR sensors respond and communicate with arduino.
transistors and motors work as expected too, but not controlled by arduino as yet.
The code I'm less confident with, not convinced we've got the arduino talking to the servo control circuit yet . I think i understand the logic, Learning a new language and translating it to code is a challenge.
How can I test if we're getting an output at pin 11&12?
OldSteve:
The first thing I noticed is that this:-
if(leftValue < 790 & rightValue < 790)
should look like this:-
if(leftValue < 790 && rightValue < 790)
&& not &
Same goes for all other similar lines.
A little known fact is that you can now also use the words "and" instead of "&&", and "or" instead of the even more wild looking "||". It's an official part of the C++ language. For example,
aarg:
A little known fact is that you can now also use the words "and" instead of "&&", and "or" instead of the even more wild looking "||". It's an official part of the C++ language. For example,
if(leftValue < 790 and rightValue < 790)
Wow, really?
I just tried it and, sure enough, it compiles.
bool a = true;
bool b = true;
bool c = false;
if(a == true and b == true)
c = true;
I'm in shock. I learned C++ about 15 years ago, and haven't kept up with the standard since then. I'd never heard of this before in C++.
(If I'd seen someone do it in their code, I would have corrected them. )
I used PICBasic Pro for a long time, and it allows "AND" and "OR", or "&&" and "||", but I never thought I'd see it in C++.
Thanks for the tip. That one's gotta be worth a point.
Made some progress this morning. Fixed up the && error, but no change.
Made some changes to the code after deciding the sensor value used in the if else statements was too close to what sensors were actually returning. No margin for errors.
Also while tidying the wiring a little I found a mistake in IR sensor wiring.
I used some LEDs to help trouble shooting by providing a visual indicator of High output from pin 11,12.
I now know our IR sensors are working, and our code appears to be working, LED indicators (in place of motor circuit) are behaving as expected.
I also identified a blown transistor in the motor control circuit. Trip to parts store is needed before we can continue.
Made some progress this morning. Fixed up the && error, but no change.
That would bring you one step closer at least. Previously, it was a bitwise "OR", ORing 790 with "rightValue", then if "leftValue" was smaller than the result, which was also smaller than 790, your 'if' statement was 'true'.
Keep us posted when you get your replacement parts.
aarg:
A little known fact is that you can now also use the words "and" instead of "&&", and "or" instead of the even more wild looking "||". It's an official part of the C++ language. For example,
if(leftValue < 790 and rightValue < 790)
That is SO COOL!!! Thanks aarg, who knew? (Well, you did for one.)