So i have been building a system and tested the code individually and i have checked wiring and it all worked individually i am also not getting any errors but the system isn't working and i was just wondering if it was the code that was the problem any help would be appreciated
#include <IRremote.h>
const int RELAY_PIM = 10;
int IR_Recv = 2; //IR Receiver Pin 2
int LED_PIN = 13;
int inPin = 8;
//when running=1, the liquid is detected, print out 1, otherwise, print out 0; running=0, the liquid is detected, print out 0, otherwise, print out 1.
int modePin = 9;
boolean running = 0;
IRrecv irrecv(IR_Recv);
decode_results results;
int a = 0;
void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600); //starts serial communication
irrecv.enableIRIn(); // Starts the receiver
pinMode(inPin, INPUT);
pinMode(modePin, OUTPUT);
digitalWrite(modePin, running);
pinMode(13, OUTPUT);
irrecv.blink13(true);
}
void loop() {
Serial.println(digitalRead(inPin));
if (irrecv.decode(&results)) {
Serial.print(results.value);
Serial.print(",");
Serial.println("");
irrecv.resume();
long int decCode = results.value;
Serial.println(decCode);
if (results.value == 16580863) {
a = a + 1;
}
if (a == 1) {
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
a = 0;
}
}
irrecv.resume();
if (results.value == 16613503) {
digitalWrite(10, HIGH);
digitalWrite(13, HIGH);
delay(5000);
digitalWrite(10, LOW);
}
if (results.value == 16597183) { //Select button 600ml
digitalWrite(10, HIGH);
digitalWrite(13, HIGH);
delay(10000);
digitalWrite(10, LOW);
}
irrecv.resume();
}
so i basicacly is a ir remote that sends a signal to a relay which turn on for x amount of time. thats pin 10. then ou have pin 13 which is lights, and pin 2 is the ir recv. u also have a senosor which is a non contact liquid level sensor that when its 0 it detects water 1 it doesn't
Changing the format does not really change your code. It makes it easier human readable.
Your nested if's will be easier to check.
That is why you should post your code after formatting. I see you changed the code in your original post. That will make this thread hard to follow...
Should all this only be checked after reading what the receiver has received?
Is blocking code. Once inside this if, your code will not respond to the irremote for 10 seconds...
Here you read the latest message from the receiver.
If there is a message, the first if ischevked.
The other if blocks are also tested if there is no new message..
Move the blocks inside the if block were you read the message...
Basically remove one of }}
And add one } at end. Then ctrl-t...
Then paste code again in new post
What is this supposed to do?
I am not familiar with your ir library...
I would expect that one call in loop should be sufficient.
Bu maybe it is not needed at all, since you did not stop or pause receiving... so what is the use of resume?