top of page
  • Writer's pictureRAJ SHARMA

434Mhz Module , Transmitter and Receiver , Arduino Codes


#include <Wire.h>

#include <Adafruit_MCP4725.h>

#include <VirtualWire.h>


const int rxPin = 12; // Digital pin connected to the RF receiver

Adafruit_MCP4725 dac; // Create a DAC object


void setup() {

Serial.begin(9600); // Start serial communication for debugging

vw_set_rx_pin(rxPin); // Set the pin for the RF receiver

vw_setup(2000); // Bits per second for the RF module

vw_rx_start(); // Start the receiver

dac.begin(x60); // Initialize the MCP4725 (default I2C address is x60)

}


void loop() {

uint8_t buf[4]; // Buffer to hold the received data

uint8_t buflen = sizeof(buf); // Length of the buffer


if (vw_get_message(buf, &buflen)) { // Check if a message has been received

int potValue;

memcpy(&potValue, buf, sizeof(potValue)); // Copy the received data into potValue


// Map the potentiometer value (-1023) to DAC (-4095)

int dacValue = map(potValue,0 , 1023,0 , 4095);

dac.setVoltage(dacValue, false); // Output the mapped voltage


Serial.print("Received Potentiometer Value: ");

Serial.print(potValue); // Print the received value

Serial.print(" -> DAC Value: ");

Serial.println(dacValue); // Print the mapped DAC value

}


delay(100); // Delay for stability, adjust as needed

}

.........................................................................................................................................................................................



#include <Wire.h>

#include <Adafruit_MCP4725.h>

#include <VirtualWire.h>


const int rxPin = 12; // Digital pin connected to the RF receiver

Adafruit_MCP4725 dac; // Create a DAC object


void setup() {

Serial.begin(9600); // Start serial communication for debugging

vw_set_rx_pin(rxPin); // Set the pin for the RF receiver

vw_setup(2000); // Bits per second for the RF module

vw_rx_start(); // Start the receiver

dac.begin(x60); // Initialize the MCP4725 (default I2C address is x60)

}


void loop() {

uint8_t buf[4]; // Buffer to hold the received data

uint8_t buflen = sizeof(buf); // Length of the buffer


if (vw_get_message(buf, &buflen)) { // Check if a message has been received

int potValue;

memcpy(&potValue, buf, sizeof(potValue)); // Copy the received data into potValue


// Map the potentiometer value (-1023) to DAC (-4095)

int dacValue = map(potValue,0 , 1023,0 , 4095);

dac.setVoltage(dacValue, false); // Output the mapped voltage


Serial.print("Received Potentiometer Value: ");

Serial.print(potValue); // Print the received value

Serial.print(" -> DAC Value: ");

Serial.println(dacValue); // Print the mapped DAC value

}


delay(100); // Delay for stability, adjust as needed

}


.........................................................................................................................................................................................


#include <VirtualWire.h>


const int rxPin = 12; // Digital pin connected to the RF receiver


void setup() {

Serial.begin(9600); // Start serial communication for debugging

vw_set_rx_pin(rxPin); // Set the pin for the RF receiver

vw_setup(2000); // Bits per second for the RF module

vw_rx_start(); // Start the receiver

}


void loop() {

uint8_t buf[4]; // Buffer to hold the received data

uint8_t buflen = sizeof(buf); // Length of the buffer


if (vw_get_message(buf, &buflen)) { // Check if a message has been received

int potValue;

memcpy(&potValue, buf, sizeof(potValue)); // Copy the received data into potValue


Serial.print("Pot Value: ");

Serial.println(potValue); // Print the received value

}


delay(100); // Delay for stability, adjust as needed

}

.........................................................................................................................................................................................


#include <VirtualWire.h>


const int potPin = A0; // Analog pin connected to the potentiometer

const int txPin = 2; // Digital pin connected to the RF transmitter


void setup() {

Serial.begin(9600); // Start serial communication for debugging

vw_set_tx_pin(txPin); // Set the pin for the RF transmitter

vw_setup(2000); // Bits per second for the RF module

}


void loop() {

int potValue = analogRead(potPin); // Read the potentiometer value

Serial.print("Potentiometer Value: ");

Serial.println(potValue); // Print value for debugging


// Transmit the value

vw_send((uint8_t*)&potValue, sizeof(potValue));

vw_wait_tx(); // Wait until the message is sent


delay(100); // Delay for stability, adjust as needed

}



0 views0 comments

Comments


bottom of page