Showing posts with label Control. Show all posts
Showing posts with label Control. Show all posts

2014/08/12

3x4 Keypad Radio Frequency remote control

  To send digits to radio frequency receiver, a 3x4 keypad and a transmitter is a good combination. To use the keypad, the connection between keypad and pins has to be clarified. For my keypad, the connections are:

Keypad.1: Pin1 + Pin5
Keypad.2: Pin1 + Pin6
Keypad.3: Pin1 + Pin7
Keypad.4: Pin2 + Pin5
Keypad.5: Pin2 + Pin6
Keypad.6: Pin2 + Pin7
Keypad.7: Pin3 + Pin5
Keypad.8: Pin3 + Pin6
Keypad.9: Pin3 + Pin7
Keypad.*: Pin4 + Pin5
Keypad.0: Pin4 + Pin6
Keypad.#: Pin4 + Pin7

I just want to send 3 digits range from 000 to 999 to receiver running the sketch posted on May. 11, 2014. The result is showed on the following photo.

Connections

1. Transmitter.Vcc -> Arduino.5V
2. Transmitter.Gnd -> Arduino.Gnd
3. Transmitter.Data -> Arduino.D12
4. Keypad.Pin1 (ROW0) -> Arduino.D5
5. Keypad.Pin2 (ROW1) -> Arduino.D4
6. Keypad.Pin3 (ROW2) -> Arduino.D3
7. Keypad.Pin4 (ROW3) -> Arduino.D2
8. Keypad.Pin5 (COL0) -> Arduino.D8
9. Keypad.Pin6 (COL1) -> Arduino.D7
10. Keypad.Pin7 (COL2) -> Arduino.D6



Photo



Updated Sketch

// Modified by Befun Hung on Oct. 28, 2014   
// Blink led after sending message to notice user 5 times 
#include <Keypad.h>
#include <VirtualWire.h>

#define maxLength 3
const byte ROWS = 4; // four rows
const byte COLS = 3; // three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {5, 4, 3, 2};
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = {8, 7, 6};    // connect to the column pinouts of the keypad
char keyins[maxLength+1] = "";
int i=0, j=0, sendTimes=5;
int led=13;

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {
  Serial.begin(9600);
  // Initialize the IO and ISR
  vw_setup(2000); // Bits per sec
  Serial.println("Ready!");
  pinMode(led, OUTPUT);
}
  
void loop() {
    char key = keypad.getKey();
    if (key) {
      Serial.print(key);
      keyins[i] = key;
      i++;
      if (i == maxLength) {
        for (j=0;j<sendTimes;j++) {
          Serial.println();
          send(keyins);
          digitalWrite(led, HIGH);
          delay(20);
          digitalWrite(led, LOW);
          delay(20);
        }
        i = 0;
      } 
    }
}

void send(char *message)
{
  vw_send((uint8_t *)message, strlen(message));
  vw_wait_tx(); // Wait until the whole message is gone
}

Sketch

#include <Keypad.h>
#include <VirtualWire.h>

#define maxLength 3
const byte ROWS = 4; // four rows
const byte COLS = 3; // three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {5, 4, 3, 2};
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = {8, 7, 6};    // connect to the column pinouts of the keypad
char keyins[maxLength+1] = "";
int i=0;

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {
  Serial.begin(9600);
  // Initialize the IO and ISR
  vw_setup(2000); // Bits per sec
  Serial.println("Ready!");
}
  
void loop() {
    char key = keypad.getKey();
    if (key) {
      Serial.print(key);
      keyins[i] = key;
      i++;
      if (i == maxLength) {
        Serial.println();
        send(keyins);
        i = 0;
      }
    }
}

void send(char *message)
{
  vw_send((uint8_t *)message, strlen(message));
  vw_wait_tx(); // Wait until the whole message is gone
}

2014/07/30

Use DIP Switch To Set Arduino Device Net ID And Node ID for Wireless Communication

  To use one remote control to many switch radio frequency wireless power supply sockets, each one must has its unique ID to identify itself and act according commands received from the remote control.
  In the example sketch, A2-A4 A1-A3 are set to 1, 0, 1; D2-D9 are set to 0,0,0,0,1,0,1,0. So the net ID is calculated as 1*4+0*2+1*1=5; node ID is calculated as 0*128+0*64+0*32+0*16+1*8+0*4+1*2+0*1=10.

Updated on Nov. 12, 2014
  Use the same DIP setting above, the output will be :
Net ID: 5
Node ID1: 0
Node ID2:10

Photo of Connections




Output


Update Sketch (Nov. 12, 2014)

// Released by abocanegra on Dec. 11, 2009 using 4 pins, "DIP Switch 8 Position to Address Sensor" in Arduino Forum
// Modified by Befun Hung on Jul. 30, 2014 to use 
// 3 analog pins(A1-A3) to set net ID 
// 8 digital pins(D2-D9) to set Node ID by using 10K pull-up resistors.
// Totally 8x256=2,048 devices can be used for wireless communication
// For practical use 8x10=80 devices can be controlled using digital key of 3x4 telephone keypad
// Modified by Befun Hung on Nov. 12, 2014 to use
// 4 digital pins(D2-D5) to set node ID1 and
// 4 digital pins(D6-D9) to set node ID2 by using 10K pull-up resistors.
// Totally 8x16x16=2,048 devices can be used for wireless communication
// For practical use 8x10x10=800 devices can be controlled using digital key of 3x4 telephone keypad
// Wire and DIP switch connections from high bit to low bit are A1, A2, A3, D2, D3, D4, D5, D6, D7, D8 and D9  
// A0 is reserved for analog sensor or digital sensor/actuator 
// A4-A5 are reserved for I2C
// D0-D1 are reserved for RX/TX
// D10-D13 are reserved for SPI

//Create and Define Global Variables
int bits=4, netID, nodeID1, nodeID2;
int dipNet[] = {15, 16, 17}; // DIP Switch Pins for Net ID
int dipNode1[] = {2, 3, 4, 5}; // DIP Switch Pins for Node ID1
int dipNode2[] = {6, 7, 8, 9}; // DIP Switch Pins for Node ID2

void setup()
{
  Serial.begin(9600);
  int i;
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
  netID = netAddress();
  // delay(100);
  Serial.print("Net ID: ");
  Serial.println(netID);
  
  for(i = 0; i<bits; i++){
    pinMode(dipNode1[i], INPUT);      // sets the digital pin 2-5 as input
  }
  nodeID1 = node1Address(bits);
  // delay(100);
  Serial.print("Node ID1: ");
  Serial.println(nodeID1);
  
  for(i = 0; i<bits; i++){
    pinMode(dipNode2[i], INPUT);      // sets the digital pin 2-5 as input
  }
  nodeID2 = node2Address(bits);
  // delay(100);
  Serial.print("Node ID2: ");
  Serial.println(nodeID2);
}

void loop()
{
  
}

//Create Net Address from DIP Switch (3 positions used A1-A3)
byte netAddress(){
  int i,j=0;
  
  //Get the switches state
  j = (j << 1) | (! digitalRead(A1));   // read the input pin
  j = (j << 1) | (! digitalRead(A2));   // read the input pin
  j = (j << 1) | (! digitalRead(A3));   // read the input pin
  return j; //return address
}

//Create Node1 Address from DIP Switch (4 positions used D2-D5)
byte node1Address(int k){
  int i,j=0;
  
  //Get the switches state
  for(i=0; i<k; i++){
  j = (j << 1) | (! digitalRead(dipNode1[i]));   // read the input pin
  }
  return j; //return address
}

//Create Node1 Address from DIP Switch (4 positions used D6-D9)
byte node2Address(int k){
  int i,j=0;
  
  //Get the switches state
  for(i=0; i<k; i++){
  j = (j << 1) | (! digitalRead(dipNode2[i]));   // read the input pin
  }
  return j; //return address
}

Sketch

// Released by abocanegra on Dec. 11, 2009 using 4 pins, "DIP Switch 8 Position to Address Sensor" in Arduino Forum
// Modified by Befun Hung on Jul. 30, 2014 to use 3 analog pins(A1-A3) to set net ID and 8 digital pins(D2-D9) to set node ID by using 10K pull-up resistors.
// Totally 8x256=2,048 devices can be used for wireless communication
// A0 is reserved for analog sensor or digital sensor/actuator 
// A4-A5 are reserved for I2C
// D0-D1 are reserved for RX/TX
// D10-D13 are reserved for SPI

//Create and Define Global Variables
int bits=8, netID, nodeID;
int dipNet[] = {15, 16, 17}; //DIP Switch Pins for Net ID
int dipNode[] = {2, 3, 4, 5, 6, 7, 8, 9}; //DIP Switch Pins for Node ID

void setup()
{
  Serial.begin(9600);
  int i;
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
  netID = netAddress();
  // delay(100);
  Serial.print("Net ID: ");
  Serial.println(netID);
  
  for(i = 0; i<bits; i++){
    pinMode(dipNode[i], INPUT);      // sets the digital pin 2-9 as input
  }
  nodeID = nodeAddress(bits);
  // delay(100);
  Serial.print("Node ID: ");
  Serial.println(nodeID);
}

void loop()
{
  
}

//Create Net Address from DIP Switch (3 positions used)
byte netAddress(){
  int i,j=0;
  
  //Get the switches state
  j = (j << 1) | (! digitalRead(A1));   // read the input pin
  j = (j << 1) | (! digitalRead(A2));   // read the input pin
  j = (j << 1) | (! digitalRead(A3));   // read the input pin
  return j; //return address
}

//Create Node Address from DIP Switch (8 positions used D2 - D9)
byte nodeAddress(int k){
  int i,j=0;
  
  //Get the switches state
  for(i=0; i<k; i++){
  j = (j << 1) | (! digitalRead(dipNode[i]));   // read the input pin
  }
  return j; //return address
}