Introduction: Light Sensor Glove
In this project we will be attaching an arduino, bread board (with respected parts and wires), and a servo motor to a glove which will be powered by a 9v battery pack. When the glove is pointed at an object a certain light will go on and the servo motor will point to that light, depending on how far away the object is.
Step 1: Materials
- 1 Arduino
- 1 Breadboard
- At least 20 Male wires
- 3 LED lights (Different Colors)
- 1 Servo Motor
- 1 Ultrasonic distance sensor
- 1 9v battery pack (with battery)
Step 2: Building
- Connect the Ultrasonic Distance Sensor
- Establish ground on the bread board by hooking up a mail wire to ground on the arduino
- Connect a wire to the first leg of the uds to ground
- The second to pinmode 11 on the arduino
The third to pinmode 12 on the arduino
The fourth to 5v on the arduino
- Connect the Three LED Lights
- First, make sure each similar leg of the LED is placed in different rows
- Connect each of the long legs of the LEDs, with a male wire, to their respected pinmodes (EX: Green; 8 Yellow; 9 Red; 10)
- Connect each short leg of the LEDs, with a male wire, to ground
- Connect the Servo Motor
- Connect the middle wire to "VIN" on the arduino
- Connect the wire to the right of that (usually brown) to ground
Connect the wire to the left of that (usually yellow) to pinmode 3 on arduno
- When this is done, you can connect it to a glove!
Step 3: Step 3: the Code
#include
Servo myservo; // create servo object to control a servo // twelve servo objects can be created on most boards
int pos = 0;
int led=8;
int val=0;
int yled=9;
int rled=10;
void setup (){
Serial.begin(9600);
pinMode(12,OUTPUT);
pinMode(11,INPUT);
pinMode(led,OUTPUT);
pinMode(yled,OUTPUT);
pinMode(rled,OUTPUT); }
void loop () {
long duration, inches;
digitalWrite (12, LOW);
delayMicroseconds(2);
digitalWrite (12, HIGH);
delayMicroseconds(5);
digitalWrite (12, LOW);
duration = pulseIn (11, HIGH);
inches = duration / 74 / 2;
if (val>0 && val<10);{
myservo.write(40);
analogWrite(led,255);
analogWrite(rled,0);
analogWrite(yled,0);
}
if(val>10 && val<40){
myservo.write(90);
analogWrite(yled,255);
analogWrite(rled,0);
analogWrite(led,0);
}
if(val>40&&val<70){
myservo.write(130);
analogWrite(rled,255);
analogWrite(led,0);
analogWrite(yled,0);
}
Serial.println(inches); delay(200); }