Archive

Archive for the ‘Arduino’ Category

NXT Shield Version 2

October 19th, 2011 32 comments

Update
The NXT Shield is for sale in our shop: http://shop.tkjelectronics.dk/product_info.php?products_id=29. A easy to use library is also provided: https://github.com/TKJElectronics/NXTShield.
Three examples that demonstrates reading the encoders, turning the motors and using the ultrasonic sensor is found in the library as well: https://github.com/TKJElectronics/NXTShield/tree/master/examples.

More pictures of the NXT Shield can be found at the following blog post: http://blog.tkjelectronics.dk/2012/04/nxt-shield-library/.

Instead of using the shield with an Arduino, one of our customers decided to hook it up to an STM32 processor to control his robot. He described his development and findings on his blog: https://www.embedded.com/design/programming-languages-and-tools/4458801/2/Making-robots-with-Ada—Part-2—Driving-the-motors
Please note however that his code is written in the Ada language and not C/C++!

I finally made a new version of my NXT Shield. The big news is that it now supports the Lego Ultrasonic Sensor and it has NXT Compatible Sockets from mindsensors.

Read more…

Arduino RGB LED Controller

August 23rd, 2011 54 comments

When reorganizing our stock I found a whole bunch of diffused RGB LEDs (>100pcs) so I thought I would make something cool with them. Maybe some kind of individual controllable christmas light or some lights you could use for showcases etc.

RGB LEDs


So I decided once again to make a project using the Arduino Duemilanove, as it is so quick and easy to get a prototype working.
After some brainstorming, thinking about how I should do the PWM multiplexing, I designed a circuit capable of driving 8 individual RGB LEDs using 11 pins. The project would be easily expandable and would only cost 1 extra pin for each extra RGB LED.
Read more…

Categories: Arduino Tags:

Guide: How to use an Arduino as an In System Programmer (ISP)

June 29th, 2011 No comments

I recently bought the “Graphic LCD Serial Backpack” from Sparkfun. When reading the comments for the product. I discovered that a user named “SummoningDark”, had made a new improved firmware. A lot of people asked Sparkfun to change the official firmware with the new one, so i decided to check it out. The problem were that I do not own a programmer, so at first I thought that I had to buy one. But after some googling I found out that the Arduino could actually be used as an In System Programmer (ISP).
After a lot of work I finally got it working and it has really improved the perfomance of the screen. The speed is much higher (SummoningDark says 10 times) and there are no more bugs (with the old firmware the screen would suddenly write the text or a line a odd place).

I will now try to explain as best as I can, how to upload the new firmware.

NB: You can also use this guide if you need a different bootloader or another hex file on any AVR. This is just meant as an example.
Read more…

Categories: Arduino, Guides Tags:

NXT Motor Shield

June 29th, 2011 12 comments

Update
The NXT Shield is for sale in our shop: http://shop.tkjelectronics.dk/product_info.php?products_id=29. A easy to use library is also provided: https://github.com/TKJElectronics/NXTShield.
Three examples that demonstrates reading the encoders, turning the motors and using the ultrasonic sensor is found in the library as well: https://github.com/TKJElectronics/NXTShield/tree/master/examples.

More pictures of the NXT Shield can be found at the following blog post: http://blog.tkjelectronics.dk/2012/04/nxt-shield-library/.

The shield mounted on a Arduino

Hallo everybody

I recently made a NXT motor shield for my arduino. It can control two NXT motors and also read the onboard encoders. In true Arduino spirit I decided to share it with the rest of the community. But first i will talk about how everything works, and then show the finished shield including a short video demonstration.
Read more…

Categories: Arduino, Development boards, Guides Tags:

Guide: Gyro and Accelerometer Kalman filtering, with the Arduino

June 14th, 2011 5 comments

Hello again everybody.
Today I agreed with my fellow classmate and team member, Kristian Lauszus, to post his guide to Kalman filtering, using the Arduino with a Gyro and Accelerometer, on my blog. So here it is, and I think it will be usefull for your guys.
Questions can be asked in the Arduino forum where the Guide was originally posted: http://arduino.cc/forum/index.php?topic=58048.0

