Know the structure and layout of the UNO.
Download the software as instructed in this video
Play with your first code and interfacing.
Copy this program:
// Pin 12 is used in this program.
int led = 12;
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
You can use same code as above.
Check voltage change using a multimeter. The code remains same.
This activity will facilitate understanding of the following things: - Interfacing of servo motors - Controlling angle of the servos - Changing speed of the servo motor - Delays - Applications of servo motors .
Copy this code:
// Use and control of a servo motor.
// Box of Science
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in
// variable 'pos'
delay(15); // waits 15ms for the servo to reach
// the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in
// variable 'pos'
delay(15); // waits 15ms for the servo to reach
// the position
}
}
Welcome - We use cookies for basic site functions and stats. It’s all secure and respectful of your privacy