Ardiuno uno and servo project

Hi Guys
Just found this website by chance what a fantastic place
i am new to all of this . I have a project that i am trying to build
what i want to do is make a small box with a lid that opens
I want to fit into a car
So when the ignition is switch on the lid opens and stays open till the ignition is switch off then closes
i have a Ardiuno uno a small servo and a voltage stabilizer
can some please point me in the right direction of any other parts i need and some coding

Many thanks for looking at my topic

1 Like

Could this be okay?

P.S It’s arduino

Thanks i will try them codes and come back

Hello, I have been playing around with the Arduino software. I couldn’t get your code to work so I just used a sketch provided on the software. I have managed to get the servo to do what I want it to do when turning on (0>180 degrees) then it stops. How do I then get it to go from 180>0 degrees with no power? i.e do I need some kind of capacitor. If so do I have to add another code? Here is the code I have so far:

#include <Servo.h>

Servo servo;
int angle = 0;

void setup() {
servo.attach(2);
servo.write(angle);
}

void loop()
{
// scan from 0 to 180 degrees
for(angle = 0; angle < 180; angle++)
{
servo.write(angle);
delay(30);
}
// now scan back from 180 to 0 degrees
for(angle = 0; angle > 180; angle–)
{
servo.write(angle);
delay(30);

}servo.detach();

}

You might need a very large capacitor to hold enough charge to close the lid, and it adds complexity to have to monitor voltage levels to know when to close the lid.

Could the lid be held open by an electromagnet? That way it would automatically fall closed (you can slow the fall with friction to look better).