I recently bought this analog 6DOF (six degrees of freedom) IMU board (http://www.sparkfun.com/products/10010) from watterott.com. It uses three gyros and three accelerometers to calculate angles in three dimensions.

6DOF Sparkfun Board


Read more…

Categories: Arduino, Guides Tags:

Arduino RFID Door Lock

April 2nd, 2011 92 comments

Arduino RFID Door Lock

Once again me and one of my class mates have finished a project in school using the Arduino.
This time it’s an RFID Door Lock made with a real door and a real lock. The lock is turned using a standard 6V servo.

The project was about luxury, and we thought it might be luxurious if the door could be unlock automatically, fx when you come home from shopping, carrying a bag in each hand. This was the beginning of this project.

In the video below you can see a short demonstration of the system.



We thought you might be interested in the code, and to see how we implemented the “Master-system”, so the code can be found beneath. Remember that you should download the Servo library, and the Parallax RFID reader should be connected to the Serial RX pin (Pin 0).

//Start
#include <eeprom.h>
#include <servo.h>

//Initialiser
Servo servoLock;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

#define RFID_Enabled_Pin 2  // sets RFID enable pin to pin 2
#define servoPin 3 // sets the servo's pin to pin 3
#define LockedPos 10
#define UnlockedPos 110

byte buffer[100]; //used to store the incoming bytes from the RFID
byte RFID_Master[10] = {'1', '7', '0', '0', '7', 'D', 'B', '2', '4', 'F'}; //the secound RFID fob (key) to look for
byte RFID_Slave1[10], RFID_Slave2[10], RFID_Slave3[10]; //the first RFID fob (key) to look for
byte i; //used to keep track of which bit to write to
byte i2; //used to erase the RFID fob (key) number from the buffer

boolean DoorLocked; //true if door is locked

byte checkPosition; //used to check if the incomming number is true or false
boolean RFID_Master_Correct; //true if it's the right RFID fob (key), false if not
boolean RFID_Slave1_Correct, RFID_Slave2_Correct, RFID_Slave3_Correct; //true if it's the right RFID fob (key), false if not
boolean RFID_SaveNextRead;

void setup() {
  pinMode(13, OUTPUT); //enables the diode on the arduino
  pinMode(RFID_Enabled_Pin, OUTPUT); //sets the RFID pin to output
  RFID_Enable(false); //used to set the status of the RFID reader
  EEPROM_Read_Slaves();
//Lock
  PreLock(); //locks the arduino on startup
  RFID_Enable(true); //used to set the status of the RFID reader
  Serial.begin(2400);  //sets baudrate
  i = 1; //sets the varible to 1, and thereby skip the start byte (0x0A)
}
//Go To
//Loop
void loop() { //the main loop
// Serial data
  if (Serial.available()) { //check if the RFID reader sends anything
    if (buffer[0] != 0x0A) { //check if it the start bit is 0x0A
      buffer[0] = Serial.read(); //write bit to buffer
    } else {
//Recieve
      buffer[i] = Serial.read(); //write next bit to buffer
      if (buffer[i] == 0x0D) {   //if end bit is send, disable the RFID reader temporary
        Serial.print("RFID Tag scanned: ");
        RFID_Enable(false);
        RFID_Master_Correct = true;
        RFID_Slave1_Correct = true;
        RFID_Slave2_Correct = true;
        RFID_Slave3_Correct = true;
//RFID ID
        // We have read all bytes - we are now going to check them
        for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
          Serial.print(buffer[checkPosition+1], BYTE);
          if (buffer[checkPosition+1] == RFID_Slave1[checkPosition] && RFID_Slave1_Correct == true) {   // compares the written bits to "RFID1"
            RFID_Slave1_Correct = true; //Slave1 RFID tag is detected
          } else {
            RFID_Slave1_Correct = false; //Slave1 RFID tag is not detected
          }
          if (buffer[checkPosition+1] == RFID_Slave2[checkPosition] && RFID_Slave2_Correct == true) {   // compares the written bits to "RFID1"
            RFID_Slave2_Correct = true; //Slave2 RFID tag is detected
          } else {
            RFID_Slave2_Correct = false; //Slave2 RFID tag is not detected
          }
          if (buffer[checkPosition+1] == RFID_Slave3[checkPosition] && RFID_Slave3_Correct == true) {   // compares the written bits to "RFID1"
            RFID_Slave3_Correct = true; //Slave3 RFID tag is detected
          } else {
            RFID_Slave3_Correct = false; //Slave3 RFID tag is detected
          }
          if (buffer[checkPosition+1] == RFID_Master[checkPosition] && RFID_Master_Correct == true) {   // compares the written bits to "RFID1"
            RFID_Master_Correct = true; //Master RFID tag is detected
          } else {
            RFID_Master_Correct = false; //Master RFID tag is detected
          }
        }
        Serial.println("");
        if (RFID_SaveNextRead == false && (RFID_Slave1_Correct == true || RFID_Slave2_Correct == true || RFID_Slave3_Correct == true) && RFID_Master_Correct == false) { //see if the right RFID fob (key) is detected
          if (RFID_Slave1_Correct == true) { Serial.println("Slave1 Card Scanned"); }
          if (RFID_Slave2_Correct == true) { Serial.println("Slave2 Card Scanned"); }
          if (RFID_Slave3_Correct == true) { Serial.println("Slave3 Card Scanned"); }
//Door
          if (DoorLocked == true) { //see if door is locked or not
//Unlock
            Serial.print("Unlocking..."); //if the door is locked then unlocked it
            Unlock(5); //unlock with 5ms delay
            Serial.println(" Unlocked!");
          } else {
//Lock
            Serial.print("Locking..."); //if the door is unlocked then lock it
            Lock(5); //lock with 5ms delay
            Serial.println(" Locked!");
          }
//Vent
          delay(1000); // Wait for you to remove the RFID fob (key)
        } else if (RFID_Master_Correct == true && RFID_SaveNextRead == false) { // If the Master Card is scanned when not in programming mode
          Serial.println("Master Card Scanned - Programming mode Enabled");
          delay(1000);
          RFID_SaveNextRead = true;  // Enable programming mode
        } else if (RFID_Master_Correct == false && RFID_SaveNextRead == true) { // If another card is scanned when in programming mode
          // Save the Card
          if (RFID_Slave1[0] == 0) { // Is the Slave1 Card slot empty?
            for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
              RFID_Slave1[checkPosition] = buffer[checkPosition+1]; // Save the scanned card as Slave1
            }
            Serial.println("RFID Card saved in: Slave1");
            delay(1000);
          } else if (RFID_Slave2[0] == 0) { // Is the Slave2 Card slot empty?
            for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
              RFID_Slave2[checkPosition] = buffer[checkPosition+1]; // Save the scanned card as Slave2
            }
            Serial.println("RFID Card saved in: Slave2");
            delay(1000);
          } else if (RFID_Slave3[0] == 0) { // Is the Slave3 Card slot empty?
            for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
              RFID_Slave3[checkPosition] = buffer[checkPosition+1]; // Save the scanned card as Slave3
            }
            Serial.println("RFID Card saved in: Slave3");
            delay(1000);
          } else {
            Serial.println("No free Card slots");
            RFID_Enable(true); //turns on the RFID reader
            delay(1000);
            RFID_Enable(false); //turns off the RFID reader
            delay(1000);
          }
          EEPROM_Save_Slaves();
          RFID_SaveNextRead = false;
        } else if (RFID_Master_Correct == true && RFID_SaveNextRead == true) { // If the Master Card is scanned when in programming mode
          Serial.println("Master Card Scanned again - Removing all saved Cards");
          delay(1000);
          // Remove all Slave Cards
          for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
            RFID_Slave1[checkPosition] = 0;
          }
          for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
            RFID_Slave2[checkPosition] = 0;
          }
          for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
            RFID_Slave3[checkPosition] = 0;
          }
          EEPROM_Save_Slaves();
          RFID_SaveNextRead = false;
        }

        RFID_Enable(true); //turns on the RFID reader
        EmptySerialBuffer(); //erase the buffer
        Serial.println("");
      }
      i++; //used in the beginning to write to each bit in the buffer
    }
  }
