Home
About Us
Achievement
Home
Raspberry-Pi Projects
_Raspberry Pi 4 Complete Guide
Arduino Project
_All Projects
Esp8266 Project
_All Projects
Esp32 Project
_Automation-with-feedback
433mhz-Rf-Modules-Arduino
Just Do Electronics
October 17, 2020
433MHz Transmit and Receive Modules with Arduino
Transmitter Code
Data Pin = 12
// Include RadioHead Amplitude Shift Keying Library #include
// Include dependant SPI Library #include
// Create Amplitude Shift Keying Object RH_ASK rf_driver; void setup() { // Initialize ASK Object rf_driver.init(); } void loop() { const char *msg = "Welcome to the JustDoElectronics"; rf_driver.send((uint8_t *)msg, strlen(msg)); rf_driver.waitPacketSent(); delay(1000); }
Receiver
Data Pin = 11
// Include RadioHead Amplitude Shift Keying Library #include
// Include dependant SPI Library #include
// Create Amplitude Shift Keying Object RH_ASK rf_driver; void setup() { // Initialize ASK Object rf_driver.init(); // Setup Serial Monitor Serial.begin(9600); } void loop() { // Set buffer to size of expected message uint8_t buf[24]; uint8_t buflen = sizeof(buf); // Check if received packet is correct size if (rf_driver.recv(buf, &buflen)) { // Message received with valid checksum Serial.print("Message Received: "); Serial.println((char*)buf); } }
Dht11 Sensor Interfacing
Transmitter
// Include RadioHead Amplitude Shift Keying Library #include
// Include dependant SPI Library #include
// Include DHT Libraries from Adafruit // Dependant upon Adafruit_Sensors Library #include "DHT.h"; // Define Constants #define DHTPIN 7 // DHT-22 Output Pin connection #define DHTTYPE DHT22 // DHT Type is DHT 22 (AM2302) // Define Variables float hum; // Stores humidity value in percent float temp; // Stores temperature value in Celcius // Define output strings String str_humid; String str_temp; String str_out; // Create Amplitude Shift Keying Object RH_ASK rf_driver; // Initialize DHT sensor for normal 16mhz Arduino DHT dht(DHTPIN, DHTTYPE); void setup() { // Initialize ASK Object rf_driver.init(); // Start DHT Sensor dht.begin(); } void loop() { delay(2000); // Delay so DHT-22 sensor can stabalize hum = dht.readHumidity(); // Get Humidity value temp= dht.readTemperature(); // Get Temperature value // Convert Humidity to string str_humid = String(hum); // Convert Temperature to string str_temp = String(temp); // Combine Humidity and Temperature str_out = str_humid + "," + str_temp; // Compose output character static char *msg = str_out.c_str(); rf_driver.send((uint8_t *)msg, strlen(msg)); rf_driver.waitPacketSent(); }
Receiver
// Include RadioHead Amplitude Shift Keying Library #include
// Include dependant SPI Library #include
// Define output strings String str_humid; String str_temp; String str_out; // Create Amplitude Shift Keying Object RH_ASK rf_driver; void setup() { // Initialize ASK Object rf_driver.init(); // Setup Serial Monitor Serial.begin(9600); } void loop() { // Set buffer to size of expected message uint8_t buf[11]; uint8_t buflen = sizeof(buf); // Check if received packet is correct size if (rf_driver.recv(buf, &buflen)) { // Message received with valid checksum // Get values from string // Convert received data into string str_out = String((char*)buf); // Split string into two values for (int i = 0; i < str_out.length(); i++) { if (str_out.substring(i, i+1) == ",") { str_humid = str_out.substring(0, i); str_temp = str_out.substring(i+1); break; } } // Print values to Serial Monitor Serial.print("Humidity: "); Serial.print(str_humid); Serial.print(" - Temperature: "); Serial.println(str_temp); } }
LM35 Sensor Interfacing
Transmitter :-
//Prateek //www.prateeksin #include
const int transmit_pin = 11; const int receive_pin = 12; const int transmit_en_pin = 3; const int led_pin = 13; const int lm35Pin = A0; //temperature sensor connected to analog pin A0 struct package { float temperatureC ; float temperatureF ; }; typedef struct package Package; Package data; void setup() { Serial.begin(9600); // Initialise the IO and ISR vw_set_tx_pin(transmit_pin); vw_set_rx_pin(receive_pin); vw_set_ptt_pin(transmit_en_pin); vw_set_ptt_inverted(true); // Required for DR3100 vw_setup(500); // Bits per sec pinMode(led_pin, OUTPUT); } void loop() { digitalWrite(led_pin, HIGH); // Flash a light to show transmitting readSensor(); vw_send((uint8_t *)&data, sizeof(data)); vw_wait_tx(); // Wait until the whole message is gone digitalWrite(led_pin, LOW); delay(2000); } void readSensor() { int tempsensor = analogRead(lm35Pin); float value = ( tempsensor / 1023.0) * 5000; float celsius = value / 10; float fahrenheit = (celsius * 9) / 5 + 32; data.temperatureC = celsius; data.temperatureF = fahrenheit; Serial.print("Temperature = "); Serial.print(celsius); Serial.print("*C "); Serial.print("Temperature = "); Serial.print(fahrenheit); Serial.print("*F "); Serial.println(); }
Receiver :-
//Prateek //www.prateeksin #include
#include
//Initialise the LCD 1602 I2C LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); const int transmit_pin = 11; const int receive_pin = 12; const int transmit_en_pin = 3; char temperaturecChar[10]; char temperaturefChar[10]; struct package { float temperatureC = 0.0; float temperatureF = 0.0; }; typedef struct package Package; Package data; void setup() { Serial.begin(9600); //initialise the IO and ISR vw_set_tx_pin(transmit_pin); vw_set_rx_pin(receive_pin); vw_set_ptt_pin(transmit_en_pin); vw_set_ptt_inverted(true); // Required for DR3100 vw_setup(500); // Bits per sec vw_rx_start(); // Start the receiver PLL running //define the LCD as 16 column by 2 rows lcd.begin (16, 2); //switch on the backlight lcd.setBacklightPin(3, POSITIVE); lcd.setBacklight(HIGH); //goto first column (column 0) and first line (Line 0) lcd.setCursor(0, 0); //Print at cursor Location lcd.print("433 MHZ RF TX/RX"); //goto first column (column 0) and second line (line 1) lcd.setCursor(0, 1); lcd.print("by Acoptex.com"); delay (3000); lcd.clear();// clears screen } void loop() { uint8_t buf[sizeof(data)]; uint8_t buflen = sizeof(data); if (vw_have_message()) // Is there a packet for us? { vw_get_message(buf, &buflen); memcpy(&data, &buf, buflen); Serial.print("Temperature Celsius: "); Serial.print(data.temperatureC); Serial.print("*C "); String temperaturecString = String(data.temperatureC, 1); temperaturecString.toCharArray(temperaturecChar, 10); String temperaturefString = String(data.temperatureF, 1); temperaturefString.toCharArray(temperaturefChar, 10); Serial.print("Temperature Fahrenheit: "); Serial.print(data.temperatureF); Serial.println("*F "); DisplayData(); } } void DisplayData() { //goto first column (column 0) and first line (Line 0) lcd.setCursor(0, 0); //Print at cursor Location lcd.print("Temp: "); //goto first column (column 0) and second line (line 1) lcd.setCursor(0, 1); lcd.print("Temp: "); //goto first column (column 7) and second line (line 0) lcd.setCursor(7, 0); lcd.print(data.temperatureC); //goto first column (column 7) and second line (line 1) lcd.setCursor(7, 1); lcd.print(data.temperatureF); //goto first column (column 12) and first line (Line 0) lcd.setCursor(13, 0); //Print at cursor Location lcd.print(" *C"); //goto first column (column 12) and second line (line 1) lcd.setCursor(13, 1); lcd.print(" *F"); }
10k Variable Interfacing
Code for the RF Transmitter //Prateek //www.prateeks.in #include
const int SensorPin = A2; // potentiometer pin int SensorData; char SensorCharMsg[5]; void setup() { pinMode(SensorPin,INPUT); // for debugging Serial.begin(9600); // VirtualWire setup vw_setup(2000); // Bits per sec } void loop() { // Read and store Sensor 1 data SensorData = analogRead(SensorPin); // Convert integer data to Char array directly itoa(SensorData,SensorCharMsg,10); // DEBUG Serial.print("Sensor Integer: "); Serial.print(SensorData); // print the sensor data Serial.print(" Sensor CharMsg: "); Serial.print(SensorCharMsg); //print the char array Serial.println(" "); delay(100); // END DEBUG vw_send((uint8_t *)SensorCharMsg, strlen(SensorCharMsg)); // send the message vw_wait_tx(); // Wait until the whole message is gone delay(200); } // END void loop Code for RF Receiver #include
int SensorData; // Sensors char SensorCharMsg[5]; // RF Transmission container const int led1 = 2; const int led2 = 3; const int led3 = 4; const int led4 = 5; const int led5 = 6; void setup() { Serial.begin(9600); pinMode(led1, INPUT); pinMode(led2, INPUT); pinMode(led3, INPUT); pinMode(led4, INPUT); pinMode(led5, INPUT); // VirtualWire // Initialise the IO and ISR // Required for DR3100 vw_set_ptt_inverted(true); // Bits per sec vw_setup(2000); // Start the receiver PLL running vw_rx_start(); } // END void setup void loop() { uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; // Non-blocking if (vw_get_message(buf, &buflen)) { int i; // Message with a good checksum received, dump it. for (i = 0; i < buflen; i++) { // Fill SensorCharMsg Char array with corresponding // chars from buffer. SensorCharMsg[i] = char(buf[i]); } // Null terminate the char array // This needs to be done otherwise problems will occur // when the incoming messages has less digits than the // one before. SensorCharMsg[buflen] = '\0'; // Convert Sensor1CharMsg Char array to integer SensorData = atoi(SensorCharMsg); // DEBUG Serial.print("Sensor "); Serial.println(SensorData); // END DEBUG } if (SensorData <= 200) { digitalWrite(led1, HIGH); } else digitalWrite(led1, LOW); if ( SensorData > 200 && SensorData <= 400) { digitalWrite(led2, HIGH); } else digitalWrite(led2, LOW); if ( SensorData > 400 && SensorData <= 600) { digitalWrite(led3, HIGH); } else digitalWrite(led3, LOW); if ( SensorData > 600 && SensorData <= 800) { digitalWrite(led4, HIGH); } else digitalWrite(led4, LOW); if ( SensorData > 800 && SensorData <= 1023) { digitalWrite(led5, HIGH); } else digitalWrite(led5, LOW); }
Rf Based Smart Robot Car
Transmitter :-
#include
const int led_pin = 11; const int transmit_pin = 12; const int transmit_en_pin = 3; int button = 7; int button1 = 8; int button2 = 2; int button4 = 4; void setup() { // Initialise the IO and ISR vw_set_tx_pin(transmit_pin); pinMode(button, INPUT); pinMode(button1, INPUT); pinMode(button2, INPUT); pinMode(button4, INPUT); vw_setup(2000); // Bits per sec } byte count = 1; void loop() { char msg[7] = {'h'}; char msg1[7] = {'j'}; char msg2[7] = {'l'}; char msg3[7] = {'m'}; char msg8[7] = {'z'}; // msg[6] = count; if(digitalRead(button) == 0 ) { vw_send((uint8_t *)msg, 1); // change this number according to the sensor values vw_wait_tx(); // Wait until the whole message is gone delay(1000); } if(digitalRead(button1) == 0 ) { vw_send((uint8_t *)msg1, 1); // change this number according to the sensor values vw_wait_tx(); // Wait until the whole message is gone delay(1000); } if(digitalRead(button2) == 0 ) { vw_send((uint8_t *)msg2, 1); // change this number according to the sensor values vw_wait_tx(); // Wait until the whole message is gone delay(1000); } if(digitalRead(button4) == 0 ) { vw_send((uint8_t *)msg8, 1); // change this number according to the sensor values vw_wait_tx(); // Wait until the whole message is gone delay(1000); } else digitalWrite(button, HIGH); digitalWrite(button1,HIGH); digitalWrite(button2,HIGH); digitalWrite(button4,HIGH); }
Receiver :-
#include
const int led_pin = 13; int rightmotor1 = 2; // right side motor int rightmotor2 = 3; // left side motor int leftmotor1 = 7; int leftmotor2 = 8; const int receive_pin = 11; void setup() { delay(1000); Serial.begin(9600); // Debugging only Serial.println("setup"); // Initialise the IO and ISR vw_set_rx_pin(receive_pin); vw_set_ptt_inverted(true); // Required for DR3100 vw_setup(2000); // Bits per sec vw_rx_start(); // Start the receiver PLL running pinMode(led_pin, OUTPUT); digitalWrite(led_pin, LOW); pinMode(rightmotor1, OUTPUT); pinMode(rightmotor2, OUTPUT); pinMode(leftmotor1, OUTPUT); pinMode(leftmotor2, OUTPUT); } void loop() { uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; if (vw_get_message(buf, &buflen)) // Non-blocking { int i; // Message with a good checksum received, dump it. Serial.print("Got: "); for (i = 0; i < buflen; i++) { char c = (buf[i]); if( c == 'z') { digitalWrite(led_pin , LOW); digitalWrite(rightmotor1 , LOW); digitalWrite(rightmotor2 , LOW); digitalWrite(leftmotor1 , LOW); digitalWrite(leftmotor2 , LOW); Serial.print(c); Serial.print(' '); } if( c == 'j') // for right side { digitalWrite(rightmotor1 , LOW); digitalWrite(rightmotor2 , LOW); digitalWrite(led_pin, LOW); digitalWrite(leftmotor1 , HIGH); digitalWrite(leftmotor2 , LOW); delay(200); digitalWrite(leftmotor1 , LOW); digitalWrite(leftmotor2 , LOW); delay(200); // digitalWrite(leftmotor1 , HIGH); // digitalWrite(leftmotor2 , LOW); Serial.print(c); Serial.print(' '); } if( c == 'h') // for straight { digitalWrite(led_pin, HIGH); digitalWrite(rightmotor1 , HIGH); digitalWrite(rightmotor2 , LOW); digitalWrite(leftmotor1 , HIGH); digitalWrite(leftmotor2 , LOW); Serial.print(c); Serial.print(' '); } if( c == 'l') // for left { digitalWrite(leftmotor1 , LOW); digitalWrite(leftmotor2 , LOW); digitalWrite(rightmotor1 , HIGH); digitalWrite(rightmotor2 , LOW); delay(200); digitalWrite(rightmotor1 , LOW); digitalWrite(rightmotor2 , LOW); delay(200); // digitalWrite(leftmotor1 , LOW); // digitalWrite(leftmotor2 , HIGH); Serial.print(c); Serial.print(' '); } if( c == 'm') { Serial.print(c); Serial.print(' '); } } } }
1 Comments
Anonymous
27 October 2023 at 18:25
good job
Reply
Delete
Replies
Reply
Add comment
Load more...
Newer
Older
ESP32 Interfacing With LDR Sensor
Smart Street Light Using Arduino
ESP32 Led Blink With Push Button
EM-18 Interface With Arduino Nano
Ultrasonic Sensor as a Counter with Arduino
ESP32 And Fingerprint Sensor Based Biometric Door Lock Security System
Measure CO2 Level in Air Using Arduino
IoT Based Patient Health Monitoring System Using Blynk App
Em-18 Interfacing With Esp32
Nodemcu Interfacing With Em-18
YouTube
Like on Facebook
Follow on Twitter
Follow on Google+
Follow on Instagram
Subscribe on Youtube
Hi WelCome To My Website If you have a creative mind and want to learn Electronics even without studying it then FRIENDS this Website And Youtube Channel is for you, I am crazy creators who love making Electronics things. I have a bunch of more than 130 Tutorial Videos on My YouTube Channel and I upload a new Tutorial every Sunday.
Tags
Arduino Project
Esp32 Project
Esp8266 Project
1 Comments
good job
ReplyDelete