I am working on an alarm system using ultrasonic sensor.
At the beginning I had a simple circuit where if the sensor detects any obstacles closer than 5 cm the LED and the buzzer will go on if not they will remain off as a second step I added a keypad where if 1 is pressed the sensor will start detecting any obstacles and if any is closer than 5 cm the LED and the buzzer will go on if not they will remain off but with this addition the sensor wasn't as accurate any-more and when I tried to add a tone and a delay before the sensor starts detecting anything and after the button 1 is pressed the sensor is completely not accurate and not giving the right measurement thus the whole project isn't functioning as supposed to and while I am running the program the following error is appearing:
Error inside Serial.serialEvent()
java.io.IOException: Bad file descriptor in nativeavailable
at gnu.io.RXTXPort.nativeavailable(Native Method)
at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532)
at processing.app.Serial.serialEvent(Serial.java:258)
at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
I attached my code
Any help is very much appreciated
![]()
alarm_system_code.txt (1.67 KB)