Components and supplies
Battery 9.6 V
433 Mhz ASK RF module transmitter and receiver
I2C LCD 20x4
arduino uno
Switch
Arduino Nano
10 jumper wires 150mm male
Breadboard - 400 contacts
Tools and machines
Laser cutter (generic)
Apps and platforms
Arduino IDE 2.0 (beta)
Project description
Code
Reviver Code
cpp
1#include <VirtualWire.h> 2#include <Wire.h> //IIC Library 3#include <LiquidCrystal_I2C.h>//For the screen 4#include <elapsedMillis.h>//For the Status 5LiquidCrystal_I2C lcd(0x3F,20,4); // set the parameters 6boolean constat=1;//Status Variable 1=On at start, 0=off at start 7int line;//Status code moves cursor, variable to store DESIRED line number 8boolean splashcleared;//Bool to hold if splash screen has been cleared 9String text = " ";//String to hold the text 10elapsedMillis packettimer;//The timer for status 11#define interval 1500//The threshold for how long it can go without "6"(The connection indicator) 12 13//initialize the symbols 14 15 16void setup() 17{ 18 pinMode(12, OUTPUT); //Module VCC 19 digitalWrite(12, HIGH); // turn the VCC to High 20 vw_set_rx_pin(11);// set you rx pin 21 vw_setup(2500); // Bits per sec. Lower for further distance. Make sure this matches the number on the transmitter 22 vw_rx_start(); // Start the receiver PLL running 23 splashcleared=0;//make sure that this is 0 24 lcd.init();//start the screen 25 //initialize the symbols 26 //setCursor comands note- Counting starts at 0 NOT 1 27 lcd.createChar(0, cchar); //Rf symbol 28 lcd.createChar(1, bar1); //Bar 1 and 2 29 lcd.createChar(2, bar2); //Bar 3 and 4 30 Serial.begin(9600);//Open serial port, add the !serial thing for leonardo 31 lcd.backlight();//Turn on the backlight 32 lcd.clear();//Clear the screen 33 lcd.home();//go home 34 35 //display Home screen This will be cleared once The siglal indicator "6" is sent 36 lcd.setCursor (5,0); 37 lcd.print("RF--Screen"); 38 lcd.setCursor (0,1); 39 lcd.print("By ICARUS"); 40 lcd.setCursor (0,2); 41 lcd.print("Connection Status-"); 42 lcd.setCursor (0,3); 43 lcd.print("Inactive"); 44 delay (1200);//set this to the interval 45} 46 47 48 void loop() 49 { 50 uint8_t buf[VW_MAX_MESSAGE_LEN]; 51 uint8_t buflen = VW_MAX_MESSAGE_LEN; 52 53 54 if (packettimer< interval){//It the status of the connection is good and "6" was recieved in the last 1.5 secs. 55 if (splashcleared==0){//if screen hasn't been cleared of status 56 lcd.clear();//clear it 57 splashcleared=1;//make sure it won't be again 58 } 59 }//make sure the screen wont clear again 60 61 62 if (constat==1){ //If the status bar is enabled 63 if (packettimer< interval){//It the status of the connection is good and "6" was recieved in the last 1.5 secs. 64 65 lcd.setCursor (17,0); //go to 3rd last position 66 lcd.write(0); //RF symbol 67 lcd.write(1);//bar one 68 lcd.write(2);//Bar two 69 } 70 71 else if (packettimer > interval) {//It the status of the connection is bad and "6" was not recieved in the last 1.5 secs. 72 //we will blink a X by the rf symbol 73 lcd.setCursor (17,0);//go to 3rd last position 74 lcd.write(0); //RF symbol 75 lcd.setCursor (18,0);//go to 2nd last position 76 lcd.print ("X ");//To add the X 77 delay (450);// wait 78 lcd.setCursor (18,0);////go to 2nd last position 79 lcd.print (" ");//To erase the X 80 delay (400);//wait 81 82 } 83 } 84 85 86 if (vw_get_message(buf, &buflen)) // Non-blocking 87 { 88 packettimer = 0;//Reset timer when data is recieved 89 text.remove(0);//clear all text from string: text 90 text=(char*)buf;//put new data into string "text" 91 92 93 text.remove(buflen-1);//Remove garbage after the end of the text 94 lcd.setCursor(0,line);//Restore cursor to original position 95 //Most of these commands are self explanitory... 96 97 if (text.startsWith("1")) { 98 lcd.setCursor(0,0); 99 line=0; 100 } 101 102 else if (text.startsWith("2")) { 103 lcd.setCursor(0,1); 104 line=1; 105 106 } 107 else if (text.startsWith("3")) { 108 lcd.setCursor(0,2); 109 line=2; 110 111 } 112 else if (text.startsWith("4")) { 113 lcd.setCursor(0,3); 114 line=3; 115 116 } 117 else if (text.startsWith("clear")) { 118 lcd.clear(); 119 } 120 else if (text.startsWith("6")) {//"6" is sent every 300 ms to check the signal, and we dont want it to display 121 packettimer = 0;//Reset timer when data is recieved 122 if (splashcleared==0){//if screen hasn't been cleared of status 123 lcd.clear(); 124 splashcleared=1;//make sure the screen wont clear again 125 } 126 } 127 else if (text.startsWith("backlight")) { 128 lcd.backlight(); 129 } 130 else if (text.startsWith("nobacklight")) { 131 lcd.noBacklight(); 132 } 133 else if (text.startsWith("status")) { 134 lcd.setCursor (17,0);//Go to the third last spot 135 lcd.write(0);//Show the Rf symbol 136 lcd.write(1);//Show bar set 1 137 lcd.write(2);//Show bar set 2 138 constat=1;//(ConnectionStatus)this variable will make the signal show 139 } 140 else if (text.startsWith("nostatus")) { 141 lcd.setCursor (17,0);//Go to the third last spot 142 lcd.print (" ");//write it over with 3 spaces 143 constat=0;//(ConnectionStatus)this variable will block the signal from showing 144 145 } 146 147 else if (text.startsWith("{")) {//if we want to sen a command word to display on screen, we precede it with{ 148 text.remove (1); //remove the"{", This must be second last of if statements 149 } 150 else {//this MUST be last statement 151 packettimer = 0;//Reset timer when data is put onto the screen 152 lcd.setCursor(0,line);//Go to the specified line 153 lcd.print(text);//If word isn't a command print it 154 } 155 156 } 157 }
I2C Code
cpp
1#include <Wire.h> 2 3void setup() 4 { 5 Wire.begin(); 6 7 Serial.begin(115200); 8 Serial.println("\nI2C Scanner"); 9 } 10 11void loop() 12 { 13 byte error, address; 14 int nDevices; 15 16 Serial.println("Scanning..."); 17 18 nDevices = 0; 19 for(address = 0; address <= 127; address++ ) 20 { 21 // The i2c_scanner uses the return value of 22 // the Write.endTransmisstion to see if 23 // a device did acknowledge to the address. 24 Wire.beginTransmission(address); 25 error = Wire.endTransmission(); 26 27 if (error == 0) 28 { 29 Serial.print("I2C device found at address 0x"); 30 if (address<16) 31 Serial.print("0"); 32 Serial.print(address,HEX); 33 Serial.println(" !"); 34 35 nDevices++; 36 } 37 else if (error==4) 38 { 39 Serial.print("Unknow error at address 0x"); 40 if (address<16) 41 Serial.print("0"); 42 Serial.println(address,HEX); 43 } 44 } 45 if (nDevices == 0) 46 Serial.println("No I2C devices found\n"); 47 else 48 Serial.println("done\n"); 49 50 delay(8000); // wait 8 seconds for next scan 51 }
Sender Code
cpp
1#include <VirtualWire.h> 2#include <elapsedMillis.h> //For the status on the reciever 3 4String serialdata; //Holds data coming in 5char msg[50]; //Char array to send data out with 6String statustext="6"; //This is the text sent every interval 7elapsedMillis packettimer;//this is the timer 8#define interval 50//Lower this if you send long packets 9 10void setup() 11{ 12 pinMode(8, OUTPUT);//Module GND 13 pinMode(9, OUTPUT); //Module VCC 14 digitalWrite(9, HIGH); // turn the VCC to HIGH, set to LOW for default off 15 digitalWrite(8, LOW); // turn the GND to LOW 16 vw_set_tx_pin(10); 17 vw_setup(2500); // Bits per sec 18 Serial.begin(9600); 19 packettimer = 0;//Reset the timer 20 Serial.println ("Serial Port Open"); 21} 22 23void loop() 24{ 25 26 if (Serial.available()){ 27 delay (50); 28 Serial.println ("I found Serial Data");// If you are having issues, these will help you find where your code doesnt work. 29 serialdata=Serial.readString();//put text from serial in serialdata string 30 31 if (serialdata.startsWith("off")) { 32 digitalWrite(9, LOW); // turn the VCC to LOW 33 digitalWrite(8, LOW); // turn the GND to LOW 34 Serial.println(""); 35 Serial.println("Module OFF"); 36 Serial.println(""); 37 } 38 else if (serialdata.startsWith("on")) { 39 digitalWrite(9, HIGH); // turn the VCC to HIGH 40 digitalWrite(8, LOW); // turn the GND to LOW 41 Serial.println(""); 42 Serial.println("Module ON"); 43 Serial.println(""); 44 } 45 46 else { 47 48 serialdata.toCharArray(msg, 50);//convert serialdat the the msg char array 49 Serial.println ("I converted it to a CHAR ARRAY"); 50 Serial.println("Text to be Sent-");//debugging 51 Serial.println("");//debugging 52 Serial.print(msg);//debugging 53 Serial.println("");//debugging 54 vw_send((uint8_t *)msg, strlen(msg)); 55 vw_wait_tx(); 56 Serial.println ("MSG send request"); 57 // driver.waitPacketSent();//wait until it is sent 58 Serial.println ("Data Sent"); 59 } 60 } 61 62 if (packettimer > interval) { 63 64 statustext.toCharArray(msg, 50);//convert the statustext string to msg char array 65 vw_send((uint8_t *)msg, strlen(msg)); //line that sends the msg variable 66 vw_wait_tx();//wait untill sent 67 } 68} 69//Code mainly From Arduino.cc and VW examples
Downloadable files
Receiver Side2.dxf
Receiver Side2.dxf
Receiver Top.dxf
Receiver Top.dxf
Transmitter Back.dxf
Transmitter Back.dxf
Transmitter Bottom.dxf
Transmitter Bottom.dxf
Transmitter Front.dxf
Transmitter Front.dxf
Transmitter Side 2.dxf
Transmitter Side 2.dxf
Transmitter Top.dxf
Transmitter Top.dxf
Transmitter Side.dxf
Transmitter Side.dxf
Receiver Back.dxf
Receiver Back.dxf
Receiver Bottom.dxf
Receiver Bottom.dxf
Receiver Front.dxf
Receiver Front.dxf
Receiver Side1.dxf
Receiver Side1.dxf
Documentation
Instructables
https://www.instructables.com/Wireless-Communication-Using-Arduino-and-RF-Module/
Comments
Only logged in users can leave comments