Send IR values using infrared emitter led on Arduino - arduino

i have Arduino Mega and an IR Emitting LED and i want to send data "Hex Data" that i choose using this LED and i have tried the IRRemote Library and i have successfully used the IRrecv class, but when using IRsend i didn't get any signal and have tried to look at the led through the mobile camera
the IR Emitter Pin is PWM 3 and have connected it to 3.3V once and to 5V once
#include <IRremote.h>
IRsend irsend;
void setup()
{
Serial.begin(9600);
}
void loop() {
if (Serial.read() != -1) {
for (int i = 0; i < 3; i++) {
irsend.sendSony(0xa90, 12); // Sony TV power code
delay(40);
}
}
}
and for the receiver:
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}
any help is appreciated :) Hiso

i Have looked at the IRRemote.cpp library you refereed to and in the header file you can see that each Arduino board have a unique PWM pin that is used to transmit infrared data so use PWM 9 it's assured to work on Arduino Mega

Related

Arduino IRremote Send and Receive simultaneously

I'm currently working on a lasertag game with several weapons.
I would like to use one arduino nano in each weapon. It should be able to receive the IR-signals of the opponents as well as send IR-signals if a button is triggered.
So now there comes my problem:
I implemented an interrupt for the IR-receiver pin, so that an opponent's shot is always detected even when I'm shooting.
When the button is permanently pressed, the IR LED will shoot every 300 milliseconds (the send-function takes approximately 70ms and I implemented a delay of 230ms).
Unfortunately, the Nano won't detect any signal of the receiver in those 300ms.
However, if I disconnect the IR-LED everything seems to work perfectly.
Now I'm wondering, why the IR-LEDs connection has an effect on the functionality of my code.
Do you know any way I could solve this problem?
Here you can see the entire code I implemented:
#define IR_SEND_PIN 3
#define BUTTON_PIN 10
#define LED_PIN 12
#include <IRremote.hpp>
#include <Arduino.h>
uint8_t sAddress = 0;
uint8_t sCommand = 0x59;
uint8_t sRepeats = 0;
volatile uint8_t hitData;
void setup() {
IrSender.begin();
IrReceiver.begin(IR_RECEIVE_PIN);
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(IR_RECEIVE_PIN), HIT, CHANGE);
}
void HIT() {
if (IrReceiver.decode()) {
hitData = IrReceiver.decodedIRData.command;
}
IrReceiver.resume();
}
void loop() {
if (digitalRead(BUTTON_PIN) == LOW) {
IrSender.sendNEC(sAddress, sCommand, sRepeats);
delay(120);
}
if (hitData == sCommand) { // indicates received signal 0x59
hitData = 0x00;
IrReceiver.resume();
digitalWrite(LED_PIN, HIGH);
delay(8);
digitalWrite(LED_PIN, LOW);
}
}```

How to send orders from Arduino to Esp32 and make it keypress

I need to send orders from Arduino to ESP32.
I have one joystick button to test.
Arduino nano is sender
Esp32 is receiver
Esp32 receives the joystick button information from Arduino (each time I push the button).
I need the Esp32 to Serial.write according to the data, for example:
If I press the button in Arduino: Send the data to Esp32 and turn bluetooth on (or turn a led on).
These are my codes:
//Arduino NANO sender
byte j = 45;
#define boton_joystick A1
void setup() {
Serial.begin(9600);
pinMode(boton_joystick, INPUT_PULLUP);
}
int boton_joystick_state;
void loop() {
//Serial.println("100");
//Serial.write("BOTON EN GRANDE");
//delay(1500);
if(!digitalRead(boton_joystick)) {
boton_joystick_state = 1;
delay(170);
} else {
boton_joystick_state = 0;
}
if (boton_joystick_state) {
Serial.println(j);
Serial.print(" ");
Serial.write(j);
Serial.println();
}
//ESP-32 receiver
#define RXD2 16
#define TXD2 17
byte j = 45;
int comdata;
void setup() {
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
}
void loop() {
//Serial.print("LEYENDO ARDUINO");
Serial.println(Serial2.readString());
if (Serial2.available() >0) {
char comdata = char(Serial2.read());
if (comdata == 'j') {
Serial.println("joystick activado");
}
}
}
am not sure
but am using Nano 33 BLE with UART and Nano has also Serial1 no need to serial2 no need to Softwearserial. Sensd on serial 1 and recive in Serial 1 but also you have to connect it Via USB. so your serial is USB and your serial 1 is TX RX.
for me it work so you can try it.

Arduino sleep while digital pin is HIGH

I want to make the Arduino Pro Mini run on a 3.7v (4.2v when fully charged) LI-Ion battery.
The project is I will use an IR sensor to control the relay. Based on the IR code received, I will toggle the relay digital output pin (HIGH or LOW). Initially, the arduino is set to deep sleep mode and when it receives an External Interrupt (pin 2 on pro-mini), it will process the IR code and switch on the relay.
//Interrupts using Arduino
//Circuit Digest
#include "LowPower.h"
#include <IRremote.h>
volatile int output = LOW;
int i = 0;
#define RECV_PIN 2
volatile boolean sleepEnabled = true;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
irrecv.enableIRIn();
pinMode(RECV_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(RECV_PIN), buttonPressed1, RISING); // function for creating external interrupts at pin2 on Rising (LOW to HIGH)
}
void loop()
{
Serial.println(i);
++i;
delay(1000);
output = LOW;
digitalWrite(13, output); //Turns LED ON or OFF depending upon output value
if (sleepEnabled == true) {
Serial.println("Going to sleep");
delay(1000);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
}
delay(500);
readIR();
}
void buttonPressed1() //ISR function excutes when push button at pinD2 is pressed
{
sleepEnabled = false;
}
void readIR() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
if (results.value == 0xff4ab5) {
sleepEnabled = true;
}
}
irrecv.resume(); // Receive the next value
}
When the pro-mini goes back to sleep, everything is turned off.
How can I make the pro-mini consume minimal power while the relay pin is HIGH ?

serial communication between Arduino and Nodemcu

I'm trying to read voltage value using Analog pin A0 in arduino uno and transmit the read voltage to Nodemcu but not getting same voltage at NodeMcu as on Arduino side for Ex. for 5 volt at Arduino i get only 4 volt at Nodemcu.
i have made the delay of both the sketches equal even tried without any delay
also tried connecting the ground pin of both device
ARDUINO CODE
#include <SoftwareSerial.h>
SoftwareSerial s(5,6);
void setup() {
s.begin(9600);
Serial.begin(9600);
}
void loop() {
// read the input on analog pin 0:
int ADCdata = analogRead(A0);
float voltage = (ADCdata * 0.0048828125);
Serial.println(ADCdata);
Serial.println(voltage);
if(s.available()>0)
{
s.write(voltage);
}
delay(1000);
}
NODEMCU CODE
#include <SoftwareSerial.h>
SoftwareSerial s(D6,D5);
void setup() {
s.begin(9600);
Serial.begin(9600);
}
void loop() {
s.write("s");
if (s.available()>0)
{
data=s.read();
Serial.println(data);
}
delay(1000);
}
I would send the float data as a string:
s.println(value)
This will append a newline to mark the end of the string.
On the receiving side, read the line and convert to float.
float value = s.parseFloat();

Arduino & Processing 3: "Dimmer" Built-In Example

Okay, so I'm using an Arduino Uno on a Windows 10 PC, as well as Processing 3. I'm attempting to follow the directions on the Arduino website for controlling the brightness of an LED by moving my across the PC screen, by having the Arduino software cooperate w/ Processing. (Here's the link to the project I'm talking about: https://www.arduino.cc/en/Tutorial/Dimmer) It seems so simple, yet it's not quite working. The LED will glow, but its brightness won't vary with the mouse's X position, and its glow is flickering. I get no error codes.
As regards the circuit, I have an LED connected to PWM pin 9, with a 200-ohm resistor to ground; I am certain that the polarity of the LED is correctly set up. The website isn't clear how exactly Processing & the Arduino software should collaborate to make this happen. (So I would greatly appreciate an explanation thereof if possible.) The Arduino & Processing codes are below. I don't understand what I'm doing wrong?
Here is my Arduino code:
const int ledPin = 9; // the pin that the LED is attached to
void setup() {
// initialize the serial communication:
Serial.begin(9600);
// initialize the ledPin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
byte brightness;
// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
brightness = Serial.read();
// set the brightness of the LED:
analogWrite(ledPin, brightness);
}
}
Here's my Processing code:
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
void setup() {
size(256, 150);
arduino = new Arduino(this, "COM3", 9600);
}
void draw() {
background(constrain(mouseX, 0, 255));
arduino.analogWrite(9, constrain(mouseX, 0, 255)); //
}
For those of you who wish to know, here is my functional code:
Arduino portion:
const int ledPin = 9; // the pin that the LED is attached to
void setup() {
// initialize the serial communication:
Serial.begin(9600);
// initialize the ledPin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
int brightness;
// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
brightness = Serial.read();
// set the brightness of the LED:
analogWrite(9, brightness);
}
delay(10);
}
Processing portion (on Processing 3):
import processing.serial.*;
import cc.arduino.*;
Serial arduino;
void setup() {
size(256, 150);
arduino = new Serial(this, "COM3", 9600);
}
void draw() {
background(constrain(mouseX, 0, 255));
arduino.write(constrain(mouseX, 0, 255)); //
}

Resources