Introduction: Moving Shield
This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)
This project was intended to be as an alarm/warning system tells the user when something approaches too close.
Step 1: Design
Design your own parts in CAD. You'll have to make the arm, shield, box, and lid.
Adjust the measurements to your own preference.
Step 2: Circuit
Use a 9V battery to power the Arduino. Use the Arduino to power and ground the system with the bread board as the "middle man". Attach the proximity sensor and the servo motor to the bread board. Make sure to power and ground the two correctly.
The proximity sensor should also have a pin going straight into the Arduino. Make sure that you have the right connecting pin in the code.
Step 3: Code
#include
#include
#define echoPin 9
#define triggerPin 8
LiquidCrystal_I2C lcd(0x3F,16, 2); Servo servo;
int servopin = 6;
int threshold = 31;
void setup()
{
Serial.begin(9600);//start serial communication
pinMode(echoPin, INPUT);//set pinmodes
pinMode(triggerPin, OUTPUT);
servo.attach(servopin); //servo.write(90);
}
void loop() {
digitalWrite(triggerPin, HIGH); // make a 10usec pulse
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
int distance = pulseIn(echoPin,HIGH); //now read the pulse that is sent back by the sensor //pulseIn returns the pulse length in usec
distance= distance/58; //the distance in [cm] is calculated by pulselength[sec]/58 Serial.println(distance); //Serial.print("hello");
int degree(0);
if(0 <= distance && distance <= 6) degree = 90;
else if(7 <= distance && distance <= 12) degree = 99;
else if(13 <= distance && distance <=18) degree = 118;
else if(19 <= distance && distance <= 24) degree = 127;
else if(25 <= distance && distance <= 30) degree = 136;
else degree = 140;
servo.write(degree);
}
Step 4: Finished Product
Note: The attachment on the end of the shield is a key chain. It is used in this project as a sound making object to demonstrate the build's ability to "sound" the alarm. You could use a bell for the shield to hit or another way of making sound.