HI,
I am trying to control 2 different devices via IR. I am using the IRremote library, but I cannot find a solution to use 2 separate IR transmitters. The library only supports one sending pin (in the pin_definicions_and_more). But as my setup requires 2 IR transmitters with different IR protocolls (sendNEC and sendPanasonic) to control 2 different devices, I want to define another sending pin.
All the excamples I found about transmitting IR codes only support one device. But How can I send commands to multiple devices?
I am using an Arduino Uno WiFi Rev2. Attached is the Schematics of how I want to implement it.
Thanks in advance for suggestions!
Rafael
Using tags at tools bar " < code > ", post your atual code.
Also post the link to the IRremote library you are using.
PS:
Read tópic Sending IR codes ---> Send pin
" GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols
I am Using IRremote: GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols
It uses an extra file called PinDefinitionsAndMore.h, which depening on what HW you're using, the send pin. But I cannot find an option to define another send pin. Or disable the macro in the link you're posted.
Here's my code (containing a bit more stuff, that is irrelevant to my issue:
#include <Arduino.h>
#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc.
#include <IRremote.hpp>
#include <SPI.h>
#include <WiFiNINA.h>
#include <Arduino_JSON.h>
#include "arduino_secrets.h"
uint16_t sAddress = 0x2;
uint8_t sCommand = 0x1D;
uint8_t sRepeats = 2;
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS; // the WiFi radio's status
// Hue constants
const char hueHubIP[] = "192.168.0.199"; //Hue hub IP
const char hueUsername[] = "Vkkwl2UWz-VMl6JlCgpHBqotGxSgSTkeDAnO1cka"; //Hue username
const int hueHubPort = 80;
// Hue variables
int hueBri; // brightness value
long hueHue; // hue value
String hueCmd; // Hue command
unsigned long buffer=0; //buffer for received data storage
unsigned long addr;
//WiFi Client
WiFiClient client;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
IrSender.begin(); // Start with IR_SEND_PIN as send pin and if NO_LED_FEEDBACK_CODE is NOT defined, enable feedback LED at default feedback LED pin
Serial.print(F("Ready to send IR signals at pin "));
Serial.println(IR_SEND_PIN);
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
// you're connected now, so print out the data:
Serial.print("You're connected to the network");
printCurrentNet();
printWifiData();
delay(1000);
Serial.println(F("Startup sequence done!"));
}
void loop() {
Serial.println(F("*****************"));
Serial.println();
int inputValue = analogRead(A5);
float Vin = inputValue * (5.0 / 1023.0);
Serial.print("Input: ");
Serial.println(Vin);
Serial.println();
if (Vin <= 2) {
IrSender.sendNEC(sAddress, sCommand, sRepeats);
Serial.println(F("Power Off Teufel"));
Serial.println();
delay(2000);
String command = "{\"on\": false}";
setHue(17,command);
delay(20000);
}
else {
delay(200);
Serial.println(F("PC On"));
Serial.println();
delay(1000);
}
}
boolean setHue(int lightNum,String command)
{
if (client.connect(hueHubIP, hueHubPort))
{
while (client.connected())
{
client.print("PUT /api/");
client.print(hueUsername);
client.print("/lights/");
client.print(lightNum); // hueLight zero based, add 1
client.println("/state HTTP/1.1");
client.println("keep-alive");
client.print("Host: ");
client.println(hueHubIP);
client.print("Content-Length: ");
client.println(command.length());
client.println("Content-Type: text/plain;charset=UTF-8");
client.println(); // blank line before body
client.println(command); // Hue command
}
client.stop();
return true; // command executed
}
}
void printWifiData() {
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
Serial.println(ip);
// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC address: ");
printMacAddress(mac);
}
void printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
printMacAddress(bssid);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.println(rssi);
// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type:");
Serial.println(encryption, HEX);
Serial.println();
}
void printMacAddress(byte mac[]) {
for (int i = 5; i >= 0; i--) {
if (mac[i] < 16) {
Serial.print("0");
}
Serial.print(mac[i], HEX);
if (i > 0) {
Serial.print(":");
}
}
Serial.println();
}
ArminJo
January 19, 2024, 11:54pm
4
How do you think manage the universal remotes you can buy, the control of 2 devices with 1 diode?
system
Closed
July 17, 2024, 11:54pm
5
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.