Thursday, August 1, 2013

Adafruit's Simple RF receiver, Testing on an Arduino

I just picked up Adafruit's Simple RF receiver right now I was testing the Momentary type (M4) Which means that while you press the keypad button the corresponding pin on the receiver goes high. I am hoping the next time I order something from them I remember to get the latching one instead because that is what I really need. Anyway since I don't have a project for this one in mind I just wanted to do some testing... so I just plugged it directly into my Arduino( avoiding the Serial pins since I needed those to display the pin states) This is the only way I could fit it on the board without putting it on a bread board. (quick and dirty!)

The VT pin isn't of to much concern for me right now so it just tucks in between the two pin banks :)

Check out the code below. This is great but if I don't want to constantly poll for buttons I may miss one. So my intention is to order a latching version, when you press the button on the keypad the pin goes high and stays high until you press it again. My thought is that if I am powering the receiver from the arduino then I can read it maybe once a second or even less often then when a high state is detected then I can simple "reboot" the receiver by dropping the +5v pin to ground. So until I get one in I will hope it resets back to ground on all the signal pins like I need

/*--------------------------------------------------------
Adafruit's Simple RF Receiver example
http://www.adafruit.com/products/1096                                  
Author: Chris Crumpacker                               
Date: August 2013 

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.
                                                           
Sketch Notes: This is set as if you put the reciever directly
onto an arduino with gnd in pin 2 and the VT pin in the 
gap between the pin banks.
--------------------------------------------------------*/

#define GROUNDPIN  2
#define POWERPIN   3

// Arduino Pin Numbers
int signalPin[4] = { 4, 5, 6, 7 };
// Reciever Pin Names
const char* pinName[] = { "D3", "D2", "D1", "D0" };
// Keyfob Pin Names
const char* buttonName[] = { "D", "C", "B", "A" };

int lastSignalState[] = { 0, 0, 0, 0 };
int signalState = 0;
float onTime = 0.00;

void setup() {
  // Set the ground pin to a Low output
  pinMode(GROUNDPIN, OUTPUT);
  digitalWrite(GROUNDPIN, LOW);
  
  // Set the +5v pin to a High output
  pinMode(POWERPIN,OUTPUT);
  digitalWrite(POWERPIN, HIGH);
  
  // Setting the signal pins as inputs
  for (int i = 0; i < 4; i++) {
    pinMode(signalPin[i], INPUT);
  }
  
  // Starting the serial interface
  Serial.begin(19200);
}

void loop(){
  // For each of the 4 pins we loop thru and check the state.
  for (int i = 0; i < 4; i++) {
    // Read the current pin
    signalState = digitalRead(signalPin[i]);
    
    if (signalState != lastSignalState[i]) {
      // if the state has changed...
      if (signalState == HIGH) {
        // ...and the current state is HIGH...
        Serial.print("Receiver Pin: ");
        Serial.println(pinName[i]);
        Serial.print("Keyfob Button: ");
        Serial.println(buttonName[i]);
        Serial.println("Switched ON");
        Serial.println("------------------------------");
        onTime = millis();
      } 
      else {
        // ...and the current State is LOW...
        Serial.print("Receiver Pin: ");
        Serial.println(pinName[i]);
        Serial.print("Keyfob Button: ");
        Serial.println(buttonName[i]);
        Serial.print("Switched OFF after ");
        Serial.print(((millis() - onTime) / 1000.00));
        Serial.println(" seconds");
        Serial.println("------------------------------");
      }
    }
    // save the current state to the last state array
    lastSignalState[i] = signalState;
  }
}

17 comments:

  1. Thank you so much this great short and easy tutorial was so helpful i was able to use my receiver!

    ReplyDelete

  2. Attractive section of content. I simply stumbled upon your blog and in accession capital to assert that I acquire in fact enjoyed
    account your blog posts. Anyway I’ll be subscribing
    on your augment or even I success you access constantly quickly.

    Here's my website : -- 부산달리기
    (jk)

    ReplyDelete
  3. Spot on with this write-up, I truly believe that this website needs a lot more attention. I'll probably be back again to read more, thanks for the advice!

    Please Visit My homepage ➤ 야동

    ReplyDelete
  4. I have always disliked the idea because of the costs 오피 . Is usually able to answer customer questions.

    ReplyDelete
  5. "What i do not realize is actually how you're no longer actually much more
    smartly-liked than you might be now. You are very intelligent.
    You know thus considerably when it comes
    to this matter, produced me in my view believe it from numerous numerous angles.
    Its like men and women don't seem to be fascinated until it's something to do with Girl gaga!

    Your individual stuffs outstanding. All the time care for it up!"

    my web page ➥ 마사지

    ReplyDelete
  6. I haven't checked in here for some time since I thought it was getting boring, but the last several posts are good quality so I guess I'll add you back to my everyday blog list. You deserve it my friend �� 건전마사지

    ReplyDelete
  7. Hello there, You’ve done an incredible job. I will definitely digg it and personally recommend to my friends. I’m confident they’ll be benefited from this website.| 스포츠토토티비

    ReplyDelete
  8. 바카라사이트 Hi there, You have done a great job. I will definitely digg it and
    personally recommend to my friends. I am confident they will be benefited from this web site.

    ReplyDelete
  9. 바카라사이트 This article presents clear idea for the new people of blogging, that really how to do running a
    blog.

    ReplyDelete
  10. Very efficiently written information. It will be valuable to everyone who utilizes it, as well as yours truly. Keep doing what you are doing – for sure i will check out more posts.
    토토
    경마
    온라인경마

    ReplyDelete
  11. I will recommend your website to everyone. You have a very good gloss. Write more high-quality articles. 스포츠토토

    ReplyDelete
  12. Great article I enjoy reading your thoughts. More power to your website. Please visit mine too 온라인카지노

    ReplyDelete
  13. It's amazing that you have that kind of idea writing this article. Thank you for valuable article. 바카라사이트

    ReplyDelete
  14. This is really interesting, You’re a very skilled blogger. 카지노사이트존

    ReplyDelete
  15. This piece of writing is truly a fastidious one it assists new web users, who are wishing in favor of blogging.

    https://www.safecasinosite.net

    ReplyDelete
  16. I really enjoy your web’s topic. Very creative and friendly for users. Definitely bookmark this and follow it everyday. 바카라사이트

    ReplyDelete