yes thats right. i do not know what kind of correct instruction to make this relay work properly. because i am really blank with irremote ver 3.x, could you please once more to write the correct one? thank you
Your program "logic" is in no way connect to the version of the IR library,
that is a very lame excuse.
sorry you feel like that, what should i do then?
Change the logic to something that does what you want-
I don't have a clue what most your commands
{0xE619FF00, "NOL"},
{0xBA45FF00, "SATU"},
{0xB946FF00, "DUA"},
{0xB847FF00, "TIGA"},
{0xBB44FF00, "EMPAT"},
{0xBF40FF00, "LIMA"},
{0xBC43FF00, "ENAM"},
{0xF807FF00, "TUJUH"},
{0xEA15FF00, "DELAPAN"},
{0xF609FF00, "SEMBILAN"},
{0xE916FF00, "BINTANG"},
are supposed to mean.
When do you want the relay to turn on and when do you want it to turn off?
its ok, may be i use irremote library version 2.6.1 only. more comfortable for me. any way thank you for supporting me in this problem. i will close this issue. thank you
This will not fix your crooked logic, just saying.
here are my latest code :
#include <IRremote.h>
int IRpin = 4;
String kodeKu;
struct kode
{
uint32_t kodeValue;
const char * ku;
} KodeList[] =
{
{0xE619FF00, "NOL"},
{0xBA45FF00, "SATU"},
{0xB946FF00, "DUA"},
{0xB847FF00, "TIGA"},
{0xBB44FF00, "EMPAT"},
{0xBF40FF00, "LIMA"},
{0xBC43FF00, "ENAM"},
{0xF807FF00, "TUJUH"},
{0xEA15FF00, "DELAPAN"},
{0xF609FF00, "SEMBILAN"},
{0xE916FF00, "BINTANG"},
{0xEF20DFF00, "PAGAR"},
{0xE718FF00, "UP"},
{0xAD52FF00, "DOWN"},
{0xA55AFF00, "FORWARD"},
{0xF708FF00, "REWIND"},
{0xE31CFF00, "OK"},
};
const char * GetKodeKu(uint32_t kode)
{
size_t kuCount = sizeof KodeList / sizeof KodeList[0];
for (size_t i = 0; i < kuCount; i++)
{
if (KodeList[i].kodeValue == kode)
{
Serial.print("Recognized as ");
Serial.println(KodeList[i].ku);
return KodeList[i].ku;
}
}
Serial.println("Kode Not Recognized");
return "";
}
const int relayPin = 7;
bool OK_State=LOW;
const int motor1pin1 = 8; //in1 motor1
const int motor1pin2 = 12; //in2 motor1
const int motor1pin3 = 11; //enable motor1
int mSpeed1 = 100;
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
delay(200);
Serial.println("setup()");
IrReceiver.begin(IRpin);
pinMode (relayPin, OUTPUT);
pinMode(motor1pin1, OUTPUT); //in1 pin motor1
pinMode(motor1pin2, OUTPUT); //in2 pin motor1
pinMode(motor1pin3, OUTPUT); //enable pin motor1
}
void loop()
{
Serial.println("loop()");
// put your main code here, to run repeatedly:
while (IrReceiver.decode() == 0);
unsigned long value = IrReceiver.decodedIRData.decodedRawData;
Serial.print("Received: ");
Serial.println(value, HEX);
IrReceiver.resume();
IrReceiver.enableIRIn();
kodeKu = GetKodeKu(value);
if (kodeKu == "OK"){
digitalWrite(relayPin,!digitalRead(relayPin));
}
if (kodeKu == "SATU") {
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
analogWrite(motor1pin3, 50);
}
if (kodeKu == "DUA") {
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, LOW);
analogWrite(motor1pin3, 0);
}
if (kodeKu == "UP") {
mSpeed1 = mSpeed1 + 10;
if (mSpeed1 > 255) {
mSpeed1 = 255;
}
analogWrite(motor1pin3, mSpeed1);
}
if (kodeKu == "DOWN") {
mSpeed1 = mSpeed1 - 10;
if (mSpeed1 < 0) {
mSpeed1 = 0;
}
analogWrite(motor1pin3, mSpeed1);
}
}
during compiling igot message :
C:\Users\Deli\Documents\Arduino\Sketch\remote_relay1\remote_relay1.ino:28:1: warning: narrowing conversion of '64190545664' from 'long long int' to 'uint32_t {aka long unsigned int}' inside { } [-Wnarrowing]
};
^
C:\Users\Deli\Documents\Arduino\Sketch\remote_relay1\remote_relay1.ino:28:1: warning: large integer implicitly truncated to unsigned type [-Woverflow]
Sketch uses 11272 bytes (34%) of program storage space. Maximum is 32256 bytes.
Global variables use 711 bytes (34%) of dynamic memory, leaving 1337 bytes for local variables. Maximum is 2048 bytes.
then after uploading i got messaga:
C:\Users\Deli\Documents\Arduino\Sketch\remote_relay1\remote_relay1.ino:28:1: warning: narrowing conversion of '64190545664' from 'long long int' to 'uint32_t {aka long unsigned int}' inside { } [-Wnarrowing]
};
^
C:\Users\Deli\Documents\Arduino\Sketch\remote_relay1\remote_relay1.ino:28:1: warning: large integer implicitly truncated to unsigned type [-Woverflow]
Sketch uses 11272 bytes (34%) of program storage space. Maximum is 32256 bytes.
Global variables use 711 bytes (34%) of dynamic memory, leaving 1337 bytes for local variables. Maximum is 2048 bytes.
there is a warning , what is it means?
then when I press button to activate motor control (button names with "SATU") after that just stuck and hang. nothing respons from any button.
any suggestion, where is my coding mistake?
thank you
{0xEF20DFF00, "PAGAR"},
This line has more digits than will fit in an 32-bit unsigned long.
Looks like it should be:
{0xF20DFF00, "PAGAR"},
Aside from that one warning, you sketch compiles without errors or warnings.
This is how I would have written it:
#include <IRremote.h>
const int IRpin = 4;
const int relayPin = 7;
const int motor1pin1 = 8; //in1 motor1
const int motor1pin2 = 12; //in2 motor1
const int motor1pin3 = 11; //enable motor1
// IRremote button values
const uint32_t RBV_NOL = 0xE619FF00;
const uint32_t RBV_SATU = 0xBA45FF00;
const uint32_t RBV_DUA = 0xB946FF00;
const uint32_t RBV_TIGA = 0xB847FF00;
const uint32_t RBV_EMPAT = 0xBB44FF00;
const uint32_t RBV_LIMA = 0xBF40FF00;
const uint32_t RBV_ENAM = 0xBC43FF00;
const uint32_t RBV_TUJUH = 0xF807FF00;
const uint32_t RBV_DELAPAN = 0xEA15FF00;
const uint32_t RBV_SEMBILAN = 0xF609FF00;
const uint32_t RBV_BINTANG = 0xE916FF00;
const uint32_t RBV_PAGAR = 0xF20DFF00;
const uint32_t RBV_UP = 0xE718FF00;
const uint32_t RBV_DOWN = 0xAD52FF00;
const uint32_t RBV_FORWARD = 0xA55AFF00;
const uint32_t RBV_REWIND = 0xF708FF00;
const uint32_t RBV_OK = 0xE31CFF00;
int mSpeed1 = 100;
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
delay(200);
Serial.println("setup()");
IrReceiver.begin(IRpin);
pinMode (relayPin, OUTPUT);
pinMode(motor1pin1, OUTPUT); //in1 pin motor1
pinMode(motor1pin2, OUTPUT); //in2 pin motor1
pinMode(motor1pin3, OUTPUT); //enable pin motor1
}
void loop()
{
Serial.println("loop()");
// Wait until a successful receive
while (IrReceiver.decode() == 0);
unsigned long value = IrReceiver.decodedIRData.decodedRawData;
Serial.print("Received: ");
Serial.println(value, HEX);
IrReceiver.resume();
IrReceiver.enableIRIn();
switch (value)
{
case RBV_OK:
// Toggle relay pin
digitalWrite(relayPin, !digitalRead(relayPin));
break;
case RBV_SATU:
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
analogWrite(motor1pin3, 50);
break;
case RBV_DUA:
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, LOW);
analogWrite(motor1pin3, 0);
break;
case RBV_UP:
mSpeed1 += 10;
if (mSpeed1 > 255)
mSpeed1 = 255;
analogWrite(motor1pin3, mSpeed1);
break;
case RBV_DOWN:
mSpeed1 -= 10;
if (mSpeed1 < 0)
mSpeed1 = 0;
analogWrite(motor1pin3, mSpeed1);
break;
default:
Serial.println("UNRECOGNIZED");
break;
}
}
sorry for the delaying repply. program compile and upload success. no more hang. the program i put as below.
I still put names of remote code (kodeKu). the fuction of it is if i press remote button , i can uderstand the remote code along with button names in serial monitor. buttons function as per expected and appeared in serial monitor.
FYI: i connect arduino uno board out to motor driver L298N for controlling speed an direction dc motors.
relay is for controlling power on / off only.
i add some code :
digitalWrite(motor1pin1, HIGH), !digitalRead(motor1pin1); //setting motor1 on and off
the fucntion of the code is for controlling motor1 on and off individually. Can i use it here?
#include <IRremote.h>
int IRpin = 4;
String kodeKu;
struct kode
{
uint32_t kodeValue;
const char * ku;
} KodeList[] =
{
{0xE619FF00, "zero"},
{0xBA45FF00, "one"},
{0xB946FF00, "two"},
{0xB847FF00, "three"},
{0xBB44FF00, "four"},
{0xBF40FF00, "five"},
{0xBC43FF00, "six"},
{0xF807FF00, "seven"},
{0xEA15FF00, "eight"},
{0xF609FF00, "nine"},
{0xE916FF00, "star"},
{0xF20DFF00, "hashtag"},
{0xE718FF00, "UP"},
{0xAD52FF00, "DOWN"},
{0xA55AFF00, "FORWARD"},
{0xF708FF00, "REWIND"},
{0xE31CFF00, "OK"},
};
const char * GetKodeKu(uint32_t kode)
{
size_t kuCount = sizeof KodeList / sizeof KodeList[0];
for (size_t i = 0; i < kuCount; i++)
{
if (KodeList[i].kodeValue == kode)
{
Serial.print("Recognized as ");
Serial.println(KodeList[i].ku);
return KodeList[i].ku;
}
}
Serial.println("Kode Not Recognized");
return "";
}
const int relayPin = 7;
const int motor1pin1 = 11; //in1 motor1
const int motor1pin2 = 12; //in2 motor1
const int motor1pin3 = 8; //enable motor1
int mSpeed1 = 50;
bool OK_State = LOW;
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
delay(200);
Serial.println("setup()");
IrReceiver.begin(IRpin);
pinMode (relayPin, OUTPUT);
pinMode(motor1pin1, OUTPUT); //in1 pin motor1
pinMode(motor1pin2, OUTPUT); //in2 pin motor1
pinMode(motor1pin3, OUTPUT); //enable pin motor1
IrReceiver.enableIRIn();
}
void loop()
{
Serial.println("loop()");
// put your main code here, to run repeatedly:
while (IrReceiver.decode() == 0);
unsigned long value = (IrReceiver.decodedIRData.decodedRawData);
Serial.print("Received: ");
Serial.println(value, HEX);
IrReceiver.resume();
kodeKu = GetKodeKu(value);
//"OK_btn" function
if (kodeKu == "OK") {
digitalWrite(relayPin, !digitalRead(relayPin));
}
switch (value) {
case1: 0xBA45FF00; //motor1 power on/off speed=0 ("one_btn")
***digitalWrite(motor1pin1, HIGH), !digitalRead(motor1pin1); //setting motor1 on and off***
digitalWrite(motor1pin2, LOW);
analogWrite(motor1pin3, mSpeed1);
break;
case2: 0xB946FF00; //motor 1 direction (two_btn)
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, HIGH);
break;
case3: 0xE718FF00;//motor1 speed up (up_btn)
Serial.println("UP");
mSpeed1 += 10;
if (mSpeed1 > 255) mSpeed1 = 255;
analogWrite(motor1pin3, mSpeed1);
break;
case4: 0xAD52FF00;// motor1 speed down (down_btn)
Serial.println("DOWN");
mSpeed1 += 10;
if (mSpeed1 < 0) mSpeed1 = 0;
analogWrite(motor1pin3, mSpeed1);
break;
}
}
The comma is acting like a semicolon. What the compiler sees is:
digitalWrite(motor1pin1, HIGH);
!digitalRead(motor1pin1);
That does the same as:
digitalWrite(motor1pin1, HIGH);
(Since reading a pin and not using the result is as useful as not doing anything.)
I think what you intended to write was:
digitalWrite(motor1pin1, !digitalRead(motor1pin1)); //setting motor1 on and off
That will toggle motor1pin1.
ok thank you Mr. Wasser.
after struggling with the code, now i am facing problem that motor can not run because after i checked that no output at all at uno pin (in this case they are pin 8,12 for run motor and 11 for speed control pulse.). I did measure of pin out by doing voltage measurement only. it should be around 5vdc. I tried replace the uno board also, same thing happen. any suggestion? thank you
thank you all arduino forum.
Hello Mr. Wasser,
i have another problem with the code. first of all when i upload the code below , it is running normal. i can adjust and set rotation , direction and speed of dc motor. :
int motor1pin1 = 8; //in1 motor1
int motor1pin2 = 12; //in2 motor1
int motor1pin3 = 11; //enable motor1
int mSpeed1 = 50;
int motor2pin1 = A0; //in1 motor2
int motor2pin2 = A1; //in2 motor2
int motor2pin3 = 10; //enable motor2
int mSpeed2 = 50;
void setup() {
// put your setup code here, to run once:
pinMode(motor1pin1, OUTPUT); //in1 pin motor1
pinMode(motor1pin2, OUTPUT); //in2 pin motor1
pinMode(motor1pin3, OUTPUT); //enable pin motor1
pinMode(motor2pin1, OUTPUT); //in1 pin motor2
pinMode(motor2pin2, OUTPUT); //in2 pin motor2
pinMode(motor2pin3, OUTPUT); //enable pin motor2
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
analogWrite(motor1pin3, mSpeed1);
digitalWrite(motor2pin1, HIGH);
digitalWrite(motor2pin2, LOW);
analogWrite(motor2pin3, mSpeed2);
}
but when i add code irremote on that sketch , it was not working. motor can not controlled at all. i change ir sensor and remote with new one, the problem same as before. any suggestion or idea to solve this problem? the code with irremote as below. thank you.
#include <IRremote.h>
int IRpin = 4;
String kodeKu;
struct kode
{
uint32_t kodeValue;
const char * ku;
} KodeList[] =
{
{0xE619FF00, "zero"},
{0xBA45FF00, "one"},
{0xB946FF00, "two"},
{0xB847FF00, "three"},
{0xBB44FF00, "four"},
{0xBF40FF00, "five"},
{0xBC43FF00, "six"},
{0xF807FF00, "seven"},
{0xEA15FF00, "eight"},
{0xF609FF00, "nine"},
{0xE916FF00, "star"},
{0xF20DFF00, "hashtag"},
{0xE718FF00, "UP"},
{0xAD52FF00, "DOWN"},
{0xA55AFF00, "FORWARD"},
{0xF708FF00, "REWIND"},
{0xE31CFF00, "OK"},
};
const char * GetKodeKu(uint32_t kode)
{
size_t kuCount = sizeof KodeList / sizeof KodeList[0];
for (size_t i = 0; i < kuCount; i++)
{
if (KodeList[i].kodeValue == kode)
{
Serial.print("Recognized as ");
Serial.println(KodeList[i].ku);
return KodeList[i].ku;
}
}
Serial.println("Kode Not Recognized");
return "";
}
const int motor1pin1 = 8; //in1 motor1
const int motor1pin2 = 12; //in2 motor1
const int motor1pin3 = 11; //enable motor1
int mSpeed1 = 50;
const int motor2pin1 = A0; //in1 motor2
const int motor2pin2 = A1; //in2 motor2
const int motor2pin3 = 10; //enable motor2
int mSpeed2 = 50;
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
delay(200);
Serial.println("setup()");
IrReceiver.begin(IRpin);
pinMode(motor1pin1, OUTPUT); //in1 pin motor1
pinMode(motor1pin2, OUTPUT); //in2 pin motor1
pinMode(motor1pin3, OUTPUT); //enable pin motor1
pinMode(motor2pin1, OUTPUT); //in1 pin motor2
pinMode(motor2pin2, OUTPUT); //in2 pin motor2
pinMode(motor2pin3, OUTPUT); //enable pin motor2
IrReceiver.enableIRIn();
}
void loop()
{
Serial.println("loop()");
// put your main code here, to run repeatedly:
while (IrReceiver.decode() == 0);
unsigned long value = (IrReceiver.decodedIRData.decodedRawData);
Serial.print("Received: ");
Serial.println(value, HEX);
IrReceiver.resume();
kodeKu = GetKodeKu(value);
switch (value) {
case1: 0xBA45FF00;//motor1 power on/off speed=0 ("one_btn")
digitalWrite(motor1pin1,HIGH);//setting motor1 on and off
digitalWrite(motor1pin2, LOW);
analogWrite(motor1pin3, mSpeed1);
break;
case2: 0xE718FF00;//motor1 speed up (up_btn)
Serial.println("UP");
mSpeed1 += 10;
if (mSpeed1 > 255) mSpeed1 = 255;
analogWrite(motor1pin3, mSpeed1);
break;
case3: 0xAD52FF00;// motor1 speed down (down_btn)
Serial.println("DOWN");
mSpeed1 -= 10;
if (mSpeed1 < 0) mSpeed1 = 0;
analogWrite(motor1pin3, mSpeed1);
break;
case4: 0xBB44FF00;//motor2 power on speed 0 "four_btn"
digitalWrite(motor2pin1, !digitalRead(motor2pin1));
digitalWrite(motor2pin2, LOW);
analogWrite(motor2pin3, mSpeed2);
break;
case5: 0xA55AFF00;//motor2 speed up (FORWARD_btn)
Serial.println("FORWARD");
mSpeed2 += 10;
if (mSpeed2 > 255) mSpeed2 = 255;
analogWrite(motor2pin3, mSpeed2);
break;
case6: 0xF708FF00;// motor2 speed down (REWIND_btn)
Serial.println("REWIND");
mSpeed1 -= 10;
if (mSpeed2 < 0) mSpeed2 = 0;
analogWrite(motor2pin3, mSpeed2);
break;
}
}
Your sketch says you are using Pin 8 for both 'motor1pin1' and 'IRpin'. That is not going to work.
sorry actually pin 4 for irremote. not working
What shows up on Serial Monitor?
Did you not notice all of these warning messages telling you that you were doing the 'switch/case' statement wrong? Look up how to write a 'switch/case' statement correctly.
/Users/john/Documents/Arduino/sketch_oct25a/sketch_oct25a.ino: In function 'void loop()':
/Users/john/Documents/Arduino/sketch_oct25a/sketch_oct25a.ino:89:24: warning: statement has no effect [-Wunused-value]
case1: 0xBA45FF00;//motor1 power on/off speed=0 ("one_btn")
^
/Users/john/Documents/Arduino/sketch_oct25a/sketch_oct25a.ino:95:24: warning: statement has no effect [-Wunused-value]
case2: 0xE718FF00;//motor1 speed up (up_btn)
^
/Users/john/Documents/Arduino/sketch_oct25a/sketch_oct25a.ino:102:24: warning: statement has no effect [-Wunused-value]
case3: 0xAD52FF00;// motor1 speed down (down_btn)
^
/Users/john/Documents/Arduino/sketch_oct25a/sketch_oct25a.ino:109:24: warning: statement has no effect [-Wunused-value]
case4: 0xBB44FF00;//motor2 power on speed 0 "four_btn"
^
/Users/john/Documents/Arduino/sketch_oct25a/sketch_oct25a.ino:115:24: warning: statement has no effect [-Wunused-value]
case5: 0xA55AFF00;//motor2 speed up (FORWARD_btn)
^
/Users/john/Documents/Arduino/sketch_oct25a/sketch_oct25a.ino:122:24: warning: statement has no effect [-Wunused-value]
case6: 0xF708FF00;// motor2 speed down (REWIND_btn)
^
/Users/john/Documents/Arduino/sketch_oct25a/sketch_oct25a.ino:89:7: warning: label 'case1' defined but not used [-Wunused-label]
case1: 0xBA45FF00;//motor1 power on/off speed=0 ("one_btn")
^~~~~
/Users/john/Documents/Arduino/sketch_oct25a/sketch_oct25a.ino:95:7: warning: label 'case2' defined but not used [-Wunused-label]
case2: 0xE718FF00;//motor1 speed up (up_btn)
^~~~~
/Users/john/Documents/Arduino/sketch_oct25a/sketch_oct25a.ino:102:7: warning: label 'case3' defined but not used [-Wunused-label]
case3: 0xAD52FF00;// motor1 speed down (down_btn)
^~~~~
/Users/john/Documents/Arduino/sketch_oct25a/sketch_oct25a.ino:109:7: warning: label 'case4' defined but not used [-Wunused-label]
case4: 0xBB44FF00;//motor2 power on speed 0 "four_btn"
^~~~~
/Users/john/Documents/Arduino/sketch_oct25a/sketch_oct25a.ino:115:7: warning: label 'case5' defined but not used [-Wunused-label]
case5: 0xA55AFF00;//motor2 speed up (FORWARD_btn)
^~~~~
/Users/john/Documents/Arduino/sketch_oct25a/sketch_oct25a.ino:122:7: warning: label 'case6' defined but not used [-Wunused-label]
case6: 0xF708FF00;// motor2 speed down (REWIND_btn)
^~~~~
it was success compile and upload . no showing error at all.
Sketch uses 10654 bytes (33%) of program storage space. Maximum is 32256 bytes.
Global variables use 703 bytes (34%) of dynamic memory, leaving 1345 bytes for local variables. Maximum is 2048 bytes.