I am very new to Arduino UNO. As in just started a few weeks ago with an online course that doesn't provide much access to example codes besides the Lab Manual for an Arduino Uno.
I am looking for some help with my project. I have copied the project description below in bold.
My main problem is where to put certain code. I understand I'm probably going to need to use some For/While loops...but I am honestly lost as what to put in it and where it would go.
I understand I can move the servo continuously utilizing the "servoRight.writeMicroseconds(1300); " but incorporating the LEDs with the rotation of the servo is something I am completely overwhelmed with and there's not really a straightforward example of this project from the researching I have done.
Some insight would be greatly appreciated. I have also attached a code I wrote up...I know its a mess and it doesn't really work but its there so you can see where I am at.
Create a program that runs a series of test sequences meant to display the capabilities for an LED clock prototype. Use a single servo to act as an “hour” hand to span 12 hours like a standard clock. Each hour should take a fixed number of seconds (your choice). It is recommended you use a 20 second delay to begin. Servos can jitter in the beginning (especially Pin 13) Align the hand to 12 o’clock after the jitter but before motion starts. Your clock needs not be perfect, but it should be no more than 10% off after a full day (24 hrs, or 240 seconds). That's 2.4 hours leeway per day. You will also use 3 LEDs as indicators for your clock prototype to simulate the passing of the day, tracking hours, and am/pm. Goals: “Hour Hand” spins CW at required speed for your chosen # seconds/hour Tracks time to within 2.4 “hours” over a full "day" (24 “hours”) LED 1 (Green) flashes the value of the hour (once for 1, thrice for 3 etc…) LED 2 (Red) is on during pm and off during am. LED 3 (Red) simulated day. Off from 7pm to 5am. Brightens steadily from 5am to noon. Dims steadily from noon to 7pm.
/*
*/
#include <Servo.h> // Include servo library
Servo servoRight; // Declare right servo signal
int pos = 0;
void setup() // Built in initialization block
{
servoRight.attach(13); // Attach left signal to pin 13
pinMode(12, OUTPUT);
pinMode(11, OUTPUT); // Set digital pin 12 -> output
pinMode(10, OUTPUT);
servoRight.writeMicroseconds(1450);
}
void loop() // Main loop auto-repeats
{
for(pos=0; pos<360; pos +=1)
{
if(pos == 360)
digitalWrite(12, HIGH);
delay(500);
}
{
digitalWrite(10, HIGH); // Pin 10 = 5 V, LED emits light
delay(500); // ..for 0.5 seconds
digitalWrite(10, LOW); // Pin 10 = 0 V, LED no light
delay(500); // ..for 0.5 seconds
}
{
digitalWrite(11, HIGH); // Pin 11 = 5 V, LED emits Green light
delay(500); // ..for 0.5 seconds
digitalWrite(11, LOW); // Pin 11 = 0 V, LED no light
delay(500);
}
}
There are plenty of simple examples on line, and included in the Arduino IDE that show you how to do basic tasks.
File>examples>etc.
Somewhere you will find "Servo sweep", which should be useful to get you started. Also, just google for example "arduino servo" to find other tutorials.
Currently, as my code stands my servo spins clockwise continuously. Which is what I need it to do, I got that down.
Right now it rotates a full rotation at about 3 seconds. My first LED I want to increment with each full rotation. So one rotation = 1 blink, two rotations = 2 blinks..etc. Once it hits the 12 mark I need it to revert back to 1 blink and then go through the process again a second time. For this portion, I tried adjusting by adding an Integer? see code below, but it only blinks once with each rotation.
And this is just for the first LED. I have yet to tackle the 2nd and 3rd ones.
This is after I have read through the Manual twice and searched multiple forums/boards/youtube videos. The reason all posts have their own way of doing things...that I feel are too advanced for me to know just yet based off my course.
Currently, as my code stands my servo spins clockwise continuously.
Then what you have is not a servo at all, rather it is an electronically controlled variable speed and direction motor, also known wrongly as a continuous rotation servo
My first LED I want to increment with each full rotation. So one rotation = 1 blink, two rotations = 2 blinks..etc.
As you do not have any feedback of the motor position you are going find this difficult. How will you know that the motor has completed a full rotation ? You cannot rely on timing because the motor speed will depend on input voltage and load amongst other things
Use debugg printouts on Serial.print to tell what is happening inside Your sketc. You will be suprised how much knowlege that can give You. Okey, testing one printout, You will get ideas for a second level of printout.
Then You will discouver things.
UKHeliBob:
Then what you have is not a servo at all, rather it is an electronically controlled variable speed and direction motor, also known wrongly as a continuous rotation servo
As you do not have any feedback of the motor position you are going find this difficult. How will you know that the motor has completed a full rotation ? You cannot rely on timing because the motor speed will depend on input voltage and load amongst other things
Yes its a continuous rotation servo.
I did search "Servo sweeps" but that only results in servos rotating 180...not continuously 360 degrees.
Based off the project instructions (the bold test in my original post) we have to time it out since we dont have specific positions. Right now i have my speed set at 1450 Microseconds, which takes the servo about 2.5 seconds to rotate fully (i timed it on my phone). That is why you see my delays set to 250 to turn on and 2300 to turn off.
Okey. I try again. Apply temporary, special code, to Your sketch, that prints out time, statuses etc. that gives You a better knowledge about what is happening.
That strategy helped me finding faults in large, unknown systems, during many years.
Railroader:
Okey. I try again. Apply temporary, special code, to Your sketch, that prints out time, statuses etc. that gives You a better knowledge about what is happening.
That strategy helped me finding faults in large, unknown systems, during many years.
Again, I am really not sure what you are asking me to do. Is this something I can do from the Arduino IDE? or do you have a link that better explains that?
The rotational speed of most "continuous rotation" servos cannot be controlled with any accuracy, and won't be useful to make a clock, as your assignment seems to require. It would be much easier to do the project with a small, low power stepping motor, like this one.
The rotational speed of most "continuous rotation" servos cannot be controlled with any accuracy, and won't be useful to make a clock, as your assignment seems to require. It would be much easier to do the project with a small, low power stepping motor, like this one.
That servo is rather different from most that are advertised as "continuous rotation", as most simply have the position sensing potentiometer removed. It is more promising than I first thought.
However, there isn't much in the way of specifications, except to state that the shaft RPM ranges from 0-50 and is linear in response to PWM.
You will need to experiment to see how slowly and accurately the shaft can be made to turn. A 12 hour clock hand rotates at (1/720) RPM.
To flash LEDs and do other things at the same time, you CANNOT USE delay(). Study this excellent tutorial to learn how to use millis() function for timing such activities.