I used VS1838 IR sensor for receiver. BUT the transmitting part failed.
Transmitter code:
/*
IR Transmitter Demonstration 1
IR-Xmit-Demo1.ino
Control TV using IR Library
IR LED must use Pin #3
DroneBot Workshop 2017
http://dronebotworkshop.com
*/
// Include IR Remote Library by Ken Shirriff
#include <IRremote.h>
// Define switch pin
const int switchPin = 7;
// Define a variable for the button state
int buttonState = 0;
// Create IR Send Object
IRsend irsend;
void setup()
{
// Set Switch pin as Input
pinMode(switchPin, INPUT);
}
void loop() {
// Set button state depending upon switch position
buttonState = digitalRead(switchPin);
// If button is pressed send power code command
if (buttonState == HIGH) {
irsend.sendNEC(0xFEA857, 32); // TV power code
}
// Add a small delay before repeating
delay(200);
}
Receiver code:
// Include IR Remote Library by Ken Shirriff
#include <IRremote.h>
// Define sensor pin
const int RECV_PIN = 4;
// Define IR Receiver and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup(){
// Serial Monitor @ 9600 baud
Serial.begin(9600);
// Enable the IR Receiver
irrecv.enableIRIn();
}
void loop(){
if (irrecv.decode(&results)){
// Print Code in HEX
Serial.println(results.value, HEX);
irrecv.resume();
}
}
You missed that this sensor is more than a simple photo diode. You have to use the IRremote library to send RAW data, then it works. Or use a simple receiver diode as shown in the reference.
I moved your topic to an appropriate forum category @john1n.
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
use INPUT_PULLUP for your button input and rewire the switch between the input pin and ground. Get rid of the resistor on the switch. Test for digitalRead(_) == LOW in your code for button pressed.
There may be other issues, but that should be a start.
Hi,
I already checked the functionality of switch by putting print function in "If" block. The problem is not from the switch as Serial.println("Here") prints "Here" after pushing button.