Skip to content

Instantly share code, notes, and snippets.

@X3msnake
Last active February 12, 2024 19:28
Show Gist options
  • Save X3msnake/486318a4bb46f73e65e2fa581b72904b to your computer and use it in GitHub Desktop.
Save X3msnake/486318a4bb46f73e65e2fa581b72904b to your computer and use it in GitHub Desktop.

Bayamo hand dryer reverse engineering

Counter board

image SN74HC164 GD-4021LB

IR Led Barrier

image Infrared Sensor: IRM-56384


/*

http://www.bristolwatch.com/arduino/arduino3.htm
Connecting Arduino to a 74C164 Shift Register
Lewis Loflin lewis@bvu.net

Demo to shift byte into 74HC164
8-Bit Serial-In - Parallel-Out Serial Shift Register
Will count from 0 to 255 in binary on eight LEDs

The 74HC164 has three inputs:

Input A-B (pins 1, 2) is for data. they can be tied
together or the one not used tied to +Vcc

Clock pin 8 data is serially shifted in and
out of the 8-bit register during
the positive going transition of clock pulse.

Clear (pin 9) is independent of the clock
and accomplished by a low level at the
clear input.

As far as LSB first or MSB bit first is up to software
and electrical connections on the output

*/

#define DATA 12
#define CLK 11
#define CLR 9
#define VCC 2
#define SIG A0
#define RLAY 6

#define OFF 0
#define ON 1

unsigned long startMillis;  // some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 1000;  // the value is a number of milliseconds

byte i, j, temp, val;

int data[] = {2, 62, 72, 40, 52, 160, 128, 50, 0, 32};

void setup() {
  pinMode(DATA, OUTPUT);
  pinMode(CLK, OUTPUT);
  pinMode(CLR, OUTPUT);
  pinMode(VCC, OUTPUT);
  pinMode(SIG, INPUT_PULLUP);
  pinMode(RLAY, OUTPUT);

  pinMode(13, OUTPUT);  // used to test-debug various sections of code

  digitalWrite(CLK, OFF);
  digitalWrite(CLR, OFF); // active LOW
  digitalWrite(VCC, ON);

  startMillis = millis();  // initial start time

  Serial.begin(115200); // open the serial port at 9600 bps:

  resetDigits();
}

void loop() {
  
  digitalWrite(13, OFF); // Debug LED 
  digitalWrite(RLAY, OFF); // PowerRelay
  delay(500);
    
  if (!digitalRead(SIG)) {
    digitalWrite(13, ON); // Debug LED
    digitalWrite(RLAY, ON); // PowerRelay

    handleInfraredSensor();
  }
  
}

void handleInfraredSensor() {

  unsigned long previousMillis = millis();
  unsigned long interval = 0; // Adjust this interval as needed

  int number = 60;
  int digit1 = 0;
  int digit2 = 0;

  while (number > 0) {
    if (millis() - previousMillis >= interval) {
      previousMillis = millis();  // Save the last time the digit was updated

      digit1 = number / 10; // First digit of the number
      digit2 = number % 10; // Second digit of the number

      // Display the same count number on both digits
      for (int count = 0; count < 50; count++) {
        digitalWrite(CLR, HIGH); // Select first 7-segment display
        val = data[digit1]; // Set value for the first 7-segment display
        shiftData(val); // Shift the data into the shift register
        delay(10); // Display the first digit for a short time

        digitalWrite(CLR, LOW); // Select second 7-segment display
        val = data[digit2]; // Set value for the second 7-segment display
        shiftData(val); // Shift the data into the shift register
        delay(10); // Display the second digit for a short time
      }

      number--;
     }
     resetDigits();
   }
 }


void shiftData(byte val) {
  for (j = 0; j < 8; j++) {
    temp = (val >> j) & 0x01;
    digitalWrite(DATA, temp);
    pulsout(CLK, 0);
  }
}

void resetDigits(){
     digitalWrite(CLR, LOW); // Select first 7-segment display
     shiftData(B11111111); // Shift the data into the shift register
     digitalWrite(CLR, HIGH); // Select first 7-segment display
     shiftData(B11111111); // Shift the data into the shift register
}

// inverts state of pin, delays, then reverts state back
void pulsout(byte x, int y) {
  byte z = digitalRead(x);
  z = !z;
  digitalWrite(x, z);
  delayMicroseconds(y);
  z = !z; // return to original state
  digitalWrite(x, z);
  return;
} // end pulsout()


image image


image

@X3msnake
Copy link
Author

X3msnake commented Feb 12, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment