It's a partially random idea,
It has a small part of the servo motor as an application of my final project idea which is a mobile gimbal.
So I chose this idea as a training for me to get used to servo motors more and add other cool features.
The Idea is simple, the user enter the number of degrees to the servo using potentiometer, before 90 degrees the rgb led emits green, between 90 & 150 degrees it emits blue and more than 150 degrees it emits red and the buzzer goes on.
I used Tinkercad to simulate the electronic circuit before making it in reality to make sure it's working and prevent burning of any component.
I'll use cardboard to make the enclosure as it's cheap and easy to use for a first prototype.
I joined the potentiometer signal port to analog port in Arduino, RGB led, buzzer and servo motor to digital ports in Arduino.
Then I used the code in the picture so that when the servo motor rotates the RGB led will emit blue at angles below 90, green between 90 and 150 and red after 150. Also the buzzer goes on after angle 150.
The 2 inputs of the device are the slide switch (that opens and closes the whole device) and the potentiometer.
Code:
#include<Servo.h>
int servo;
char pot=0;
Servo myservo;
void setup()
{
myservo.attach(7);
Serial.begin(9600);
pinMode(7,OUTPUT);
pinMode(2,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(A0,INPUT);
}
void loop()
{
servo = map(analogRead(pot),0,1023,0,180);
myservo.write(servo);
delay(100);
if(servo >= 150)
{
digitalWrite(8,HIGH);
digitalWrite(2,HIGH);
}
else
{
digitalWrite(8,LOW);
digitalWrite(2,LOW);
}
if(servo >= 90 && servo <= 150)
{
digitalWrite(10,HIGH);
}
else
{
digitalWrite(10,LOW);
}
if(servo <= 90)
{
digitalWrite(9,HIGH);
}
else
{
digitalWrite(9,LOW);
}
}
I used the small breadboard as it consume less space than the large one.
I did the same code and connection as on Tinkercad.
I also made this box as an enclosure for the project.
When the project didn't work I didn't know what was the problem so I asked for feedback from my teammates and instructors.
Also during the 3 sessions of the week we had a lot of conversations about each others projects and had a lot of fun benefiting each others.
I forgot how to use join the servo motor and whether the potentiometer is analog or digital, so I returned to the videos and did some research on Arduino website and a video I found on google to have a better understanding on these components and how to join them together.
The Servo motor was not working so I replaced it by another one from the lab which was also not working, so I ended up using my personal one.
This is the video I saw on Google it helped a lot:
https://www.google.com/search?q=how+to+control+servo+motor+with+potemtiometer+arduino&oq=how+to+control+servo+motor+with+potemtiometer+arduino&aqs=chrome..69i57j0i22i30.29516j1j7&sourceid=chrome&ie=UTF-8#kpvalbx=_Jw02YYr4Aorqav6biuAE20
Also in the EOW session I got stuck me and my teammate, so we did some research after fighting with the internet connection, and we also asked the instructors Mohanad and Menna to help us in the process of coding and wiring.
Title of Media
I now know more about servo motors,
and I can use the project for this week to add other features in the final project (mobile gimbal), these features will help the user have better understanding on the device and will feel better subconsciously when he sees the device is interacting with him more.
I finally got used to the Arduino coding and it felt great when I used the code directly to add some features without the need of blocks in tinkercad
Title of Media