Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Yuhine
Created September 3, 2024

Automated Door Accessibility System

Automated Door Accessibility System Using SWAN 3 and Notecard Cellular NBGL for Improved Mobility

20
Automated Door Accessibility System

Things used in this project

Story

Read more

Code

code

C/C++
#include <Servo.h>
#include <Wire.h>
#include <Notecard.h>

// Define pins for the servo motor and sensor
const int servoPin = 9;
const int sensorPin = 2;  // Push button or proximity sensor input

// Instantiate servo object
Servo doorServo;

// Instantiate Notecard object
Notecard notecard;

// Define servo positions (degrees)
const int openPosition = 90;  // Position to open the door
const int closedPosition = 0; // Position to close the door

void setup() {
  // Initialize serial communication
  Serial.begin(115200);

  // Initialize servo motor
  doorServo.attach(servoPin);
  doorServo.write(closedPosition); // Start with the door closed

  // Initialize sensor pin
  pinMode(sensorPin, INPUT_PULLUP); // Assuming push button is active LOW

  // Initialize Notecard
  notecard.begin();
  notecard.sendRequest("card.status");
}

void loop() {
  // Read sensor state
  int sensorState = digitalRead(sensorPin);

  // Check if sensor is activated
  if (sensorState == LOW) {  // Adjust based on sensor type
    // Open the door
    doorServo.write(openPosition);
    delay(500);  // Wait for the door to fully open

    // Send status update
    sendDoorStatus("open");

    // Delay before closing the door
    delay(3000);

    // Close the door
    doorServo.write(closedPosition);
    delay(500);  // Wait for the door to fully close

    // Send status update
    sendDoorStatus("closed");
  }

  // Short delay before next reading
  delay(100);
}

void sendDoorStatus(const char* status) {
  // Create a Notecard request
  J *req = notecard.newRequest("note.add");
  if (req != NULL) {
    JAddStringToObject(req, "file", "door.qo");
    JAddStringToObject(req, "body", status);

    // Send the request
    J *rsp = notecard.sendRequest(req);
    if (rsp != NULL) {
      Serial.println(JGetString(rsp, "status"));
      JDelete(rsp);
    }
  }
}

Credits

Yuhine

Yuhine

1 project • 1 follower

Comments