//Go to
}


void EmptySerialBuffer() { //replaces all bits in the buffer with zeros
  while (Serial.available()) { Serial.read(); }
  for (i2 = 0; i2 <= i; i2++) {
    buffer[i2] = 0;
  }
  i = 0;
}

void PreLock() {
  servoLock.attach(servoPin);  // attaches the servo on pin 3 to the servo object
  servoLock.write(LockedPos);              // tell servo to go to position in variable 'LockedPos'
  delay(250);                       // waits 1s for the servo to reach the position
  servoLock.detach();   //detaches the servo, so it's not using power
  DoorLocked = true;    //the door is locked
}

void Unlock(byte speedDelay) {
  int pos;
  servoLock.attach(servoPin);  // attaches the servo on pin 3 to the servo object
  for(pos = LockedPos; pos < UnlockedPos; pos += 1)  // goes from 10 degrees to 110 degrees
  {                                  // in steps of 1 degree
    servoLock.write(pos);              // tell servo to go to position in variable 'pos'
    delay(speedDelay);                       // waits 5ms for the servo to reach the position
  }
  servoLock.detach();   //detaches the servo, so it's not using power
  DoorLocked = false;   //the door is unlocked
}

void Lock(byte speedDelay) {
  int pos;
  servoLock.attach(servoPin);  // attaches the servo on pin 3 to the servo object
  for(pos = UnlockedPos; pos > LockedPos; pos -= 1)  // goes from 110 degrees to 10 degrees
  {                                  // in steps of 1 degree
    servoLock.write(pos);              // tell servo to go to position in variable 'pos'
    delay(speedDelay);                       // waits 5ms for the servo to reach the position
  }
  servoLock.detach();   //detaches the servo, so it's not using power
  DoorLocked = true;    //the door is locked
}

