Monday, June 29, 2015

Leds Keypad Switch

How to build and control an LED on an Arduino using a keypad membrane:
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.


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: Biotronics: The Silver Species, Joey Lawsin, 1988, USA.

================================================================== 
The Homotronics® and Homodruinos® logos are registered trademarks.
Copyright Biotronics© Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®

L.A.W.S.I.N. Educational Production
 ================================================================== 

Arduino Keypad Basics

How to build and control an LED on an Arduino using a keypad switch:
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.


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: Biotronics: The Silver Species, Joey Lawsin, 1988, USA.

================================================================== 
The Homotronics® and Homodruinos® logos are registered trademarks.
Copyright Biotronics© Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®

L.A.W.S.I.N. Educational Production
 ================================================================== 



Sunday, June 14, 2015

I Love You Matrix

How to build and control a Dot Led Matrix on an Arduino:
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: Biotronics: The Silver Species, Joey Lawsin, 1988, USA.

================================================================== 
The Homotronics® and Homodruinos® logos are registered trademarks.
Copyright Biotronics© Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®

L.A.W.S.I.N. Educational Production
 ================================================================== 



Wednesday, June 10, 2015

Photosensor

How to build and control an LED on an Arduino with an LDR sensor:
by J.B. Wylzan

Project 11: LDR Sensor

This project teaches how to turn on and off any of your first 10 projects with a light sensor.



Hardware:
LEDs
resistors
photosensor
wires
breadboard
Arduino UNO

Block Diagram:

image designed by Fritzing

Note: Replace the switch button with the photosensor (A0/3,3v).See actual assembly below:


Actual Assembly:  





Procedure:
1. Use the same prototype as shown above
2. Run the Arduino Interface
3. Select File > New
4. Copy Code #11  below
5. Paste Code #11
6. Click File > Save
7. Click Verify
8. Click Upload
9. Activate leds by cupping the light sensor

Code # 11:  
/* 
    iHackLab The Switch 
    powered by Arduino
    sketched by J.B. Wylzan
    modified by Lawsinium
    code is public domain. */
    
const int ldrPin = 0;
const int ledPin = 8;
int Calphotons;
int Valphotons;


void setup()
{
  pinMode(ledPin, OUTPUT);
  Calphotons = analogRead(ldrPin);
}


void loop()
{
  Valphotons = analogRead(ldrPin);

 if (Valphotons < Calphotons - 50)
  {
    digitalWrite(ledPin, HIGH);
  }

  else
  {
    digitalWrite(ledPin, LOW);
  }

}


/* end program */



Project # 12: The Game of Reflex




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: Biotronics: The Silver Species, Joey Lawsin, 1988, USA.

================================================================== 
The Homotronics® and Homodruinos® logos are registered trademarks.
Copyright Biotronics© Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®

L.A.W.S.I.N. Educational Production
 ==================================================================