quarta-feira, 17 de setembro de 2025

 Movimento de servo motores utilizando o arduino

O controle do ângulo de cada um é feito através de um potênciometro que na sua faixa de valores de resistência/tensão no pino de entrada, é convertido a um ângulo de 0 a 180 Graus. Aqui está o circuito e a programação utilizada. A montagem e a simulação foi feita no site: www.tinkercad.com, gratuíto. 



Programação proposta:

#include <Servo.h>

Servo myservo1;  // create servo object to control a servo
Servo myservo2;  // create servo object to control a servo
Servo myservo3;  // create servo object to control a servo
Servo myservo4;  // create servo object to control a servo

int potpin1 = 0;  // analog pin used to connect the potentiometer
int val1;    // variable to read the value from the analog pin

int potpin2 = 1;  // analog pin used to connect the potentiometer
int val2;    // variable to read the value from the analog pin

int potpin3 = 2;  // analog pin used to connect the potentiometer
int val3;    // variable to read the value from the analog pin

int potpin4 = 3;  // analog pin used to connect the potentiometer
int val4;    // variable to read the value from the analog pin

void setup() {
  myservo1.attach(3);  // attaches the servo on pin 9 to the servo object
  myservo2.attach(4);  // attaches the servo on pin 9 to the servo object
  myservo3.attach(5);  // attaches the servo on pin 9 to the servo object
  myservo4.attach(6);  // attaches the servo on pin 9 to the servo object
  
  pinMode(8, INPUT);
  pinMode(potpin1, INPUT);
  pinMode(potpin2, INPUT);
  pinMode(potpin3, INPUT);
  pinMode(potpin4, INPUT);
}

void loop() {
  
  int botao = digitalRead(8);
  
  if(botao==1)
  {
  val1 = analogRead(potpin1);            // reads the value of the potentiometer (value between 0 and 1023)
  val1 = map(val1, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo1.write(val1);                  // sets the servo position according to the scaled value
  
  
  val2 = analogRead(potpin2);            // reads the value of the potentiometer (value between 0 and 1023)
  val2 = map(val2, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo2.write(val2);                  // sets the servo position according to the scaled value
  
  val3 = analogRead(potpin3);            // reads the value of the potentiometer (value between 0 and 1023)
  val3 = map(val3, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo3.write(val3);                  // sets the servo position according to the scaled value
  
  val4 = analogRead(potpin4);            // reads the value of the potentiometer (value between 0 and 1023)
  val4 = map(val4, 0, 1023, 89, 180);     // scale it to use it with the servo (value between 0 and 90)
  myservo4.write(val4);                  // sets the servo position according to the scaled value
  
 
  delay(15);                           // waits for the servo to get there
  }

}



 Escrita no LCD 16x2 Usando o Arduino UNO, através de simulação no TinkerCAD.



Programa teste utilizado: 

#include <LiquidCrystal.h>
/*Este programa, a cada clique do botão aumenta a luminosidade
do LED, o aumento é graduação, sendo no máximo em 10 passos, no
decimo primeiro passo, o led volta ao nível zero*/

const int rs = 12, en = 11, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int conta = 0;
int conversao = 0;
int botao = 0;

void setup() {
  lcd.begin(16, 2);
  lcd.clear();  
  lcd.print("Iniciando LCD");
  delay(1000);
  lcd.clear();
  pinMode(2, INPUT);
  Serial.begin(9600);
}

void loop() {
  botao = digitalRead(2);
  if(botao == 1){
   conta = conta + 1;
   conversao = conta * 255.;
   conversao = conversao / 10.;
   Serial.println(conversao);
   Serial.println(conta);
   delay(300);
  }
  if(conta > 10){
    conta=0;
    conversao = 0;
  }
  lcd.setCursor(0, 0);         
  lcd.print("Contagem: ");        
  lcd.print(conta);
  lcd.setCursor(0, 1);         
  lcd.print("led a %: ");  
  analogWrite(9,conversao);
  Serial.println(conversao);
  int c = conversao / 25.;
  c = c *10;
  if(c<100){
   lcd.print(c);
  }else{
   lcd.print("100");
  }
  if(c == 0){
  lcd.setCursor(10, 1);         
  lcd.print("   ");
  lcd.setCursor(10, 0);         
  lcd.print("   ");
  }

}


 


Oscilador com CI 555


A montagem foi feita usando site gratuito: www.tinkercad.com