Pyfirmata-Turret
This project guides you in creating an automated turret using an Arduino, OLED screen, distance sensor, and servos. The turret detects objects, displays data on the OLED, and tracks movements dynamically. It’s a fun and practical way to explore robotics, electronics, and programming. Follow the steps to assemble and test your turret with ease!
Supplies
- Arduino Board(2): ARDUINO A000066 Uno DIP-1.5 (Available on Amazon.ca) Link: Arduino Uno on Amazon.ca
- Servo Motors (2): Miuzei Servo Motors for Helicopter Airplane Control (Available on Amazon.ca). Link: [Servo Motors on Amazon.ca](https://www.amazon.ca/Miuzei-Motors-Helicopter-Airplane-Control/dp/B07Z16DWGW/ref
- Breadboard(2): Eiechip Breadboard Solderless Prototype Board (Available on Amazon.ca) Link: Breadboard on Amazon.ca
- Ultrasonic Distance Sensor(1): Ultrasonic Distance Measuring Transducer Sensor (Available on Amazon.ca) Link: Distance Sensor on Amazon.ca
- RGB LED(1): Tricolor Multicolor RGB LED
- Photoresistor(1): HiLetgo Light Dependent Resistor Photoresistor
- Male to Female Jumper Wires: Elegoo 120pcs Multicolored Jumper Wires (Available on Amazon.ca) Link: Male to Female Jumper Wires on Amazon.ca
- Webcam (you can also use the camera from your computer)
- 330Ω Resistors(6): Projects 10EP514330R 330Ω Resistors Pack (Available on Amazon.ca) Link: 330Ω Resistors on Amazon.ca
- LED(2): BOJACK LED
- Power source for Arduino (USB cable or batteries)
- Slide Switch(1): HiLetgo SS-12D00 Toggle Switch
Distance Sensor
Wire the Distance Sensor:
- VCC Pin: Connect the VCC pin of the distance sensor to the 5V pin on the Arduino.
- GND Pin: Connect the GND pin of the distance sensor to the GND pin on the Arduino.
- TRIG Pin: Connect the TRIG pin of the distance sensor to pin 9 on the Arduino.
- ECHO Pin: Connect the ECHO pin of the distance sensor to pin 10 on the Arduino.
After you are doen with these steps power your arduino and put this aside.
OLED Screen
Connect the OLED Screen:
- VCC Pin: Connect the VCC pin of the OLED screen to the 5V pin on the Arduino.
- GND Pin: Connect the GND pin of the OLED screen to the GND pin on the Arduino.
- SCL Pin: Connect the SCL pin of the OLED screen to the A5 pin on the Arduino (or SCL if available).
- SDA Pin: Connect the SDA pin of the OLED screen to the A4 pin on the Arduino (or SDA if available).
Upload Code
Upload the following code into your Arduino using a computer.
Downloads
Attatch Servos
Get two servo motors, place in in three-legged pin beads and connect them to the breadboard. Connect the power of the servo directly to power (without resistor or any other component), and similarly attach the other servo motor to power. Further, you would need to provide the ground of the servo motors with the ground directly from the ground rail. Connect the signal for the first servo to PIN 12 and the pin of the second servo to PIN 13.
Install Pyfirmata
In your Python environment, install the necessary libraries using:
"pip install opencv-python mediapipe pyfirmata" OR "pip3 install opencv-python mediapipe pyfirmata"
dependant on if python has been added to your computer's path or not.
Python Code
Run the attached Python script on your computer using a python compiler. This script uses OpenCV and MediaPipe to detect hand movements and controls the servo motors based on hand positions, and that would mark the end to the first breadboard.
Downloads
Logic Gate Circuit
Recreate the circuit in the image using 2 and gates one xor gate and one or gate. Attach this circuit to the arduino that controls the movement of the servos. After uploading the code, the servos won't move until you provide the correct pin of 001.