ArduShop.ro

ArduShop.ro
cod Z4A413ZN reducere 5%, pentru vizitatorii paginilor mele !

joi, 21 noiembrie 2013

Arduino si un servomotor

   Dupa ce am primit un cadou deosebit, un "Arduino Starter Kit" de la prietenul meu Adrian Roman, caruia ii multumesc si pe aceasta cale, am ales sa fac probe cu servomotorul si, bineinteles, placa originala Arduino UNO R3...
   Din primele teste am constatat ca servomotorul meu nu poate face cursa completa pana la 1800 am limitat miscarea intre 0..1700.
   Am folosit sketch-ul numit Sweep de la Servo din exemple si sketch-ul prezentat la http://www.hobbytronics.co.uk/arduino-tutorial2-servos
iar un sketch, care le combina pe cele doua, in care pinul D9 este pentru comanda:
/*
Arduino Servo Test sketch
http://www.hobbytronics.co.uk/arduino-tutorial2-servos
and 
SWEEEP by BARRAGAN http://barraganstudio.com
adapted by niq_ro from http://nicuflorica.blogspot.com
*/

#include <Servo.h>
Servo servoMain; // Define our Servo

void setup()
{
servoMain.attach(9); // servo on digital pin 9
pinMode(13, OUTPUT); // initialize the digital pin no 13 as an output.
}

void loop()
{
  
   servoMain.write(45);  // Turn Servo Left to 45 degrees
   delay(1000);          // Wait 1 second
   servoMain.write(0);   // Turn Servo Left to 0 degrees
   delay(1000);          // Wait 1 second
   servoMain.write(90);  // Turn Servo back to center position (90 degrees)
   digitalWrite(13, HIGH);  
   delay(4000);          // Wait 1 second
   digitalWrite(13, LOW);  
   servoMain.write(135); // Turn Servo Right to 135 degrees
   delay(1000);          // Wait 1 second
   servoMain.write(170); // Turn Servo Right to 170 degrees
   delay(1000);          // Wait 1 second
   servoMain.write(90);  // Turn Servo back to center position (90 degrees)
   delay(1000);          // Wait 1 second   

// adapted part from SWEEP example
  for(int pos = 0; pos < 170; pos += 1)  // goes from 0 degrees to 170 degrees 
  {                                  // in steps of 1 degree 
    servoMain.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  }
 delay(1000); 
  for(int pos = 170; pos>=1; pos-=1)     // goes from 170 degrees to 0 degrees 
  {                                
    servoMain.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
delay (1000);
}
iar filmul, care demonstreaza functionarea, dupa acest sketch se numeste First tests with servomotor and Arduino from "Arduino Starter Kit":
   Pentru a nu aparea neclaritati, pun si schema de conectare:

Un comentariu:

  1. Thank you for your post. it was quite interesting. i really liked it. check out this http://komotek.com/html/eng/main.html, you will like it.

    RăspundețiȘtergere