I'm trying to make a contraption where you press a button on one board and it moves the servo either to 90 degrees or 180 degrees on the other board. If it's at 90 then it moves to 180 and vice versa.
I'm not very knowledgeable when it comes to this stuff as this is my first major project so bear with me. I already have the wireless system working (thanks to hours of Googling) and a toggle system for an LED (for testing to see if the wireless is working).
I'm using one of the tiny RF transmitters, two Nanos, and a servo from Radio Shack. The problem is the servo doesn't turn but my test LED turns on and off. Here is the code for the receiver end of things:
#include <VirtualWire.h>
#include <ServoTimer2.h>
const int releu_pin = 9;
const int servoPin = 6;
const int transmit_pin = 12;
const int receive_pin = 3;//pin connected between RX module and Arduino
const int transmit_en_pin = 5;
ServoTimer2 myservo;
void setup() {
myservo.attach(servoPin);
myservo.write(45);
vw_set_tx_pin(transmit_pin);
vw_set_rx_pin(receive_pin);
vw_set_ptt_pin(transmit_en_pin);
vw_set_ptt_inverted(true);
vw_setup(2000);//speed communication bps
vw_rx_start(); // activate receiving mode
pinMode(releu_pin, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT); //Debug
}
void loop() {
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) {
//verify if any data is received
if(buf[0]=='1') {
//if received 1 turn ON releu_pin
myservo.write(90);
digitalWrite(releu_pin , HIGH);
digitalWrite(LED_BUILTIN, HIGH); //Debug
delay(100);
}
if(buf[0]=='0') {
myservo.write(180);
digitalWrite(releu_pin , LOW);
digitalWrite(LED_BUILTIN, LOW); //Debug
delay(100);
}
}
}