Hi everyone, I'm new at arduino
I'm trying to activate two relay using two potentiometers. While first potentiometer value bigger than the second one, first relay must be activate. While second potentiomer value bigger than the first one, the second relay must be activate. If the first potentiometer is equal the second potentiomer, relays must be stop.
But I couldn't this thing. I'm getting this error code ''too few arguments to function 'void digitalWrite(uint8_t, uint8_t)' '' Could you help me please?
Thanks for assistance.
I add fritzing sketch and codes.
int potB = 0;
int potR = 0 ;
int potBRIDGE = A1;
int potRUDDER = A2;
int relaySTBD = 5;
int relayPORT = 6;
void setup(){
pinMode(potBRIDGE, INPUT);
pinMode(potRUDDER, INPUT);
pinMode(relaySTBD, OUTPUT);
pinMode(relayPORT, OUTPUT);
}
void loop(){
potB=analogRead(potBRIDGE);
potB= map(potBRIDGE,0,1023,0,90);
potR=analogRead(potRUDDER);
potR= map(potRUDDER,0,1023,0,90);
if (potR>potB){
digitalWrite(relayPORT == LOW);
digitalWrite(relaySTBD == HIGH);
}
if (potR<potB) {
digitalWrite(relayPORT == LOW);
digitalWrite(relaySTBD == HIGH);
}[/b]
else }
digitalWrite(relayPORT == HIGH);
digitalWrite(relaySTBD == HIGH);
}
}
Moderator edit: </mark> <mark>[code]</mark> <mark>
For a start you have the same combination of high/low for both of the < and > cases (assuming you fixed the == vs , thing). Presumably one should be low/high and one high/low?
And your brace in the else is back to front: should be { not }
The complete sketch I gave in #4 ran perfectly for me, although I just have LEDs on the outputs not relays. It also worked for OP who found a wiring error so from #9 onwards, all is good.
kjp_Durgesh just clouded the issue by re-hashing stuff I pointed out to OP and fixed in #3 and #4. (And which you say you fixed in #10, but left errors.) Not sure why you even posted a "fix" in the post immediately after the one where the OP already said it was working. Because of that, posts #11, #12 and #13 are redundant since they relate to kjp_Durgesh's duff code not the OP's code which was fixed by #4 and "approved by the client" in #9.
@hsnhsynarslan maybe it would help if you edited the title in the first post and added [answered] or similar.
Hi everyone, thanks for attention. I fix the problem with @ard_guy suggestions. I had another problem witth potentiometer, because ı forget the pulldown in the potentiometers gnd side. Now everythings is okey but ı have still sensivity problem on the system. Could you suggest me anything possible in this issue?
hsnhsynarslan:
Now everythings is okey but ı have still sensivity problem on the system. Could you suggest me anything possible in this issue?
Well, you are mapping 1024 values to 90 values. That will reduce sensitivity. If all you care about is that the pots have the same value, then why map them down to 0-90? 90 is not a factor of 1024, so doing this will also introduce aliasing: "jagged edges" in the mapping.
If the problem is that the system is hunting when the pots are nearly at the same value, then you need to introduce a little tolerance and/or hysteresis. That is, if the statem is in once state, the pots have to be a little further along to shift to state B.
// tolerance is how close to zero the difference is to count as being zero
// tolerance 5 means that a difference of -9 to +9 counts as zero
const int TOLERANCE = 5;
// hysteresis is how "sticky" the system is. To change state, the difference
// has to exceed this value in the other direction
const int HYSTERESIS = 3;
hysteresis = 0;
void loop() {
int potB=analogRead(potBRIDGE);
int potR=analogRead(potRUDDER);
if (potR - potB + hysteresis >= TOLERANCE )
{
digitalWrite(relayPORT, LOW);
digitalWrite(relaySTBD, HIGH);
hysteresis = HYSTERESIS; // hysteresis
}
else if (potR - potB + hysteresis<= - TOLERANCE)
{
digitalWrite(relayPORT, LOW);
digitalWrite(relaySTBD, HIGH);
hysteresis = -HYSTERESIS; // hysteresis
}
else
{
digitalWrite(relayPORT, LOW);
digitalWrite(relaySTBD, LOW);
hysteresis = 0;
}
}