I am tying to use RF receiver to take the input from a sound sensor then depending on the input send a signal to the receiver and activate a servo I uploaded the code with no problems but when I tested it nothing worked and the servo spun right when I plugged it in
I am using an Arduino Nano
I am using this Transmitter and receiver: HiLetgo 5 Sets 433M Transmitter + Receiver Kit High Frequency Super Regenerative Transceiver Module for Burglar Alarm
A mini servo
a sound sensor
here are the schematics
Here is the code for the transmitter
#include <VirtualWire.h>
int sensorAnalogPin = A0; // Select the Arduino input pin to accept the Sound Sensor's analog output
int sensorDigitalPin = 3; // Select the Arduino input pin to accept the Sound Sensor's digital output
int analogValue = 0; // Define variable to store the analog value coming from the Sound Sensor
int digitalValue;
void send (char *message)
{
vw_send((uint8_t *)message, strlen(message));
vw_wait_tx(); // Wait until the whole message is gone
}
void setup()
{
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
Serial.begin(9600); // The IDE settings for Serial Monitor/Plotter (preferred) must match this speed
pinMode(sensorDigitalPin, INPUT);
}
void loop()
{
analogValue = analogRead(sensorAnalogPin); // Read the value of the analog interface A0 assigned to digitalValue
digitalValue = digitalRead(sensorDigitalPin); // Read the value of the digital interface 7 assigned to digitalValue
Serial.println(analogValue); // Send the analog value to the serial transmit interface
if (analogValue > 300) // When the Sound Sensor sends signla, via voltage present, light LED13 (L)
{
send("Hello, it's me");
delay(1000);
}
}
Here is the code for the receiver
#include <VirtualWire.h>
#include <ServoTimer2.h>
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message
ServoTimer2 myServo;
void setup()
{
myServo.attach(9);
Serial.begin(9600);
Serial.println("Device is ready");
Serial.begin(9600); // The IDE settings for Serial Monitor/Plotter (preferred) must match this speed
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver
}
void loop()
{
if (vw_get_message(message, &messageLength)) // Non-blocking
{
Serial.print("Received: ");
for (int i = 0; i < messageLength; i++)
Serial.write(message[i]);
myServo.write(1500);
}
{
Serial.println();
}
}