3) Fix parts A and C together with 2 pointed screws.
4) Internally attach the servo motor to part C. Then place the servo motor on part B and screw it.
5) For the holder, cut one of the servo motor heads in the middle of the gear part that you printed on the 3D printer and place it into the gear. Then screw it to the servo motor.
6) Adhere together the 3D printed Linear gear and the handle with strong adhesive.
7) Place the servo in the 3D print holder and fix it. You can do this with hot silicone or by screwing. When placing the servo gear on the linear gear, make sure it is fully open.
8) Attach the holding servo system to part B with silicone.
9) Pass the piece we prepared in step 3 over the cylinder we prepared from cardboard in the first step and fix it with silicone.
10) Put the motor drive jumpers on the Servo pins. Connect the cable of the holding servo to the GPIO21 and the cable of the tilting servo to the GPIO22.
from machine import Pin, PWM, ADC
from utime import sleep
from picobricks import WS2812
# Define libraries
ws = WS2812(6, brightness=0.3)
ldr = ADC(27)
buzzer = PWM(Pin(20, Pin.OUT))
servo1 = PWM(Pin(21))
servo2 = PWM(Pin(22))
# Define LDR, buzzer, and servo motor pins
servo1.freq(50)
servo2.freq(50)
buzzer.freq(440)
# Define frequencies of servo motors and buzzer
# RGB color settings
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
angleupdown = 4770
angleupdown2 = 8200
def up():
global angleupdown
for i in range(45):
angleupdown += 76
servo2.duty_u16(angleupdown)
sleep(0.03)
buzzer.duty_u16(2000)
sleep(0.1)
buzzer.duty_u16(0)
# Servo2 goes up at specified intervals
def down():
global angleupdown
for i in range(45):
angleupdown -= 76
servo2.duty_u16(angleupdown)
sleep(0.03)
buzzer.duty_u16(2000)
sleep(0.1)
buzzer.duty_u16(0)
# Servo2 goes down at specified intervals
def open():
global angleupdown2
for i in range(45):
angleupdown2 += 500
servo1.duty_u16(angleupdown2)
sleep(0.03)
buzzer.duty_u16(2000)
sleep(0.1)
buzzer.duty_u16(0)
# Servo1 works for opening the clamps
def close():
global angleupdown2
for i in range(45):
angleupdown2 -= 500
servo1.duty_u16(angleupdown2)
sleep(0.03)
buzzer.duty_u16(2000)
sleep(0.1)
buzzer.duty_u16(0)
# Servo1 works for closing the clamps
open()
servo2.duty_u16(angleupdown)
ws.pixels_fill(BLACK)
ws.pixels_show()
while True:
if ldr.read_u16() > 20000:
ws.pixels_fill(RED)
ws.pixels_show()
sleep(1)
buzzer.duty_u16(2000)
sleep(1)
buzzer.duty_u16(0)
open()
sleep(0.5)
down()
sleep(0.5)
close()
sleep(0.5)
up()
ws.pixels_fill(GREEN)
ws.pixels_show()
sleep(0.5)
# According to the data received from LDR, RGB LED lights red and green and servo motors move
Robot Arm Servo Code:
from machine import Pin, PWM
servo1 = PWM(Pin(21))
servo2 = PWM(Pin(22))
servo1.freq(50)
servo2.freq(50)
servo1.duty_u16(8200) # 180 degree
servo2.duty_u16(4770) # 90 degree
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define NUMPIXELS 1
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
#include <Servo.h>
Servo myservo1;
Servo myservo2;
int angleupdown;
void setup() {
pinMode(20, OUTPUT);
pinMode(27, INPUT); // define input and output pins
pixels.begin(); // Initialize the NeoPixel library.
pixels.clear(); // Initialize all pixels to 'off'
myservo1.attach(21);
myservo2.attach(22); // Attach the servos.
Open();
angleupdown = 180;
myservo2.write(angleupdown);
}
void loop() {
if (analogRead(27) > 150) {
pixels.setPixelColor(0, pixels.Color(255, 0, 0)); // Red color.
pixels.show();
delay(1000);
tone(20, 700); // Sound the buzzer
delay(1000);
noTone(20); // Stop the buzzer
Open();
delay(500);
Down();
delay(500);
Close();
delay(500);
Up();
pixels.setPixelColor(0, pixels.Color(0, 255, 0)); // Green color.
pixels.show();
delay(500);
// Clear the color after a delay.
pixels.setPixelColor(0, pixels.Color(0, 0, 0)); // Off
pixels.show();
delay(500);
Open();
angleupdown = 180;
myservo2.write(angleupdown); // Reset the servo position
}
}
void Open() {
myservo1.write(180); // Servo opens
}
void Close() {
myservo1.write(30); // Servo closes
}
void Up() {
for (int i = 0; i < 45; i++) {
angleupdown += 2;
myservo2.write(angleupdown); // Move servo up
delay(30);
}
}
void Down() {
for (int i = 0; i < 45; i++) {
angleupdown -= 2;
myservo2.write(angleupdown); // Move servo down
delay(30);
}
}
GitHub Project Page