I just made this Ardruino Nano cubicle alarm. If anybody is within a few feet of your work cubicle, including behind me, the led will turn red.
I used the HC-SR04 ultra-sonic sensor: 1.) 5V on Arduino to VCC of HC-SR04 2.) Dig pin 12 on Arduino to Trig of HC-SR04 3.) Dig pin 13 on Arduino to Echo of HC-SR04 4.) GND on Arduino to GND of HC-SR04 Here's my sketch:#include Ultrasonic ultrasonic(12,13); int ledPin = 11; long int distanceInches; void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); } void loop() { Serial.print(ultrasonic.Ranging(INC)); Serial.println("in"); distanceInches = ultrasonic.Ranging(INC); if (distanceInches < 200) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } delay(100); }
Next I want to get the HC-SR04 Sonic Sensor working with Rasberri Pi https://www.modmypi.com/blog/hc-sr04-ultrasonic-range-sensor-on-the-ras…