![]() ![]() #define RELAY1 31 #define RELAY2 33 #define RELAY3 35 #define RELAY4 37 #define RELAY5 39 #define RELAY6 41 #define RELAY7 43 #define RELAY8 45 NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE) // NewPing setup of pins and maximum distance. Maximum sensor distance is rated at 400-500cm. #define MAX_DISTANCE 60 // Maximum distance we want to ping for (in centimeters). #define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor. ![]() Whenever an object is brought in the range of the sonar, the screensaver mode turns off and the user has control of the valves once again.īelow is the actual code used in Arduino Mega #include #define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor. Now the code takes control and does its own pattern opening and closing the valves. Based on the averaged distance data, a corresponding relay channel was activated and thus, a valve was opened.Īfter 9 seconds of no proper distance value from the sonar, a screensaver mode would be activated. The last 5 values given by the sonar were averaged so that the whole system wouldnt be too jumpy or fast. But we used a regulator to get a more fitting 5V voltage.īasically, code pinged the sonar at 30 ms intervals and received the distance to any object in front of the sonar. The Arduino was also powered by the 12V power source. The valves and LED were powered by a 12V 2.0A power source which could be directly plugged to a wall outlet. Instead, an the 8-channel relay was used which could be controlled directly by the Arduino. The valves were 24V and the LED were 12V, so we couldn't directly control them with the Arduino without overheating. Arduino Mega and a 8-channel relay was used to control the digital valves. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |