An Awesome School Project - DIY Crane
About this Project :-
Servo Motors
Parts List :-
1. Arduino Uno :- https://amzn.to/3VVxP5q
2. Servo Motors :- https://amzn.to/3kgRzTT
3. Push Buttons :- https://amzn.to/3CKj3Yb
4. Red LEDs :- https://amzn.to/3CQ2drb
5. CardBoard
Circuit Diagram :-
Arduino Code :-
// https://www.youtube.com/channel/UCaXI2PcsTlH5g0et67kdD6g //
// DIY Crane //
// MOHD SOHAIL //
#include <Servo.h>
Servo myservo;
Servo myservo1;
int angle =180; // initial angle for servo
int angleStep =5;
int angle1 =180; // initial angle for servo
int angleStep1 =5;
#define LEFT 3
#define RIGHT 2
#define UP 4
#define DOWN 5
int red = 6;
void setup() {
Serial.begin(9600);
myservo.attach(9);
myservo1.attach(10);
pinMode(LEFT,INPUT_PULLUP);
pinMode(RIGHT,INPUT_PULLUP);
pinMode(UP,INPUT_PULLUP);
pinMode(DOWN,INPUT_PULLUP);
pinMode(red, OUTPUT);
myservo.write(angle);
myservo1.write(angle1);
}
void loop() {
//--------------------------------------------------------------
while(digitalRead(RIGHT) == LOW){
right();
}
//--------------------------------------------------------------
while(digitalRead(LEFT) == LOW){
left();
}
//--------------------------------------------------------------
while(digitalRead(UP) == LOW){
up();
}
//--------------------------------------------------------------
while(digitalRead(DOWN) == LOW){
down();
}
{
for(int fading = 1 ; fading <= 10; fading+=1) {
analogWrite(red, fading);
delay(50);
}
analogWrite(red, 255);
delay (50);
for(int fading = 10 ; fading >=1;fading -=1) {
analogWrite(red, fading);
delay(100);
}
delay(100);
}
}
//--------------------------------------------------------------
void left()
{
if (angle >= 0 && angle <= 180) {
angle = angle + angleStep;
if(angle >180){
angle =180;
}else{
myservo.write(angle);
Serial.print(angle); // print the angle
Serial.println(" degree");
}
}
delay(100);
}
void right()
{
if (angle > 0 && angle <= 180) {
angle = angle - angleStep;
if(angle < 0){
angle = 0;
}else{
myservo.write(angle);
Serial.print(angle);
Serial.println(" degree");
}
}
delay(100);
}
void up()
{
if (angle1 > 0 && angle1 <= 180) {
angle1 = angle1 - angleStep1;
if(angle1 < 0){
angle1 = 0;
}else{
myservo1.write(angle1);
Serial.print(angle1);
Serial.println(" degree");
}
}
delay(100);
}
void down()
{
if (angle1 >= 0 && angle1 <= 180) {
angle1 = angle1 + angleStep1;
if(angle1 >180){
angle1 =180;
}else{
myservo1.write(angle1);
Serial.print(angle1); // print the angle
Serial.println(" degree");
}
}
delay(100);
}
Instagram Page : eif.08
1 Comments
great for school project.
ReplyDelete