I am pretty new to the Arduino platform and am needing some help making a specific function work.
I'm trying to use some of the inexpensive 433mhz transmitter/receiver pars work as a momentary trigger. So far I have at least been able to make the 2 units talk to each other by using the serial input function and the virtualwire library. This is the code that I used for that.
Transmitter
"#include <VirtualWire.h>
void setup()
{
Serial.begin(9600);
vw_setup(2000);
vw_set_tx_pin(7);
pinMode(13, OUTPUT);
}
void loop()
{
if(Serial.available())
{
char c = Serial.read();
if(c == '1')
{
vw_send((uint8_t *)c, 1);
}
else if(c == '0')
{
vw_send((uint8_t *)c, 1);
}
}
}"
Receiver
"#include <VirtualWire.h>
void setup()
{
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
vw_setup(2000);
vw_set_rx_pin(7);
vw_rx_start();
}
void loop()
{
uint8_t buflen = VW_MAX_MESSAGE_LEN;
uint8_t buf[buflen];
if(vw_get_message(buf, &buflen))
{
for(int i = 0;i < buflen;i++)
{
if(buf == '1')
- {*
- digitalWrite(13,HIGH);*
- }*
_ else if(buf == '0')_
* {*
* digitalWrite(13,LOW);*
* }*
* }*
* }*
}"
Using this code as a base I then tried to add in a normally closed button with the serial input pullup function. This is the code I used for that.
Transmitter with button:
"#include <VirtualWire.h>
void setup()
{
* Serial.begin(9600);*
* vw_setup(2000);
vw_set_tx_pin(7);
pinMode (2, INPUT_PULLUP);
_ pinMode (13, OUTPUT);_
_}_
void loop()
_{_
_ int sensorVal = digitalRead(2);_
_ Serial.println(sensorVal);_
_ if(Serial.available())_
_ {_
_ char c = Serial.read();*_
* if(c == '1')*
* {*
vw_send((uint8_t )c, 1);
_ digitalWrite(13,HIGH);_
_ }_
_ else if(c == '0')_
_ {_
vw_send((uint8_t )c, 1);
_ digitalWrite(13,LOW);_
* }*
* }*
}"
I can't seem to get this setup to function at all. Could somebody please let me know if there is something that I am missing or if you have a better idea. Sorry if the terminology used is wrong. Still getting the hang of all this.
Thanks