Hi!
I am building a radio controlled digger. Everything works just fine, but only when plugged to PC. Code works like this
Read recieved message from transmitter
Check the third letter
Is third letter an 'F'?
YES
Run motors
NO
Turn motors off
Well, everything is okay, until we unplug the Arduino. In this case it works like this
Start
Wait for the message
Message is 'F', run the motors
Run the motors
Run the motors
Run the motors
And it's stuck, won't read any other messages I am sending
I am using Arduino Uno with Motor Shield (Shield powered with 4xAA batteries and Arduino with 9V battery via barrel connector) and 433 MHz XY-MK reciever
This is my code:
#include <VirtualWire.h>
#include <AFMotor.h>
AF_DCMotor motor1(3);
AF_DCMotor motor2(4);
char c;
void setup()
{
motor1.setSpeed(140);
motor1.run(RELEASE);
motor2.setSpeed(140);
motor2.run(RELEASE);
vw_set_rx_pin(2);
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_rx_start();
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))
{
int i;
String data;
for (i = 0; i < buflen; i++)
{
data +=char(buf[i]);
}
c = data[2];
switch(c){
case 'F':motor1.run(FORWARD);
motor2.run(FORWARD);
break;
case 'L':motor1.run(FORWARD);
motor2.run(BACKWARD);
break;
case 'R':motor1.run(BACKWARD);
motor2.run(FORWARD);
break;
case 'B':motor1.run(BACKWARD);
motor2.run(BACKWARD);
break;
default: motor1.run(RELEASE);
motor2.run(RELEASE);
break;
}
}
}
Someone knows what is the problem? It's slowly driving me mad
Appropriate forum section - checked
Correct language - checked (i'm not speaking fluent english yet but I am trying to write everything correctly)
Do some research before posting - I've spended 2 days for research before writing this post, checked
Make a meaningful subject line - checked
Code tags - checked
Post in proper sentences - checked
Detailed description - checked
Expectations and reality - checked
Bumps - well, that's my fault but normally people here are getting answers in half an hour, not 3 days
jremington, I am trying to, but I really can't see your point. Can you tell me what do you think is wrong with my post?
Yes, I am using PP3 batteries. I know that their lifespan is equal to the lifespan of a fly, but I have no room (or battery basket) for 6 AA batteries in my project. I think good solution would be nimh or another rechargeable accumulators but this would provide further research and some money investment, so, maybe later but for now I will stick with casual PP3s
The battery life comes from (in part) the available amperage in those batteries, @AWOL is very very right when he says that AAAs would be better. Also the motors in other situations may stall out easier by pulling too much current as they get near stalling AKA browning it out atleast in part. A final note is that it'll help your "project piggy bank" if you switch them due to a longer battery life, and AAAs are much cheaper and in ready supply in comparison to those clunky PP3s