void RFID_Enable(boolean enabled) {
  if (enabled == true) {
    digitalWrite(RFID_Enabled_Pin, LOW); //enables the RDIF reader and turns on the diode on the arduino
    digitalWrite(13, HIGH);
  } else {                               //disables the RDIF reader and turns off the diode on the arduino
    digitalWrite(RFID_Enabled_Pin, HIGH);
    digitalWrite(13, LOW);
  }
}


void EEPROM_Read_Slaves() {
  byte EPROMaddr;
  for (EPROMaddr = 0; EPROMaddr < 10; EPROMaddr++) { //Read bit fra 0-9
    RFID_Slave1[EPROMaddr] = EEPROM.read(EPROMaddr);
  }
  for (EPROMaddr = 10; EPROMaddr < 20; EPROMaddr++) { //Read bit fra 0-9
    RFID_Slave2[EPROMaddr-10] = EEPROM.read(EPROMaddr);
  }
  for (EPROMaddr = 20; EPROMaddr < 30; EPROMaddr++) { //Read bit fra 0-9
    RFID_Slave3[EPROMaddr-20] = EEPROM.read(EPROMaddr);
  }
}

void EEPROM_Save_Slaves() {
  byte EPROMaddr;
  for (EPROMaddr = 0; EPROMaddr < 10; EPROMaddr++) { //Read bit fra 0-9
    EEPROM.write(EPROMaddr, RFID_Slave1[EPROMaddr]);
  }
  for (EPROMaddr = 10; EPROMaddr < 20; EPROMaddr++) { //Read bit fra 0-9
    EEPROM.write(EPROMaddr, RFID_Slave2[EPROMaddr-10]);
  }
  for (EPROMaddr = 20; EPROMaddr < 30; EPROMaddr++) { //Read bit fra 0-9
    EEPROM.write(EPROMaddr, RFID_Slave3[EPROMaddr-20]);
  }
}

Update:
The newest version of the code is now available at Github: https://github.com/TKJElectronics/ArduinoRFIDDoorLock.

Categories: Arduino Tags:

WiFi Controlled RC Car with the Arduino

February 8th, 2011 134 comments

I haven’t been posting in a long time, but I just haven’t had time to do it. I have been playing around with many different projects, both Freelance projects and my own projects.
Then I thought it would be nice to post some pictures and a video about my latest project about my Hacked/Modded DACKO RC Car.

