Adding blinking LED sketch to RC sketch for rc bulldozer reversing alarm

Hi

I am using an arduino uno, with a dual h bridge motor controller to control an RC bulldozer, I am using a code from indestructibles, it works very well but I would like to a add reversing alarm .

I think I know what I need to do but have no idea how to write the code !

This is what I think needs to happen:

When the 2 pins for reverse are low/high turn on pin connected to buzzer? But I would also like the buzzer to be 1 sec on 1 sec off.

Post your code. Post a schematic. What type of buzzer is it? Does it need a frequency signal or does it just need an on or off signal?

Read the "how to use this forum-please read" stickies to see how to properly post code and some hints on how to ask a good question. See #7 & 11.

here is part of the code that deals with reverse:

case DIRECTION_REVERSE:
      digitalWrite(LEFT1,HIGH);
      digitalWrite(LEFT2,LOW);
      digitalWrite(RIGHT1,HIGH);
      digitalWrite(RIGHT2,LOW);

the circuit is made up as follows:

MOTOR DRIVER -> ADUINO

M1A -> arduino pin5
M1B ->arduino pin6
ENABLE1 ->arduino pin10
M2A ->arduino pin7
M2B ->arduino pin8
ENABLE2 ->arduino pin11
GND-> arduino gnd
+5v ->arduino vcc

RECEIVER -> ARDUINO

CH1 -> pin 3
CH2 -> pin 2
GND->GND
+5V->+5V

What I think I need to do is when LEFT 1 and RIGHT 1 are both high, turn on pin 13 and use a similar code to the LED blink?

and use a similar code to the LED blink?

To the blink without delay, you mean.

Pual

Beep 1 sec on 1 sec off is what I am trying to achieve, trying to create a code but getting no where.

trying to create a code but getting no where.

All I've seen is a 5 line snippet, with no context.

You really should start with a sketch that does nothing but make the thing make the kind of noise you want. Might even want to go simpler - make the thing make ANY kind of noise. At least that way, you'll know that the device is connected correctly, and can make (obnoxious) noises.

 case 'void' :pinMode(13, OUTPUT)

        ;digitalWrite(LEFT1, HIGH);
        digitalWrite(LEFT2, LOW);
        digitalWrite(RIGHT1, HIGH);
        digitalWrite(RIGHT2, LOW);
        break;

This what I wrote,I verified and uploaded it no problem but it dose not work.

The code i have converts the signal from a RC receiver in to signals a dual H bridge motor driver can use, control 2 DC motors on a radio controlled bulldozer i tried to post the whole code up it was to big.

case 'void' :pinMode(13, OUTPUT)

Single quotes are for single characters. Can you post a picture of your keyboard with the void key circled?

Is it

really

to much trouble

to put the complete

statement (INCLUDING the :wink: on ONE line? And NOT the same line as the case statement?

So Im guessing form your reply 'void 'should have some relevant information there instead or be written as "void"?

Please put URL tags on links. The forum doesn't do it automatically.

Here is the sketch I am using.RC Sketch

In a nut shell I am trying to insert the basic pin 13 LED blink sketch in to it, but only have it start when both motors are running in reverse.

Sorry, my phone can't open .ino files. There isn't enough code in the main article to guess what is wrong.

In a nut shell I am trying to insert the basic pin 13 LED blink sketch in to it, but only have it start when both motors are running in reverse.

First thing, is to follow PaulS's advice from reply #5. Write a simple sketch which does not use delay(), and runs the buzzer.

Look carefully at your code. You will see that the switch case for gDirection code only runs when the gDirection or gGear is changed, so you just can't put the buzzer function into the case DIRECTION_REVERSE as the code will not loop through that case.

Here's one way to work with that situation.

Set up a global boolean variable soundBackUpBuzzer and initialize it to false. Set it equal true in the DIRECTION_REVERSE case. Set it equal false, in all the other cases.

Then add a section to your code

if(soundBackUpBuzzer == true)
{
// run the non blocking code you wrote to sound the buzzer
}

Thank you, I will try that.

Ok,
I am now using a different motor driver and sketch DRV8835 to be exact, managed to edit a sketch found on line to convert the rx out put to the correct signal for the driver. Which i am very happy with by the way.

I have almost got a reversing buzzer working! I can switch on the led at pin 13 when in reverse, but also when turning left.

I have tried various combinations in the last 2 digitalwrite lines in sketch below which either have the LED on all the time or not on at all!

Some assistance would be greatly appreciated.

int thrPin = 2;
int ailPin = 3;
int leftPWMPin = 9;
int leftDirPin = 7;
int rightPWMPin = 10;
int rightDirPin = 8;
int buzzerPin= 13;
unsigned long thrLen, ailLen;

float thrPos, ailPos, rightVal, leftVal;

float clamp = 0.25;
int minLen = 1004;
int maxLen = 1976;

void setup()
{
pinMode(thrPin, INPUT);
pinMode(ailPin, INPUT);

pinMode(leftDirPin, OUTPUT);
pinMode(rightDirPin, OUTPUT);
pinMode(leftPWMPin, OUTPUT);
pinMode(rightPWMPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Hello world!"); 
}

void loop()
{
thrLen = pulseIn(thrPin, HIGH);
ailLen = pulseIn(ailPin, HIGH);
thrPos = ((float)thrLen-minLen)/(maxLen-minLen)*2 - 1;
ailPos = ((float)ailLen-minLen)/(maxLen-minLen)*2 - 1;
/*
Serial.println("throttle, aileron:");
Serial.println(thrLen);
Serial.println(ailLen);
*/
leftVal = min(max(thrPos - ailPos, -1), 1);
rightVal = min(max(thrPos + ailPos, -1), 1);

if (leftVal < clamp and leftVal > -clamp) leftVal = 0;
if (rightVal < clamp and rightVal > -clamp) rightVal = 0;

Serial.println("left, right");
Serial.println(leftVal);
Serial.println(rightVal);

digitalWrite(leftDirPin, leftVal < 0 ? HIGH : LOW);
analogWrite(leftPWMPin, abs(leftVal) * 255);
digitalWrite(rightDirPin, rightVal < 0 ? HIGH : LOW);
analogWrite(rightPWMPin, abs(rightVal) * 255);
digitalWrite(buzzerPin, leftVal < 0 ? HIGH :LOW );
digitalWrite(buzzerPin, rightVal < 0 ? HIGH :LOW);

delay(100);
}
digitalWrite(buzzerPin, leftVal < 0 ? HIGH :LOW );

digitalWrite(buzzerPin, rightVal < 0 ? HIGH :LOW);

The ternary operator is neat but you can use the assumption that HIGH is also the same as true. So when the comparison is true (HIGH) then you used the ternary to return HIGH.

Surely you want the reverse buzzer to be on when both left and right are negative, like, at the same time?

digitalWrite(buzzerPin, leftVal < 0 && rightVal < 0 );