Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Cosmarino relay control- Simultaneously with Smart Phone App and Remote control
#include <IRremote.h>
const int irReceiverPin = 7;
const int relayPin = 2;
const int ledPin = 11;
IRrecv irrecv(irReceiverPin); //create an IRrecv object
decode_results decodedSignal; //stores results from IR sensor
void setup() {
pinMode(relayPin, OUTPUT);
pinMode(ledPin, OUTPUT);
irrecv.enableIRIn(); // Start the receiver object
boolean lightState = false; //keep track of whether the LED is on
unsigned long last = millis(); //remember when we last received an IRmessage
void loop(){
if (irrecv.decode(&decodedSignal) == true) //this is true if a message has been received
if (millis() - last > 250) { //has it been 1/4 sec since last message
lightState = !lightState; //toggle the LED
digitalWrite(relayPin, lightState);
digitalWrite(ledPin, lightState);
last = millis();
irrecv.resume(); // watch out for another message
if (Serial.available() > 0) {
int thisChar =;
// say what was sent:
Serial.print("You sent me: \'");
if (thisChar=='h')
digitalWrite(2, HIGH);
else {
digitalWrite(2, LOW);
Serial.print("\' ASCII Value: ");
Serial.println("Give me another byte:");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment