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 Jan 4, 2024

IR barrier reverse engineering test code

This code assumes that you have connected your analog sensors to pins A0, A1, and A2, and an LED to pin D13 on your Arduino board. Adjust the pin configurations based on your actual hardware connections if necessary. The voltages are read and printed to the serial monitor, and if any of them goes below 3 volts, the LED on pin D13 is turned on for X seconds.

const int analogPinA0 = A0;
const int analogPinA1 = A1;
const int analogPinA2 = A2;
const int ledPin = 13;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // Read voltages from analog pins
  float voltageA0 = analogRead(analogPinA0) * (5.0 / 1023.0);
  float voltageA1 = analogRead(analogPinA1) * (5.0 / 1023.0);
  float voltageA2 = analogRead(analogPinA2) * (5.0 / 1023.0);

  // Check if any voltage is lower than 3 volts
  if (voltageA0 < 3.0 || voltageA1 < 3.0 || voltageA2 < 3.0) {
  
    // Output message to serial monitor
    Serial.println("Voltage below 3V detected. LED turned on.");
    
    // Output voltages to serial monitor
    Serial.print("Voltage A0: ");
    Serial.print(voltageA0);
    Serial.print("V, Voltage A1: ");
    Serial.print(voltageA1);
    Serial.print("V, Voltage A2: ");
    Serial.print(voltageA2);
    Serial.println("V");
    
    // Turn on LED for X seconds
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
    
  }

  delay(50); // Adjust delay as needed
}

@X3msnake
Copy link
Author

X3msnake commented Feb 12, 2024

Merged Code

With the help of Copilot
https://sl.bing.net/IzeIaj9otg


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

#define OFF 0
#define ON 1

const int analogPinA0 = A0;
const int analogPinA1 = A1;
const int analogPinA2 = A2;

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(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);
    
  // Read voltages from analog pins
  float voltageA0 = analogRead(analogPinA0) * (5.0 / 1023.0);
  float voltageA1 = analogRead(analogPinA1) * (5.0 / 1023.0);
  float voltageA2 = analogRead(analogPinA2) * (5.0 / 1023.0);

  // Check if any voltage is lower than 3 volts
  if (voltageA0 < 3.0 || voltageA1 < 3.0 || voltageA2 < 3.0) {
    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 = 30;
  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()

@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