Introduction: Autonomous Sentinel Arduino Vehicle
Using the servo mounted ultrasonic and infrared sensors, the Sentinel scans for threats within its exclusion zone. Once a threat is detected, it approaches for the kill with its "laser cannon". The ultrasonic is used to detect targets at long range, while the infrared is used to control the final approach.
Well documented code is provided to enable you to perform further experimentation with the platform.
Step 1: Essentials
You will require the following items, or equivalent.
1) Any Arduino powered vehicle platform. Pictured is the DFRobotShop Rover V2.
2) SeeedStudio 3 Pin Ultrasonic Range Finder. The 3 pin is better than the available 4 pin sensors because it frees up a pin on your Arduino platform.
3) Dagu Compound Infrared Sensor. Although you could modify the project code to use any simple IR sensor, this project takes advantage of the unique left/right sensing capabilities of the Dagu.
4) Dagu Mini Pan and Tilt Kit . This project only requires a simple pan capability, but you might want to experiment with tilt capabilities later.
5) DFRobot 7.4V Lipo 2200mAh Battery. Any power pack will do, but I like the duration and size of this battery.
All items available at RobotShop
Step 2: Optional Sensor Shield
A sensor shield simplifies attachment of all the various sensors and components to your Arduino. Highly recommended... many are available.
Pictured is the DFRobot I/O Expansion Shield V7
Step 3: Optional On-board I/O Module
TM1638 Display Module. Easily found on eBay, this module provides you with simple I/O capabilities on your platform.
Step 4: Optional Weaponry
Red Dot Laser Module. What good is a Sentinel without weaponry? Easily found on eBay, the laser module provides this.
Or you could build your own from any laser pointer you have laying around. Remove batteries, tape switch "on", connect the "spring" inside the body to ground, and connect the "body" to your signal pin. If this doesn't work, change connections. Pretty easy.
Step 5: Build Your Vehicle
Since this project is not really specific to any vehicle platform, I'll leave it to you to build your own vehicle. Many kits are available, you could build your own from scratch using another Instructable, or your could redeploy a platform you already have.
You'll want the ultrasonic and IR sensors mounted on the pan/tilt servo assembly and facing forward so it can scan the target area ahead of the Sentinel.
Pictured is my DFRobotShop Rover V2 with expansion plate and sensor shield.
The second forward facing ultrasonic sensor is for a different project, not used here.
Here are the pin assignments used by the code provided in the next step. More details on these can be found in the code.
2 PANPIN (servo)
4 RANGEFINDERPIN (ultrasonic)
5 MOTORRIGHTSPEED (motor speed & direction)
9 LASERPIN (cannon)
10 TM1638STBPIN (optional on board display module)
13 IRLEDSPIN (compound IR LEDs)
A2 IRRIGHTPIN (compound IR phototransistors)
Step 6: The Algorithm
The Sentinel remains stationary while the pan servo scans for targets using the long range ultrasonic sensor. Panning occurs from 0 degrees (right) to 180 degrees (left), and back again.
When a target is detected, the vehicle pivots and the servo pans in opposite directions until the target is "directly ahead". In the case of the provided illustration, a target has been detected at 45 degrees, so the Sentinel will pivot right while continuing to pan left until the pan servo angle shows the target to be somewhere in the 80 to 100 degree range.
At that point it begins the approach. If everything goes correctly, it will move ahead until the more precise compound IR sensor detects the target and brings it in for a "kill shot" when a predetermined distance has been reached.
If the target is lost during this process (which it often is because of the imprecise nature of cheap sensors), the Sentinel will stop and resume scanning. Once the target is located again, the process continues as before.
If the Sentinel finds itself too close to the target, it will retreat until a safe distance is achieved.
A video is provided later in this Instructable to demonstrate all of this action.
Step 7: The Sensors Explained
The ultrasonic sensor operates by sending a short ultrasonic pulse , and measuring the time it takes to receive an "echo" back. The shorter the amount of time, the closer the object.
Using a predefined library (included in provided code), the code to accomplish this is rather simple...
panRangeInCentimeters = ultrasonicPan.microsecondsToCentimeters();
The compound IR sensor works by emitting IR light onto an object and then detecting the reflected IR. The level of reflected light read by each of the 8 phototransistors allows the compound sensor to detect where the object is. For example, if the left phototransisters read 200 and the right ones read 100, that must mean there is something on the left reflecting more IR light back. The Dagu Compound IR Sensor has 2 each Top, Bottom, Left, and Right phototransistors, and 4 IR LEDS.
Here is sample code showing the left and right sensor logic...
// Turn on IR LEDs to read Total light (ambient + reflected IR)
// Allow time for phototransistors to respond
// Total = Ambient + LED IR reflected from object
irLeft = analogRead(IRLEFTPIN);
irRight = analogRead(IRRIGHTPIN);
// Turn off IR LEDs to read Ambient light (ie natural light)
// Reflected IR = Total (read previously) - Ambient (read now)
irLeft = irLeft - analogRead(IRLEFTPIN);
irRight = irRight - analogRead(IRRIGHTPIN);
Step 8: Install Code
This is where the magic happens.
I've provided an extensively documented Arduino sketch that provides the AI for your Sentinel.
If you've configured your components correctly in the previous step, it should work as is. Some fine tuning will probably be required.
Step 9: Your Turn to Code!
There's lots more you can do with this project.
How about another sensor in the back to guard against sneak attacks from behind? Or side sensors?
Why not try coding a "patrol sequence"? Right now it just sits in the same spot waiting for something to happen. You could develop some AI to be more of a hunter.
For more experimentation with this platform, visit my related Instructable Autonomous Wall Hugging Arduino Vehicle
1 Person Made This Project!
- L1Ranger made it!