Monday, June 29, 2015

Leds Keypad Switch

by J.B. Wylzan


Project 18:  Leds Keypad Switch

This project  turns On and Off  4 leds using a Membrane Switch Keypad.




4X3 Matrix Keypad Configuration:  

   ROW1 - Arduino pin 4
   ROW2 - Arduino pin 5
   ROW3 - Arduino pin 6
   ROW4 - Arduino pin 7
   COL1 - Arduino pin 8
   COL2 - Arduino pin 9
   COL3 - Arduino pin 10

*Note: These rows and columns can be changed anytime.


Block Diagram:



Hardware:
1 Keypad; 4x3 Matrix 
4 leds
4 resistors
connecting wires
breadboard
Arduino R3 UNO board

Code # 18:
/*
  iHacklab Leds Switch Keypad
  powered by Arduino
  modified by Lawsinium

Note: Keypad Library for Arduino
Authored by  Mark Stanley, Alexander Brevig
Downloaded from http://playground.arduino.cc/Code/Keypad

  Turns On and Off leds using a keypad
  The example code is public domain.
 */

#include <Keypad.h>

const byte ROWS = 4;       // Keypad has four rows
const byte COLS = 3;        // Keypad has three columns
char key = 0;                       // Initializes a variable

// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

// Connect keypad’s pins to Arduino pins.
byte rowPins[ROWS] = { 4, 5, 6, 7 };  
byte colPins[COLS] = { 8, 9, 10 };   

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

//setup the pins' inputs and outputs void setup() {
  pinMode(4, INPUT);
 pinMode(5, INPUT);
 pinMode(6, INPUT);
  pinMode(7, INPUT);
   pinMode(8, INPUT);
    pinMode(9, INPUT);
     pinMode(10, INPUT);
      pinMode(2, OUTPUT);
       pinMode(3, OUTPUT);
       pinMode(11, OUTPUT);
       pinMode(12, OUTPUT);
}

void loop()
{
  key = keypad.getKey();     // get key
  pressKey('1', '2', 2);          // On = '1', Off = '2', pin = 2
  pressKey('3', '4', 3);          // On = '1', Off = '2', pin = 3
  pressKey('5', '6', 11);        // On = '1', Off = '2', pin = 11
  pressKey('7', '8', 12);        // On = '1', Off = '2', pin = 12                          
}
unsigned int pressKey(char on, char off, int output) {
  if(key) {
    if (key == on) {
      digitalWrite(output, HIGH);
    }
    if (key == off) {
      digitalWrite(output, LOW);
    }
  } 
}
// end of the sketch


Challenge: Use Keypad to light an LED using a numerical password. If the password is invalid a red led lights up. If the password is valid, a green led lights up.


Actual Layout:


Procedure:
1. Build the prototype as shown above
2. Run the Arduino Interface
3. Select File > New
4. Copy Code #18 above
5. Paste Code #18
6. Click File > Save
7. Click Verify
8. Click Upload
9. Press any key to turn On and Off an Led.


Project # 19:  Keypad with Password


Disclaimer:  We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email. 

Public Domain Notice: Copyright (c) 2000. All rights reserved. This article is part of a book entitled iHackRobot. Copies are welcome to be shared or distributed publicly as long proper citations are observed. Please cite as follows: A Journal of a Creative Mind, Joey Lawsin, 1988, USA.


"The Last Human on Earth will no longer be Human." ~ Joey Lawsin
================================================================== 
The Homotronics® and Homodruinos® logos are registered trademarks.
Copyright Biotronics© Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®


 ================================================================== 

Arduino Keypad Basics

by J.B. Wylzan


Project 17:  Arduino Keypad Basics

This tutorial shows how to connect a Membrane Switch Keypad to an Arduino Board to control an led. The input of pressing a key is posted as output on a serial monitor.


4X3 Matrix Keypad Configuration:  

   ROW1 - Arduino pin 4
   ROW2 - Arduino pin 5
   ROW3 - Arduino pin 6
   ROW4 - Arduino pin 7
   COL1 - Arduino pin 8
   COL2 - Arduino pin 9
   COL3 - Arduino pin 10


Block Diagram:



Hardware:
1 Keypad; 4x3 Matrix 
connecting wires
Arduino R3 UNO board

Code # 17:
/*
  iHacklab Membrane Switch Keypad
  powered by Arduino
  modified by Lawsinium

Note: Keypad Library for Arduino
Authored by  Mark Stanley, Alexander Brevig
Downloaded from http://playground.arduino.cc/Code/Keypad

  Reads keypad input where output projected on Arduino Serial Monitor
  The example code is public domain.
 */

#include <Keypad.h>

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','*'}
};
byte rowPins[ROWS] = {4, 5, 6, 7};    //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 9, 10};        //connect to the column pinouts of the keypad

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

void setup(){
  Serial.begin(9600);
}

void loop(){
  char key = keypad.getKey();

  if (key != NO_KEY){
    Serial.println(key);
  }
}

Challenge: Us the number 9 to turn On all four Leds and number 0 to turn OFF all four leds.


Actual Layout:


Procedure:
1. Build the prototype as shown above
2. Run the Arduino Interface
3. Select File > New
4. Copy Code #17 above
5. Paste Code #17
6. Click File > Save
7. Click Verify
8. Click Upload
9. Open the Arduino Serial Monitor
10. Press any key and that number is posted on your serial monitor.


Project # 18:  Keypad with Leds


