Sterowanie pilotem IR, Servomechanizmu

zibi
Posty: 10
Rejestracja: pt cze 14, 2019 6:23 pm

Sterowanie pilotem IR, Servomechanizmu

Postautor: zibi » wt cze 25, 2019 2:39 pm

Witam
W tym projekcie chciałbym przedstawić jak za pomocą pilota np od telewizora możemy sterować serwomechanizmem, ustawiając dowolny kąt pracy serwa.

Arduino Uno
Servo (dowolne)
Odbiornik podczerwieni wykorzystałem HS0038B

Najpierw odnajdujemy kod pilota, używając tego programu i wchodzimy do arduino monitora portu szeregowego.

#include <IRremote.h>
int IRpin = 11;
IRrecv irrecv(IRpin);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println(results.value, DEC); // Print the Serial 'results.value'
irrecv.resume(); // Receive the next value
}
}


Potem kod z pilota podstawiamy do programu i gotowe.

#include <IRremote.h>
#include <Servo.h>
int IRpin = 11; // pin for the IR sensor
IRrecv irrecv(IRpin);
decode_results results;
Servo myservo;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
if (irrecv.decode(&results))
{
irrecv.resume(); // Receive the next value
}
if (results.value == 551505585) // change according to your IR remote button number
{
myservo.write(0);
delay(15);
}
if (results.value == 551521905) // change according to your IR remote button number
{
myservo.write(90);
delay(15);
}
}
Załączniki
schemat.jpg
schemat.jpg (140.99 KiB) Przejrzano 12877 razy