The WiFi Controlled RC Car


As you can see on the image, I have disassembled the car and then found the controller module. Then I found an RF chip/IC on the board (RX2), and I was lucky to be able to find the datasheet of that.

Closeup of the WiFi Controlled RC Car


Then I soldered some wires to the specific pins for the motor driver circuit, one pin for each direction (forward, backward, left and right).

Then I connected theese wires to the Arduino, made a test program where the Forward and Backward pins was PWM controlled, making it possible to change speed. The left and right pin should just be driven high to turn the wheels.

After some testing, I attached the WiShield WiFi module from Asynclabs, and then I started programming a socket application for the Arduino. I thought it would be fastest and easiest to use the TCP protocol directly, than serving a webpage. After some tests with Hercules SETUP Utility I made myself a controller application in Visual Basic .NET – and off we go!


After a couple of inquiries from people asking for the Arduino and Visual Basic .NET code for this project, I’ve decided to upload it.
You can download the complete project including the used WiShield library, the Arduino code and the VB.NET code, here: WiFi Controlled Car Project

Categories: Arduino Tags:

Arduino Weather station (school project)

June 20th, 2010 15 comments

Arduino Weather station

I’ve nearly finished first year out of three on HTX, which is a kind of Technical Highschool. On HTX you have a lesson called Technology where you have to find a problem, and then find a way to solve it!

Our last project this year was about the weather, and me and my friend found a problem on the harbours – they don’t know the correct weather where they are. So we chosed to make a weather station.

We ended up using an Arduino Duemilanove connected to a temperature sensor, pressure sensor, rain sensor and wind speed and direction sensor. All these data is shown on a 128×64 GLCD display! Please take a look at this video to see how it ended up working (the things on the display is in danish though)…

 

The shield which is on top of the Arduino is made in Eagle. You can see the schematic here…

Source code
The source code can be found on our Github:
https://github.com/TKJElectronics/ArduinoWeatherStation

Featured in the local newspaper
We were recently (7th March 2012) out placing this weather station on the roof of a local harbour.
In that occasion we were interviewed by the local newspaper and the article (OBS. in danish) can be found here: Weather Station article

IN DANISH
Vi skrev desuden en 40 siders rapport som kan downloades herunder. Desuden lavede vi en salgsbrochure som også kan downloades.
Download Rapport
Download Brochure

Efter den ovennævnte artikel blev bragt i Dagbladet blev vi desuden ogsÃå fremvist på skolens hjemmesides nyhedssektion: http://htx.ucholstebro.dk/pages/visNyhed.asp?NewsGuid=84579

Categories: Arduino Tags:

Arduino Mega and ILI9320 Display

March 28th, 2010 33 comments

Hi everybody.
Last week I started making a ILI9320 library for the Arduino Mega, as I was hoping it would work with my 2.8″ Display (with a ILI9320 controller of course).
After a couple of hours I’ve made the code doing the timings correctly, and then I made a simple PutPixel routine. It worked, so I continued to make a Text function, and afterwards different polygons commands.
When I had made all these commands I began to optimise everything, as the Arduino isn’t running fast enough, so a complete screen clear takes about 2-3 second. After a couple of days optimizing, I got it down to 1 second, and other commands such as rectangle was alot faster. I had also made a function so I could “scroll” the screen – which is descriped in the ILI9320 datasheet!

Here you can see some pictures of the final version, and download the code here: Arduino Mega and ILI9320 code

Arduino Mega and a 2.8-inch display (ILI9320)


A close up of the Hello World screen



And here is a user posted video of the library in action on an ATMEGA16A.
Thank you to ‘Maarten van ingen’ for showing us this video.

Magnetic Card lock with the Arduino

February 17th, 2010 8 comments

I have posted alot of projects recently, and here is another project with the Arduino!
This projects is about making a magnetic card lock using the Arduino, a servo and a $4 cheap magnetic card reader from AllElectronics.com

Magnetic Card Lock project


Magnetic Card Reader Connections

The card reader, which you can see in the first picture, has 7 pins. The picture below shows theese pins functionality!

