Materials:
Rodless Cylinder
Time of Flight Sensor
Arduino Nano
Relays
5 Way 3 Position Valve
Regulator
XL Belt
Pulleys
Door Strips
YouTube Video
Downloads:
Fusion 360 File
Pololu Library
Arduino Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | /* || -NYCCNC Automitic Rubber Strip Egress (A.R.S.E.) || -version 1.1 || -author Ed Rees || -www.nyccnc.com || -10/30/2018 || || This program is free software: you can redistribute it and/or modify || it under the terms of the GNU General Public License as published by || the Free Software Foundation, either version 3 of the License, or || (at your option) any later version. || || This program is distributed in the hope that it will be useful, || but WITHOUT ANY WARRANTY; without even the implied warranty of || MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the || GNU General Public License for more details. || || You should have received a copy of the GNU General Public License || along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include // included with Arduino IDE. #include // pololu library for VL53L0X sensor. Available at: https://github.com/pololu/vl53l0x-arduino #include <avr/wdt.h> // included with Arduino IDE. VL53L0X sensor; // time-of-flight (LIDAR) person sensor 1. VL53L0X sensor2; // time-of-flight (LIDAR) person sensor 2. const int openRelay = 2; // pin 2 controls DOOR OPEN relay. const int closeRelay = 3; // pin 3 controls DOOR CLOSE relay. const int sensorRange = 3000; // shop side sensor range (mm). const int sensor2Range = 3000; // office side sensor range (mm). bool sense = true; // should sensors check for a person? bool Open = false; // open door? bool Close = false; // close door? int closeTimer = 200; // time that door stays open. (1 = ~100ms) void(* resetFunc) (void) = 0; //declare reset function @ address 0 void setup() { pinMode(openRelay, OUTPUT); // initialize open relay pin as output. pinMode(closeRelay, OUTPUT); // initialize close relay pin as output. digitalWrite(openRelay, HIGH); // set open relay HIGH to keep it closed on start. digitalWrite(closeRelay, HIGH); // set close relay HIGH to keep it closed on start. pinMode(4, OUTPUT); // initialize sensor 1 reset pin as output. pinMode(5, OUTPUT); // initialize sensor 2 reset pin as output. digitalWrite(4, LOW); // set sensor 1 reset pin LOW. digitalWrite(5, LOW); // set sensor 2 reset pin LOW. delay(50); // delay 50mS Wire.begin(); Serial.begin(9600); pinMode(4, INPUT); // set sensor 1 reset pin LOW. sensor.init(true); // initialize sensor 1. sensor.setAddress((uint8_t)22); // set i2c address of sensor 1. pinMode(5, INPUT); // set sensor 2 reset pin LOW. sensor2.init(true); // initialize sensor 2. sensor2.setAddress((uint8_t)26); // set i2c address of sensor 2. //we need to change the i2c address of the second sensor in order to support the use of multiple sensors sensor.init(); // reinitialize sensor 1 with new i2c address. sensor.setTimeout(0); // set sensor timeout mS (0 = disabled). sensor.startContinuous(100); // begin sensing at 100mS intervals. sensor2.init(); // reinitialize sensor 2 with new i2c address. sensor2.setTimeout(0); // set sensor timeout mS (0 = disabled). sensor2.startContinuous(100); // begin sensing at 100mS intervals. } void loop() { // stop sensing and begin door open/close cycle if a person is sensed. This loop sets itsself false, so it only runs once per cycle. if (sense && (sensor.readRangeContinuousMillimeters() <= sensorRange || sensor2.readRangeContinuousMillimeters() <= sensor2Range)) { sense = false; Open = true; } // If statement to Open ARSE. //This loop sets itself false, so it only runs once per cycle. if (Open) { Open = false; digitalWrite(openRelay, LOW); // activate DOOR OPEN valve. delay(600); // delay for pneumatic cylinder action. digitalWrite(openRelay, HIGH); // deactivate DOOR OPEN valve Close = true; } // If statement to close ARSE when a person is no longer sensed. //This loop sets itsself false, so it only runs once per cycle. if (Close && sensor.readRangeContinuousMillimeters() >= sensorRange && sensor2.readRangeContinuousMillimeters() >= sensor2Range) { Close = false; while (closeTimer >= 1) { if (((sensor.readRangeContinuousMillimeters() <= sensorRange || sensor2.readRangeContinuousMillimeters() <= sensor2Range)) && closeTimer <= 200) { closeTimer = 200; } closeTimer -= 1; Serial.println(closeTimer); } digitalWrite(closeRelay, LOW); // activate DOOR CLOSE valve. delay(2000); // delay for pneumatic cylinder action. digitalWrite(closeRelay, HIGH); // deactivate DOOR CLOSE valve. resetFunc(); // relay noise frequently disrupts sensor transmission, so we reset at the end of every cycle. Requires a few seconds to reset; increases long term reliability. } } |