Abstract

With the added effect of a moving spray to track the intruder using a servo motor, this motion-detecting spray gun using Arduino is guaranteed to keep your item safe from invasion. Using a Bluetooth module, we have added a second component to our system: the ability for you to control the spray with the push of a button from further away, so that you can anticipate your friends approaching your dorm room if you don’t want them to come.

Motivation

PK and I chose this project because while streaming the internet we found a motorised water gun that could spray water up to 7m away without the effort of having to manually pump the water up the straw. We wanted to replicate this in our circuit by controlling the spray ourselves through Arduino and Bluetooth. We found that one insect spray repellent, Raid bug barrier spray, used a motorised spray so that a simple press of the trigger would turn on the motor which would be responsible for spraying the repellant a range of up to 7m.

We immediately saw two quite distinct purposes of this project: the first is an ordinary boobie trap of being able to spray someone from a distance without having to exert any effort. With the use of a ping sensor, which sends out ultrasonic pulses that return to the sensor, we could set the range at which we wanted the water gun to be triggered, so that someone walking within that range would be automatically pressed. The second application would be for protecting small gardening patches; small animals such as squirrels or birds are a nuisance as they often eat and damage the garden. This system would act as an animal repellant, gentle enough not to harm the animals but strong enough to deter them from approaching the area of the semicircular zone, with radius r, that the water pray can reach. The zone would be a semicircle because of the use of a 180 degrees servo motor attached at the bottom of the water bottle, meaning that our water gun can “sweep” 180 degrees on demand. Marketability-wise, this would be a cheap and efficient way (the RAID bug spray with automated trigger gun costs only $14 off Amazon, and Arduino parts can be bought cheaply too) of simultaneously protecting your plants and also watering them, ensuring that the water used does not go to waste.

Technical process

We started by connecting the first sensory aspect of our circuit: the ping sensor and the servo motor. The servo motor was twitching at first instead of smoothly sweeping, because it was not grounded directly to the arduino, and was picking up noise from the other connections made through the breadboard. We also had to play with the settings of the angles to maximise the angular range, since each servo motor is configured with a different starting angle. We started by taking apart the inside mechanism of the Bug Auto Trigger nozzle spray, which had a small motor powered by 5V batteries. We took the batteries out, since we originally thought the 5V from the Arduino would be enough to power it. We cut the wires connecting the motor to the batteries to extend them (via soldering). This photo shows the inside disks that converts the rotating movement of the motor to the vertical motion of the straw, responsible for drawing up the water from the bottle.

The water trigger motor was responsible for the suction movement of the nozzle. We found that this motor needed 0.6A and 5V for the motor to run fast enough and for the pressure differential to draw up the water fast enough, so we had to use an external battery pack because the Arduino Uno could only supply 0.2A. We also used a MOSFET (NPN transistor) to increase the current supplied to the water gun motor. The battery pack also powered the servo motor, because we found that the servo motor worked better when supplied by this external power pack instead of the arduino.

Our initial plan was to use an ethernet shield to be able to send a text message whenever the water gun had been activated. However, we found that we delays on the ping sensor Serial.println function only delayed the speed at which the water gun motor moved, so that it was not powerful enough to draw the water up the straw. But when we had no delays, and that we had successfully connected our arduino to wifi and had set up Twilio text messaging service, the ping sensor values were too fast to correctly be processed by the internet connection. Therefore, we switched from internet to bluetooth so that a “master” could control the on/off of the water spray and essentially override the “if” conditional of the ping sensor. This served a different purpose to the text message component but was due to time and power constraints, was easier to implement with the lack of delays for the ping sensor.

The last part of our project includes the mechanical mounting and structuring of our final device. We used thick duct tape to tape the servo to the base of the bottle, and the bottom of the servo taped to the corner of a table. We taped the nozzle of the water gun to the top of the bottle. Our water gun was now taped and ready to spray.

CODE

SLAVE Circuit: include include

Servo nameservo; //initializing the variables const int out=12; const int in=13; int motorPin = 7; int pos = 0;

SoftwareSerial BTSerial (2,3);

void setup() { // setting up everything that needs to be run once: BTSerial.begin(38400);

Serial.begin(38400); pinMode(out,OUTPUT); pinMode(in,INPUT); pinMode(5, OUTPUT); pinMode(motorPin, OUTPUT); digitalWrite(motorPin, LOW); int pos = 0;

nameservo.attach(5); }

void loop() { long duration,inches; digitalWrite(out,LOW); delayMicroseconds(2); digitalWrite(out,HIGH); delayMicroseconds(10); digitalWrite(out,LOW); duration=pulseIn(in,HIGH);

//Serial.println(String(duration));

inches = microsecondsToInches (duration); Serial.print(inches); Serial.println("in, ");

if (inches<25 ) { nameservo.write(pos); digitalWrite(motorPin, HIGH); nameservo.write(pos); nameservo.write(pos++); //to make the servo rotate } else { nameservo.write(90); digitalWrite(motorPin, LOW); }

if (BTSerial.available()) { //to ensure that the bluetooth communication is taking place char inChar = (char) BTSerial.read(); //reads single character at a time Serial.println(inChar); if(inChar == 'H') { //if the button was pressed, the motor would start working nameservo.write(pos); digitalWrite(motorPin, HIGH); nameservo.write(pos--); } } nameservo.write(pos); }
long microsecondsToInches(long microseconds) { return microseconds / 74 / 2; }

MASTER Circuit: include SoftwareSerial BTSerial(2, 3); //TX RX const int button = 9; int val = 0;

void setup() { BTSerial.begin(38400); Serial.begin(38400); pinMode(button, INPUT); }

void loop() { val = digitalRead(button); if(val == HIGH) { BTSerial.print("H"); //sending the character ‘H’ when the button is pressed Serial.println("H"); } else if(val == LOW) { BTSerial.print("L"); //sending the character ‘L’ when the button is not pressed Serial.println("L"); } }

What we learned

While all the labs in the class helped us learn technical aspects and hard skills, the final project was a bit different since it also taught us soft skills such as making a timeline and following it, working as a team member, keeping our work organized, and not giving up even when things didn’t work out the right way. However, this is not to say that the final project did not prove useful in terms of learning hardware and software technicalities. First, since most of the ESE111 labs essentially required us to copy the code and then use it, we did not actually grasp the skill of writing code from scratch. But for our final project, we did have to build up the code from nothing. Second, we had to solder at many instances to make our motor work and pump up the water. So that is another important skill that the project taught us. Third, we learned how to make optimum utilisation of the equipment around us. We learned to use a Digital Multimeter for testing potential differences across different parts for the circuit, to see at which points the circuit was not working and test for short circuits (for example when we burnt a MOSFET). We also improvised when something we required was not available. For instance, we needed an Arduino Mega Board for making the wifi signal work. However, the Detkin lab had run out of these boards so we simply decided to improvise instead of panicking and changed our way of implementing IOT. The final project was a great way to get insight into how a product can be developed, tested and improved.

After our demo day, we ran a final evaluation and thought of things we could have perhaps changed or improved. One thing we could have changed was the bottle we used for the spray away gun having realized that a shorter and sturdier bottle would have been more suitable. We should have also used a longer straw to suck the water out of the bottle so that we optimise the amount of water in the bottle. Lastly, we could have improved the IoT component of the project by also implementing the text messaging feature whenever the spray was operated. The reason we did not implement it was that it caused a decrement in the speed of the motor since the wifi elements in the code took a lot of time to be processed and the water did not get pulled out efficiently. We could have possibly worked on eliminating this issue and getting the text messaging feature to work. Had we more time, we could also have made a mechanical support to keep the bottle vertically in place when taped to the table, so that it did not tilt when the servo was swinging.

Built With

Share this project:

Updates