Disclaimer:  We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email. 

Public Domain Notice: Copyright (c) 2000. All rights reserved. This article is part of a book entitled iHackRobot. Copies are welcome to be shared or distributed publicly as long proper citations are observed. Please cite as follows: A Journal of a Creative Mind, Joey Lawsin, 1988, USA.


"The Last Human on Earth will no longer be Human." ~ Joey Lawsin
================================================================== 
The Homotronics® and Homodruinos® logos are registered trademarks.
Copyright Biotronics© Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®


 ================================================================== 


Sunday, June 14, 2015

I Love You Matrix

by J.B. Wylzan
Project 15:  The Dot Led Matrix
This project displays the words " I Love You" as it flashes one letter at a time 
scrolling across the matrix display. It also blinks the Heart pattern 3 times
and simulate partially the space invader game.






Block Diagram:



Hardware:
MAX7219 Dot Led Matrix Display
connecting wires
breadboard
Arduino R3 UNO board


Binary Code Refresher:


Cheat Sheet:
Led Dot Matrix X-Y Address Codex


Code # 15:
/*
  iHacklab I Love You Matrix
  powered by Arduino
  modified by Lawsinium

I love you will flash one letter at a time and blink the Heart three times after scrolling. Take note I coded the binary pattern into various approaches. Try to study them and find which one is best for your programming. This example code is public domain.
 */

 // Setup matrix display
 unsigned char m;
 unsigned char n; 

int pinCLK = 11;  // Clock pin of MAX7219 
int pinCS = 10;   // Load pin of MAX7219  
int pinDIN = 12;  // Data pin of MAX7219 

unsigned char disp1[15][8]={
{0x0,0x7c,0x10,0x10,0x10,0x10,0x7c,0x0}, // code for letter I
0, 0, 0x18, 0 , 0, 0, 0, 0, //.
0, 0x24, B00011000, 0 , 0, 0, 0, 0, // .
0, B01100110, B00011000, 0 , 0, 0, 0, 0, // .
0, B01100110, B10011001, 0 , 0, 0, 0, 0, // .
0, B01100110, B10011001, B01000010 , 0, 0, 0, 0, // .
0, B01100110, B10011001, B01000010, B00100100, 0, 0, 0, // .
0, B01100110, B10011001, B01000010, B00100100, B00011000, 0, 0, // 
{0x0,0x44,0x44,0x44,0x44,0x44,0x38,0x0},   // code for letter U
0, 0, 0, 0 , 0, 0, 0, 0, // .
0, B01100110, B10011001, B01000010, B00100100, B00011000, 0, 0, // .
0, 0, 0, 0 , 0, 0, 0, 0, // .
0, B01100110, B10011001, B01000010, B00100100, B00011000, 0, 0, // .
0, 0, 0, 0 , 0, 0, 0, 0, // .
0, B01100110, B10011001, B01000010, B00100100, B00011000, 0, 0, // .
};

void byteWrite(unsigned char DATA) 
{   
            unsigned char m;
   digitalWrite(pinCS,LOW);
   for(m=8;m>=1;m--)
          {  
             digitalWrite(pinCLK,LOW);
             digitalWrite(pinDIN,DATA&0x80);
             DATA = DATA<<1;
             digitalWrite(pinCLK,HIGH);
           }                                 
}

void chipWrite(unsigned char address,unsigned char data)
{
        digitalWrite(pinCS,LOW);
        byteWrite(address);           
        byteWrite(data);                
        digitalWrite(pinCS,HIGH);
}

void Init_chip(void)
{
 chipWrite(0x09, 0x00);       //decode BCD
 chipWrite(0x0a, 0x03);       //brightness 
 chipWrite(0x0b, 0x07);       //scanlimit
 chipWrite(0x0c, 0x01);       //power mode
 chipWrite(0x0f, 0x00);       //test display
}

void setup()
{
  pinMode(pinCLK,OUTPUT);
  pinMode(pinCS,OUTPUT);
  pinMode(pinDIN,OUTPUT);
  delay(50);
  Init_chip();
}

void loop()

   for(n=0;n<15;n++)    
  {
   for(m=1;m<9;m++)
    chipWrite(m,disp1[n][m-1]);
   delay(500);
  }
}
// end Love Matrix  

Challenge: Review what you have learned from Project Binary Counter step by step. The format 
B00000000 means all leds are OFF. The format B11111111 means all leds are ON. Using both formats can turn on and off an led of leds in a particular row or column. the format B00011000 can also be coded as 18 ( 0001 = 1 and 1000 = 8)


Actual Layout:


Procedure:
1. Use the same prototype as shown above
2. Run the Arduino Interface
3. Select File > New
4. Copy Code #15 above
5. Paste Code #15
6. Click File > Save
7. Click Verify
8. Click Upload
9. I love you will flash one letter at a time and blink the Heart three times after scrolling.


Project # 16:  Ultrasonic Sensor


Disclaimer:  We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email. 

Public Domain Notice: Copyright (c) 2000. All rights reserved. This article is part of a book entitled iHackRobot. Copies are welcome to be shared or distributed publicly as long proper citations are observed. Please cite as follows: A Journal of a Creative Mind, Joey Lawsin, 1988, USA.


"The Last Human on Earth will no longer be Human." ~ Joey Lawsin
================================================================== 
The Homotronics® and Homodruinos® logos are registered trademarks.
Copyright Biotronics© Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®
 ==================================================================