Xbee doorbell project

Not rated 17,321

Xbee doorbell project
Xbee doorbell project

When the start button is pressed, the Arduino selects a random 4-digit code and flashes lights to indicate the code. If the user successfully repeats the code using the other buttons, the XBee module sends a message to another XBee module, which triggers a bell. The bell is connected to pin 5. The setup function initializes the bell as an output and begins serial communication at 9600 baud. The loop function checks for incoming serial data and triggers the bell if a specific character is received. Various buttons are defined with pull-down configurations, and the system captures button presses to verify against the generated code.

The electronic circuit described involves an Arduino microcontroller, an XBee wireless module for communication, and a bell actuator. The circuit is designed to function as a code entry system where a user inputs a sequence of button presses that correspond to a randomly generated code.

The Arduino's setup function configures the necessary pins, including the bell and the buttons, and initializes serial communication. The bell is activated by setting pin 5 to HIGH, which triggers the bell sound. The loop function continuously monitors for serial input. When a specific character is detected, the bell is toggled on and off in a sequence, providing auditory feedback.

The buttons are managed using a Button library that allows for easy handling of button presses. Each button is set up with a pull-down resistor configuration to ensure stable readings. The uniquePress method is utilized to detect single presses of the buttons, allowing the system to capture the user's input accurately.

The pattern generation occurs in the pickPattern function, where a random sequence of button indices is created. These indices correspond to the buttons that will be lit up, providing a visual cue for the user. The system then waits for the user to replicate this pattern by pressing the buttons in the correct order.

Once the user has pressed the number of buttons equal to the length of the generated pattern, the checkCombo function is called to verify if the input matches the expected sequence. If the user's input is correct, the system signals success by lighting an indicator LED connected to pin 11 and sending a confirmation message via serial communication.

The reset function clears the captured button presses and prepares the system for a new round of input. The startMatching function manages the state of the button presses, ensuring that the system is ready to capture the user's input while providing feedback through the visual indicators.

Overall, this circuit effectively combines input handling, random pattern generation, and feedback mechanisms to create an interactive code entry system, demonstrating the capabilities of the Arduino platform along with wireless communication using XBee modules.When you press a start button, the arduino picks a random 4 diget code and flashes lights to show the code. When you repeat the code in the other buttons, the XBee will send a message to the other XBee, which will ring the bell.

int bell=5; void setup(){ pinMode(bell, OUTPUT); Serial. begin(9600); } void loop(){ if(Serial. available()>0){ if(Serial. read()=`D`) { for(int i=0;i<=6;i+){ digitalWrite(bell, HIGH); delay(20); digitalWrite(bell, LOW); delay(20); } Serial. print(`K`); } } } #include Button btn1 = Button(10, PULLDOWN); Button btn2=Button(9, PULLDOWN); Button btn3=Button(8, PULLDOWN); Button btn4=Button(7, PULLDOWN); Button startBtn=Button(2, PULLUP); int numInPattern=4; boolean correct=false; int red=11; // store last time LED was updated long previousMillis = 0; // interval at which to blink (milliseconds) long interval = 1000; int pattern[4]={ }; int match[4]={ }; int count=0; int captureBtns=0; void setup(){ pinMode(red, OUTPUT); Serial. begin(9600); randomSeed(analogRead(0); for(int i=3;i<=6;i+){ pinMode(i, OUTPUT); } } void loop(){ //press the start btn to reset the pattern if(startBtn. uniquePress(){ // read input value and store it in val pickPattern(); } //check if user has pressed the number of buttons in pattern if (captureBtns=numInPattern) { //check if the patterns match checkCombo(); } //once pattern is selected, start capturing button presses startMatching(); } void pickPattern(){ for(int i=0;i
print("pattern="); for(int i=0;i interval) { Serial. print(`D`); // remember the last time you blinked the LED //by setting previousMillis to millis() if (Serial.

available()>0){ if(Serial. read()=`K`){ reset(); } } } else{ digitalWrite(red, LOW); } } void reset(){ captureBtns=0; count=0; correct=false; digitalWrite(red, LOW); // previousMillis = millis(); } void startMatching(){ if(captureBtns=3;i-){ digitalWrite(i, LOW); } if(btn1. uniquePress(){ popArray(1); digitalWrite(3, HIGH); delay(100); } if(btn2. uniquePress(){ popArray(2); digitalWrite(4, HIGH); delay(100); } if(btn3. uniquePress(){ popArray(3); digitalWrite(5, HIGH); delay(100); } if(btn4. uniquePress(){ popArray(4); digitalWrite(6, HIGH); delay(100); } } } void popArray(int num){ match[captureBtns]=num; Serial.

println(match[captureBtns]); captureBtns+; } 🔗 External reference