I’ve made a video about the project which explains it all!
httphd://www.youtube.com/watch?v=S1i1DAMpy5E

If you want to try it yourself, you can grab the code underneath and change the checkCode character array to match the string on your card!

#include <string.h>

#include <Servo.h>
Servo servo1;

 /* Magnetic Card lock with the Arduino and servo's
 * by Thomas Jespersen http://elec.tkjweb.dk
 *
 * Reads a magnetic stripe and opens lock (turns servo) if card is the same as programmed
 *
 */

// Connections: DATA = Pin 2, CLOCK = Pin 3, CARD IN = Pin 5
// See PDF "Magnetic Stripe Card Reader! << HACKMIAMI.pdf" for more connection information


int cld1Pin = 5;            // Card status pin
int rdtPin = 2;             // Data pin
int reading = 0;            // Reading status
volatile int buffer[400];   // Buffer for data
volatile int i = 0;         // Buffer counter
volatile int bit = 0;       // global bit
char cardData[40];          // holds card info
int charCount = 0;          // counter for info
int DEBUG = 0;
const byte checkCodeLen = 23;
char checkCode[checkCodeLen+1] = ";0123456789=0123456789?";
boolean unlock = false;

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

  servo1.attach(9);
  servo1.write(10);

  // The interrupts are key to reliable
  // reading of the clock and data feed
  attachInterrupt(0, changeBit, CHANGE);
  attachInterrupt(1, writeBit, FALLING);
}

void loop(){

  // Active when card present
  while(digitalRead(cld1Pin) == LOW){
    reading = 1;
  }

  // Active when read is complete
  // Reset the buffer
  if(reading == 1) {

    if (DEBUG == 1) {
      printBuffer();
    }

    decode();
    reading = 0;
    i = 0;

    int l;
    for (l = 0; l < 40; l = l + 1) {
     cardData[l] = '\n';
    }

    // Code added by mindthomas for buffer clearing (If not, you can just insert card slightly, and then last card data will be written)
    for (l = 0; l < 200; l = l + 1) {
      buffer[l] = 0;
    }
    // End of added code

    charCount = 0;
  }
}

// Flips the global bit
void changeBit(){
  if (bit == 0) {
    bit = 1;
  } else {
    bit = 0;
  }
}

// Writes the bit to the buffer
void writeBit(){
  buffer[i] = bit;
  i++;
}

// prints the buffer
void printBuffer(){
  int j;
  for (j = 0; j < 200; j = j + 1) {
    Serial.println(buffer[j]);
  }
}

int getStartSentinal(){
  int j;
  int queue[5];
  int sentinal = 0;

  for (j = 0; j < 400; j = j + 1) {
    queue[4] = queue[3];
    queue[3] = queue[2];
    queue[2] = queue[1];
    queue[1] = queue[0];
    queue[0] = buffer[j];

    if (DEBUG == 1) {
      Serial.print(queue[0]);
      Serial.print(queue[1]);
      Serial.print(queue[2]);
      Serial.print(queue[3]);
      Serial.println(queue[4]);
    }

    if (queue[0] == 0 & queue[1] == 1 & queue[2] == 0 & queue[3] == 1 & queue[4] == 1) {
      sentinal = j - 4;
      break;
    }
  }

  if (DEBUG == 1) {
    Serial.print("sentinal:");
    Serial.println(sentinal);
    Serial.println("");
  }

  return sentinal;
}

