Instructables

HELP! With Arduino coding.

Im working on a project to link 2 radios to make an em-comm repeater. I need the Arduino to preform the duty of the controller, and turn the transmitter on when a signal is received. I have all the sensors figured out, i just need help on the code, which il include at the end. if anyone can help, your name will be given kudos in the instructable, and will have my eternal gratitude!

The entire project only takes up 4 digital pins, which are the receiver senseor(sensePin), the transmiter key(trigPin), the busy led(busyPin) and the ready led(readyPin).

The idea is that when sensePin reads a HIGH state when a signal is received, it will set trigPin to HIGH, keying the transmitter, and set busyPin to HIGH, activating the BUSY indicator.At the end of this proccess, i would need a 3-5 second delay before the standby/ready sequence.
When sensePin is read as LOW, trigPin & busyPin would be set LOW and readyPin would be set HIGH, activating the READY indicator.

#define sensePin 13
#define trigPin 12
#define busyPin 11
#define readyPin 10

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(busyPin, OUTPUT);
pinMode(readyPin, OUTPUT);
pinMode(sensePin, INPUT);

}

void loop() {
if(sensePin, HIGH){digitalWrite(trigPin, HIGH); digitalWrite(busyPin, HIGH); digitalWrite(readyPin, LOW);
delay(5000);}
else {digitalWrite(trigPin, LOW); digitalWrite(busyPin, LOW); digitalWrite(readyPin, HIGH);}
if(sensePin,LOW){digitalWrite(trigPin, LOW); digitalWrite(busyPin, LOW); digitalWrite(readyPin, HIGH);}
else {digitalWrite(trigPin, HIGH); digitalWrite(busyPin, HIGH); digitalWrite(readyPin, LOW);}}

If anyone can figure this out, like i said,i would be eternally greatful!

KJ4ZVQ (author) 1 year ago
Thank you to everyone that replied! i just got done modifying and testing it out,and yall were right, the if(digitalRead(sensePin)==HIGH) line solved most of my problems.
You guys are AWESOME!!!!!
You don't say what's wrong with the code ?
KJ4ZVQ (author)  steveastrouk1 year ago
It just doesnt work. when i aplied voltage to sensepin, it didnt change any behavior
lewisb421 year ago
The first problem I see is you never actually read the sensePin. For example "if(sensePin, HIGH)" should actually be "if(digitalRead(sensePin)==HIGH)"

The other thing you need to remember is that once you set an output to HIGH or LOW it stays that way until you change it. Your logic suggests you may think you must continually refresh them. In fact, I think you can get rid of the entire second if-statement (everything from "if(sensePin,LOW)" on.
if(digitalRead(sensePin)==HIGH)

Could also be if(digitalRead(sensePin)) because the return value from digitalRead is always boolean.

Like wise you can have if(!digitalRead(sensePin))
Technically digitalRead() returns either HIGH or LOW as an int, not boolean, so it's possible (though not likely) sometime in the future HIGH could be re-defined to zero and LOW to something other than zero, in which case if(digitalRead(sensePin)) wouldn't work.

Too many years of thinking about maintainable software has driven me to thinking such mad thoughts...
It compiled. I haven't run it through my simulator yet.I shall return !!!!

My code looks prettier.....
gmoon1 year ago
While I'm not an Arudino user (prefer AVRGCC), I see you've defined sensePin as a constant, then feed that to your conditional statement.

So the two if statements read:

if (13, HIGH)
if (13, LOW)

And shouldn't if have only one argument, even in the Arduino version of C?

(after writing this, I see it's essentially what lewishb wrote before..)
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!