title: Transmitting hex code through Arduino Leonardo by USART to device
body: <p>I am trying to send a hex command to a device with an Arduino Leonardo, that also accepts commands through a Bluetooth interface.</p>
  
  <p>Basically I am trying to switch a laser on and off through hex commands transmitted on an Arduino Leonardo, but I am having no luck. If I send the hex codes through the Bluetooth USB interface it works in the current configuration<a href="https://i.stack.imgur.com/FZ70v.jpg" rel="nofollow noreferrer">wiring config</a>, but not when I try and push it over the TX pin (I had to use a voltage divider with a 5k6 and 12k Ohm to bring the voltage down from 5V to 3.3V).</p>
  
  <p>The code I am trying is shown below:</p>
  
  <pre><code>byte laserON[] = {0xAA,0x00, 0x01, 0xBE, 0x00, 0x01, 0x00, 0x01, 0xC1};
  byte laserOFF[] = {0xAA,0x00, 0x01, 0xBE, 0x00, 0x01, 0x00, 0x00, 0xC0};
  
  void setup() {
   Serial1.begin(19200);
  }
  
  void loop() {
  for(byte i =0;isizeof(laserON);i++)(Serial1.write(laserON[i]));
  
  delay(1000);
  Serial1.write(laserON, sizeof(laserON));
  
  
  for(byte i =0;isizeof(laserOFF);i++)(Serial1.write(laserOFF[i]));
  delay(1000);
  Serial1.write(laserOFF, sizeof(laserOFF));
  }
  </code></pre>