void decode() {
  int sentinal = getStartSentinal();
  int j;
  int i = 0;
  int k = 0;
  int thisByte[5];

  for (j = sentinal; j < 400 - sentinal; j = j + 1) {
    thisByte[i] = buffer[j];
    i++;
    if (i % 5 == 0) {
      i = 0;
      if (thisByte[0] == 0 & thisByte[1] == 0 & thisByte[2] == 0 & thisByte[3] == 0 & thisByte[4] == 0) {
        break;
      }
      printMyByte(thisByte);
    }
  }

  cardData[charCount] = '\0';

  Serial.print("Stripe_Data:");
  for (k = 0; k < charCount; k = k + 1) {
    Serial.print(cardData[k]);
  }
  Serial.println("");


 // Check if the card data is the same as the data in checkCode - if yes, unlock (turn servo)
 unlock = true;
 for (k = 0; k < checkCodeLen; k++) {
   if (cardData[k] == checkCode[k]) {
     if (DEBUG == 1) {
       Serial.print(cardData[k]);
       Serial.print("=");
       Serial.println(checkCode[k]);
     }
   } else {
     if (DEBUG == 1) {
       Serial.print(cardData[k]);
       Serial.print("!=");
       Serial.println(checkCode[k]);
     }
     unlock = false;
     break;
   }
 }

 if (unlock) {
  servo1.write(200);
  delay(2000);
  servo1.write(10);
  unlock = false;
 }


}

void printMyByte(int thisByte[]) {
  int i;
  for (i = 0; i < 5; i = i + 1) {
    if (DEBUG == 1) {
      Serial.print(thisByte[i]);
    }
}
    if (DEBUG == 1) {
      Serial.print("\t");
      Serial.print(decodeByte(thisByte));
      Serial.println("");
    }

    cardData[charCount] = decodeByte(thisByte);
    charCount ++;
}

char decodeByte(int thisByte[]) {
    if (thisByte[0] == 0 & thisByte[1] == 0 & thisByte[2] == 0 & thisByte[3] == 0 & thisByte[4] == 1){
      return '0';
    }
    if (thisByte[0] == 1 & thisByte[1] == 0 & thisByte[2] == 0 & thisByte[3] == 0 & thisByte[4] == 0){
      return '1';
    }

    if (thisByte[0] == 0 & thisByte[1] == 1 & thisByte[2] == 0 & thisByte[3] == 0 & thisByte[4] == 0){
      return '2';
    }

    if (thisByte[0] == 1 & thisByte[1] == 1 & thisByte[2] == 0 & thisByte[3] == 0 & thisByte[4] == 1){
      return '3';
    }

    if (thisByte[0] == 0 & thisByte[1] == 0 & thisByte[2] == 1 & thisByte[3] == 0 & thisByte[4] == 0){
      return '4';
    }

    if (thisByte[0] == 1 & thisByte[1] == 0 & thisByte[2] == 1 & thisByte[3] == 0 & thisByte[4] == 1){
      return '5';
    }

    if (thisByte[0] == 0 & thisByte[1] == 1 & thisByte[2] == 1 & thisByte[3] == 0 & thisByte[4] == 1){
      return '6';
    }

    if (thisByte[0] == 1 & thisByte[1] == 1 & thisByte[2] == 1 & thisByte[3] == 0 & thisByte[4] == 0){
      return '7';
    }

    if (thisByte[0] == 0 & thisByte[1] == 0 & thisByte[2] == 0 & thisByte[3] == 1 & thisByte[4] == 0){
      return '8';
    }

    if (thisByte[0] == 1 & thisByte[1] == 0 & thisByte[2] == 0 & thisByte[3] == 1 & thisByte[4] == 1){
      return '9';
    }

    if (thisByte[0] == 0 & thisByte[1] == 1 & thisByte[2] == 0 & thisByte[3] == 1 & thisByte[4] == 1){
      return ':';
    }

    if (thisByte[0] == 1 & thisByte[1] == 1 & thisByte[2] == 0 & thisByte[3] == 1 & thisByte[4] == 0){
      return ';';
    }

    if (thisByte[0] == 0 & thisByte[1] == 0 & thisByte[2] == 1 & thisByte[3] == 1 & thisByte[4] == 1){
      return '<';
    }

    if (thisByte[0] == 1 & thisByte[1] == 0 & thisByte[2] == 1 & thisByte[3] == 1 & thisByte[4] == 0){
      return '=';
    }

    if (thisByte[0] == 0 & thisByte[1] == 1 & thisByte[2] == 1 & thisByte[3] == 1 & thisByte[4] == 0){
      return '>';
    }

    if (thisByte[0] == 1 & thisByte[1] == 1 & thisByte[2] == 1 & thisByte[3] == 1 & thisByte[4] == 1){
      return '?';
    }
}

Categories: Arduino Tags: