The Illumi-naughty
By: Abdul Rahman Syed, Michaela Petrova, Aya Bakaraki, Dara Abu Khajil, Naima Baig
The Daniels registrar seeks to stop its slaves from napping on the job to ensure maximum productivity. Thus we introduce the Illumi-naughty. The goal of the weapon is to sense when someone is sleeping through the ultrasonic sensor.
Supplies
Materials:
- A toy gun (trigger activated)
- 9V battery
- Arduino Uno + USB cable for computer connection
- Servomotor
- Ultra Sonic Sensors x6
- Bread Boards x6
- Jumper Wires
- Wooden plates
- Wooden dowels
Code Explanation
Initialization:
#define trigPinR1 3 // R stands for right side
#define echoPinR1 2 // L stands for left side
// No letter or C means center
#define trigPinR2 5 // 1 means lower level
#define echoPinR2 4 // 2 means upper level
#define trigPin 7
#define echoPin 6
#define trigPin2 9
#define echoPin2 8
#define trigPinL1 11
#define echoPinL1 10
#define trigPinL2 13
#define echoPinL2 12
#include <Servo.h> //allows for servos to work
Servo myservo;
int pos = 0;
Sensor Setup
long durationR1, distanceR1; //long creates a variable for duration and distance
digitalWrite(trigPinR1, LOW);
delayMicroseconds(2);
digitalWrite(trigPinR1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPinR1, LOW);
//the last five lines turn the trigger off, then on for a few microseconds, and then off again
durationR1 = pulseIn(echoPinR1, HIGH);
//reads the time it took for the ultrasonic wave to come back to the sensor
distanceR1 = (durationR1/2) / 29.1;
//distance is calculated by dividing duration by 2 (since the wave goes and comes back) and by 29.1 (related to the speed of sound at 20 degrees C).
Shooting Condition
if (distanceR1 <=40 && distanceR2 >=80)
//activates if the distance from the desk level sensor is less than 40 and greater than 80 for the head level sensor
{
digitalWrite(LED_BUILTIN, HIGH);
//turns the built in LED on to test that sensors are detecting when gun isn't connected
delay(1500);
myservo.write(pos);
pos = 90;
delay(1500);
myservo.write(pos);
pos =180;
delay(1500);
myservo.write(pos);
pos = 0;
//rotation of the servo for the gun
}
else{
digitalWrite(LED_BUILTIN, LOW);
}
Code
#define trigPinR1 3
#define echoPinR1 2
#define trigPinR2 5
#define echoPinR2 4
#define trigPin 7
#define echoPin 6
#define trigPin2 9
#define echoPin2 8
#define trigPinL1 11
#define echoPinL1 10
#define trigPinL2 13
#define echoPinL2 12
#include <Servo.h>
Servo myservo;
int pos = 0;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(trigPinL1, OUTPUT);
pinMode(echoPinL1, INPUT);
pinMode(trigPinL2, OUTPUT);
pinMode(echoPinL2, INPUT);
pinMode(trigPinR1, OUTPUT);
pinMode(echoPinR1, INPUT);
pinMode(trigPinR2, OUTPUT);
pinMode(echoPinR2, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
myservo.attach(A0);
}
void loop() {
// right side
long durationR1, distanceR1;
digitalWrite(trigPinR1, LOW);
delayMicroseconds(2);
digitalWrite(trigPinR1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPinR1, LOW);
durationR1 = pulseIn(echoPinR1, HIGH);
distanceR1 = (durationR1/2) / 29.1;
if (distanceR1 >= 100 || distanceR1 <= 0)
{
Serial.println("Out of rangeR1");
}
else {
Serial.print(distanceR1);
Serial.println(" cm R1");
}
long durationR2, distanceR2;
digitalWrite(trigPinR2, LOW);
delayMicroseconds(2);
digitalWrite(trigPinR2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPinR2, LOW);
durationR2 = pulseIn(echoPinR2, HIGH);
distanceR2 = (durationR2/2) / 29.1;
if (distanceR2 >= 100 || distanceR2 <= 0)
{
Serial.println("Out of rangeR2");
}
else {
Serial.print(distanceR2);
Serial.println(" cm R2");
}
// center
long durationC1, distanceC1;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
durationC1 = pulseIn(echoPin, HIGH);
distanceC1 = (durationC1/2) / 29.1;
if (distanceC1 >= 100 || distanceC1 <= 0)
{
Serial.println("Out of range");
}
else {
Serial.print(distanceC1);
Serial.println(" cm C1");
}
long durationC2, distanceC2;
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
durationC2 = pulseIn(echoPin2, HIGH);
distanceC2 = (durationC2/2) / 29.1;
if (distanceC2 >= 100 || distanceC2 <= 0)
{
Serial.println("Out of range 2");
}
else {
Serial.print(distanceC2);
Serial.println(" cm C2");
}
//left side
long durationL1, distanceL1;
digitalWrite(trigPinL1, LOW);
delayMicroseconds(2);
digitalWrite(trigPinL1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPinL1, LOW);
durationL1 = pulseIn(echoPinL1, HIGH);
distanceL1 = (durationL1/2) / 29.1;
if (distanceL1 >= 100 || distanceL1 <= 0)
{
Serial.println("Out of rangeL1");
}
else {
Serial.print(distanceL1);
Serial.println(" cm L1");
}
long durationL2, distanceL2;
digitalWrite(trigPinL2, LOW);
delayMicroseconds(2);
digitalWrite(trigPinL2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPinL2, LOW);
durationL2 = pulseIn(echoPinL2, HIGH);
distanceL2 = (durationL2/2) / 29.1;
if (distanceL2 >= 100 || distanceL2 <= 0)
{
Serial.println("Out of rangeL2");
}
else {
Serial.print(distanceL2);
Serial.println(" cm L2");
}
//servo right condition
if (distanceR1 <=40 && distanceR2 >=80)
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1500);
myservo.write(pos);
pos = 90;
delay(1500);
myservo.write(pos);
pos =180;
delay(1500);
myservo.write(pos);
pos = 0;
}
else{
digitalWrite(LED_BUILTIN, LOW);
}
//servo center condition
if (distanceC1 <=40 && distanceC2 >=80)
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1500);
myservo.write(pos);
pos = 90;
delay(1500);
myservo.write(pos);
pos =180;
delay(1500);
myservo.write(pos);
pos = 0;
}
else{
digitalWrite(LED_BUILTIN, LOW);
}
//servo left condition
if (distanceL1 <=40 && distanceL2 >=80)
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1500);
myservo.write(pos);
pos = 90;
delay(1500);
myservo.write(pos);
pos =180;
delay(1500);
myservo.write(pos);
pos = 0;
}
else{
digitalWrite(LED_BUILTIN, LOW);
}
delay(1500);
}
Base
Construct the base of the structure and the connecting three lower walls, leaving two holes in each wall for the ultrasonic sensors.
Desk Level Sensors
Place into position three ultrasonic sensors on the lower level, one on each side through the holes of the walls. Place the sensors into the breadboards, connecting the power and ground wires of each sensor into one breadboard (central board) and then connect that breadboard to the power and ground wires into the Arduino. In the physical example, the central board is made a larger size, in the fritzing diagram it is quite literally in the center.
Ceiling
Add another floor to separate the lower wiring level and make a platform for the servo. Be sure to add dowels underneath to support the higher floors.
Servo
Screw in a piece of wood on top of the servo to give the gun a base to sit on. Glue the servo into the middle of the second floor. Connect the power and ground wires into the servo breadboard and then the input wire into its respective pin based on pin A0.
Gun Attachment
Glue the gun's supporting floor into position and then position the gun through the floor. Glue the gun onto the servo.
Upper Sensor Level
Construct the upper sensor floors separately from the main body and then position the sensors in their place. Wire the power and ground wires into the breadboards that are located underneath each sensor. In other words, the power and ground wires for the upper left sensor should go into the lower left sensor breadboard.
Connecting the Floors
Assemble both parts by adding supporting dowels onto the gun floor and the upper sensor floors above.
ILLUMANTI CONFIRMED (Optional)
Glue together three walls of the pyramid at the top. Add an LED strip inside and then glue the final wall into place sealing the pyramid up. The red eye of the elite now watches. Glue it at the top of the Illumi-naughty.
Wire the Arduino
Attach all the echo pin and trigger pin wires into the Arduino and their respective ports. Once more Capitalism is upheld.
Conclusion
The process of coding and fabrication in a team is an experience that has improved our coding skills, physical computing on elements, functions, and arrangement, and creative application of the gained skills in physical terms. Throughout the project, developing the core function and robot purpose has been achieved. Originally, a toy gun is supposed to expose bubbles after detecting a movement captured by an ultrasonic motion sensor. However, due to the position of the servo in the structure, we couldn't achieve this goal. We left it for further brainstorming and exploration but further on we will strive to achieve the full functioning of a toy gun.