Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
c010rblind3ngineer
Published © GPL3+

Arduino 'Can't Touch This' Device

Prevent people from touching your stuffs when you're away from your desk!

IntermediateShowcase (no instructions)142
Arduino 'Can't Touch This' Device

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Analog Accelerometer: ADXL335
Adafruit Analog Accelerometer: ADXL335
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×1
5 mm LED: Red
5 mm LED: Red
×1
Buzzer
Buzzer
Passive Buzzer
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 330 ohm
Resistor 330 ohm
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Schematics

Circuit:

Schematic:

Code

Code:

Arduino
/* Arduino 'Can't Touch This' Device

   Components:
                - Arduino Nano
                - ADXL335
                - Passive Buzzer
                - Push button tactile switch
                - Red LED
                - 220Ohm resistor
                - 330Ohm resistor
                - 10kOhm resistor
                - Breadboard
                - Some jumper wires

   Created on 26 July 2022 by c010blind3ngineer
*/

int X_axis = A0;
int Y_axis = A1;
int Z_axis = A2;
const int buzzerPin = 9;
const int LEDpin = 8;
const int btnPin = 7;
const int deg_acc = 3;
boolean trigAlarm = false;
int x, y, z;

int STILL[4];

void setup() {
  analogReference(EXTERNAL);
  pinMode(buzzerPin, OUTPUT);
  pinMode(LEDpin, OUTPUT);
  pinMode(btnPin, INPUT);
  Serial.begin(9600);
  while (digitalRead(btnPin) != HIGH) {}
}

void loop() {
  if (digitalRead(btnPin) == HIGH) {
    Serial.print("Calibrating");
    delay(500);
    int i = 0;    // reset 'i' counter
    while (i < 3) {   // read XYZ readings 3 times, it also gives the User time to stabilise the device properly
      Serial.print(".");
      STILL[0] = analogRead(X_axis);
      STILL[1] = analogRead(Y_axis);
      STILL[2] = analogRead(Z_axis);
      delay(500);
      i++;
    }
    digitalWrite(LEDpin, HIGH);
    tone(buzzerPin, 2000);
    delay(100);
    digitalWrite(LEDpin, LOW);
    noTone(buzzerPin);
    delay(100);
    digitalWrite(LEDpin, HIGH);
    tone(buzzerPin, 2000);
    delay(100);
    digitalWrite(LEDpin, LOW);
    noTone(buzzerPin);
    trigAlarm = false;
  }
  // Read XYZ axis values
  x = analogRead(X_axis);
  y = analogRead(Y_axis);
  z = analogRead(Z_axis);

  // Check to see if the device is in the same position when the User set it initially
  if ((x > (STILL[0] - deg_acc)) && (x < (STILL[0] + deg_acc)) && (y > (STILL[1] - deg_acc)) && (y < (STILL[1] + deg_acc)) && (z > (STILL[2] - deg_acc)) && (z < (STILL[2] + deg_acc)) ) {
    // You can uncomment the lines below to see the XYZ values in the Serial Monitor
    //    Serial.print(x);
    //    Serial.print("\t");
    //    Serial.print(y);
    //    Serial.print("\t");
    //    Serial.print(z);
    //    Serial.println();
  }
  else {
    trigAlarm = true;
  }
  // Alarm goes off when someone moves the device out of position
  if (trigAlarm == true) {
    digitalWrite(LEDpin, HIGH);
    tone(buzzerPin, 2000);
    delay(100);
    digitalWrite(LEDpin, LOW);
    noTone(buzzerPin);
  }
  delay(100);
}

Repository link:

Credits

c010rblind3ngineer
5 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.