

Arduino virtual wire library serial#
By checking your serial monitor you should be able to tell what's working and not.This post is a guide for the popular RF 433MHz Transmitter/Receiver modules with Arduino.
Arduino virtual wire library how to#
Check this link on how to set char arrays: Īlso try to make use of the debug parts in the code above. If not a work around that could be to just do a simple if, then else function and check if Sensor1Data is "true" and if so set Sensor1CharMsg to "1" and if "false" set Sensor1CharMsg to "0". However I don't actually know if there is such a thing as a "btoa" function, a quick google yielded some results so you might as well try it just to see if it works. You would probably have to declare Sensor1Data as a boolean variable instead and perhaps use "btoa" to convert it into a char array. This is the variable that is later sent via virtualWire.

Then read the analog pin to store its value into the Sensor1Data variable.Ī bit further down the code you then see how this integer is converted to a char array by the use of "itoa" before it is stored in the Sensor1CharMsg variable. I do this by first declaring that sensor1Data will contain an integer. In essence you should read whatever data you want to send to Sensor1Data. Sending data is done with the virtualWire library i.e this part of the code: I think the problem here is that you are trying to transmit by using digitalWrite, that is not how the code works. If you do work it out you're more than welcome to post your result here. You can always hijack the thread I've linked to in the beginning of the post to see if someone has another solution. Then it's just a matter of reading the first char in the array to find out if it's the temperature or humidity being sent, strip that char away and use the rest of the char array as in my code.Įxactly how you would accomplish this I don't know but if I recall correctly it's not that hard to mess around with char arrays. Let's say the letter "T" for Temperature and "H" for Humidity. The messages would be just as the one in my code but with one char added to identify the message on the receiving end. I would send the data in two separate messages. I'm no expert and there are probably better solutions than the one I will suggest but I'll try to point you in a good direction. However I guess you want to send both humidity and temperature. If you want to send a longer number you just need to change the number of chars in the char array. I suggest you try this code first with a simple potentiometer or something to make sure you connection works. With my code you can send any 4 digit integer with virtual wire it doesn't matter if it's from an analog sensor, digital sensor or just made up. Serial.println("Failed to read from DHT") check if returns are valid, if they are NaN (not a number) then something went wrong! Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor Connect pin 4 (on the right) of the sensor to GROUND Connect pin 2 of the sensor to whatever your DHTPIN is Connect pin 1 (on the left) of the sensor to +5V #define DHTPIN 2 // what pin we're connected to Next the sketch I use for the DHT22 sensor alone: Is it possible read an digital sensor (DHT22) instead of an analog sensor? Can you help me? I will use a DHT22 sensor with RF and Virtual wire. Turn off light to and await next message Convert Sensor1CharMsg Char array to integer when the incoming messages has less digits than the This needs to be done otherwise problems will occur Fill Sensor1CharMsg Char array with corresponding Message with a good checksum received, dump it. Turn on a light to show received good message Gets a sensor reading 0-1023 in a char array Vw_wait_tx() // Wait until the whole message is goneĭigitalWrite(13, false) // Turn off a light after transmission

Vw_send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg)) Convert integer data to Char array directlyĭigitalWrite(13, true) // Turn on a light to show transmitting The code and comments below are pretty much self explanatory:
