I have an arduino leonardo and I want send a command to a camara in Hex (camera has a RS232 reciver (RX)) each time one of my PIRs close circuit (one hex for each PIR) so the camera rotate to a preset possition…
the hexs are {0x81,0x01,0x04,0x3F,0x02,0x00,0xFF} PIR 1
{0x81,0x01,0x04,0x3F,0x02,0x01,0xFF} PIR 2
{0x81,0x01,0x04,0x3F,0x02,0x02,0xFF} PIR 3
I tried
int PIR1 = 8;
int PIR2 = 9;
int PIR3 = 10;
void setup()
{
pinMode(PIR1 INPUT);
pinMode(PIR2 INPUT);
pinMode(PIR3 INPUT);
Serial1.begin(9600); // to start port 1 in arduino leonardo(TX). this one I connect it to the RX port in the camera
}
void loop()
{
if(digitalRead(PIR1) == HIGH)
{
byte arrayBytes [] = {0x81,0x01,0x04,0x3F,0x02,0x00,0xFF};
Serial.write(arrayBytes, 7);
if(digitalRead(PIR2) == HIGH)
{
byte arrayBytes [] = {0x81,0x01,0x04,0x3F,0x02,0x01,0xFF};
Serial.write(arrayBytes, 7);
if(digitalRead(PIR3) == HIGH)
{
byte arrayBytes [] = {0x81,0x01,0x04,0x3F,0x02,0x02,0xFF};
Serial.write(arrayBytes, 7);
}