
Int data // the data bufferĬonst int dataBytes = numberOfAnalogPins * sizeof(int) // the number of bytesįor(int i=0 i <= numberOfAnalogPins i++)ĭata = analogRead(i) // store the values into the data buffer Sends digital and analog pin values as binary data using VirtualWire libraryĬonst int numberOfAnalogPins = 6 // how many analog pins to read The size of the buffer is the number of integers to be sent multiplied by the number of bytes in an integer (the six analog integer values take 12 bytes because each int is two bytes): The sending sketch that follows is similar to the transmit sketch in this recipe’s Solution, but it fills the message buffer with binary values from reading the analog input ports using analogRead.

The VirtualWire library handles the assembly of multiple bytes into packets, so sending binary data consists of passing the address of the data and the number of bytes to send. vw_get_message will return true if a message is available, and if so, each character in the message is printed to the Serial Monitor. The receive side initializes the library receive logic and then waits in loop for the message. The loop code simply calls a send function that calls the library vw_send and waits for the message to be transmitted. The VirtualWire library defaults to pin 12 for transmit and pin 11 for receive, but see the documentation link at the end of this recipe if you want to use different pins.

If (vw_get_message(message, &msgLength)) // Non-blocking This sketch displays text strings received using VirtualWireĬonnect the Receiver data pin to Arduino pin 11īyte message // a buffer to hold the incoming messagesīyte msgLength = VW_MAX_MESSAGE_LEN // the size of the message
