The User taps the touch screen to Turn ON/OFF a desired remote appliance. This is detected by the Primary microcontroller (Atmega2560) which broadcasts a command through the secondary microcontroller (ATmega328P) via the 433 MHz transmitter module. Additionally a RTC (Real Time Clock) connected to the Microcontroller displays the current time and date in the touch screen. On the remote receiver end the wireless signal is received by the 433 MHz receiver module, and the microcontroller decides which electrical appliance to turn ON/OFF, and does so by the relays.

 

 



 

 The Atmega168 Bare-Bone Arduino Transmitter:

Arduino Code:
  1.  
  2. #include "VirtualWire.h"
  3. char inData[50]; // Allocate some space for the string
  4. char outData[50];
  5. char nullData[50];
  6. char inChar = -1; // Where to store the character read
  7. byte index = 0; // Index into array; where to store the character
  8.  
  9.  
  10. void setup()
  11. {
  12. Serial.begin(9600); // Debugging only
  13. Serial.println("setup");
  14. vw_set_tx_pin(9);
  15. // Initialise the IO and ISR
  16. vw_set_ptt_inverted(true); // Required for DR3100
  17. vw_setup(2000); // Bits per sec
  18. }
  19.  
  20. void loop()
  21. {
  22. //const char *msg = "hello";
  23.  
  24. while (Serial.available() > 0) // Don't read unless
  25. // there you know there is data
  26. {
  27. if (index < 49) // One less than the size of the array
  28. {
  29. inChar = Serial.read(); // Read a character
  30. inData[index] = inChar; // Store it
  31. index++; // Increment where to write next
  32. inData[index] = '\0'; // Null terminate the string
  33. }
  34. }
  35. Serial.print("The input data is: ");
  36. Serial.println(inData);
  37. if (strcmp(inData, nullData) == 0) {
  38. delay(1);
  39. }
  40. else
  41. {
  42. strcpy(outData, inData);
  43. }
  44. for (int i = 0; i < 49; i++) {
  45. inData[i] = 0;
  46. }
  47. index = 0;
  48. Serial.print("The output data is: ");
  49. Serial.println(outData);
  50.  
  51. digitalWrite(13, true); // Flash a light to show transmitting
  52. vw_send((uint8_t *)outData, strlen(outData));
  53. vw_wait_tx(); // Wait until the whole message is gone
  54. digitalWrite(13, false);
  55. delay(200);
  56.  
  57. for (int i = 0; i < 49; i++) {
  58. outData[i] = 0;
  59. }
  60. }
  61.  




The Touch Screen Controller (Transmitter):

Arduino Code:
  1.  
  2.  
  3. #include "UTFT.h"
  4. #include "UTouch.h"
  5.  
  6. #include "DigitalToggle.h"
  7.  
  8. #include "Wire.h"
  9. #include "RTClib.h"
  10.  
  11. RTC_DS1307 RTC;
  12.  
  13. // Declare which fonts we will be using
  14. extern uint8_t SmallFont[];
  15. extern uint8_t BigFont[];
  16. extern uint8_t SevenSegNumFont[];
  17.  
  18. UTFT myGLCD(ITDB32S, 38, 39, 40, 41);
  19. UTouch myTouch(6, 5, 4, 3, 2);
  20.  
  21. int x, y;
  22.  
  23.  
  24. /*************************
  25. ** Custom functions **
  26. *************************/
  27.  
  28. void drawButtons()
  29. {
  30. // Draw the fan on/off button
  31. myGLCD.setColor(0, 0, 255);
  32. myGLCD.fillRoundRect (10, 130, 150, 180);
  33. myGLCD.setColor(255, 255, 255);
  34. myGLCD.drawRoundRect (10, 130, 150, 180);
  35. myGLCD.print("Fan On/Off", 40, 147);
  36.  
  37. //Draw the Light On/Off button
  38. myGLCD.setColor(0, 0, 255);
  39. myGLCD.fillRoundRect (160, 130, 300, 180);
  40. myGLCD.setColor(255, 255, 255);
  41. myGLCD.drawRoundRect (160, 130, 300, 180);
  42. myGLCD.print("Light On/OFF", 190, 147);
  43. myGLCD.setBackColor (0, 0, 0);
  44.  
  45. // //Draw Fan Speed Control
  46. // myGLCD.setColor(0, 0, 255);
  47. // myGLCD.fillRoundRect (10, 185, 70, 235);
  48. // myGLCD.setColor(255, 255, 255);
  49. // myGLCD.drawRoundRect (10, 185, 70, 235);
  50. // myGLCD.print("+", 30,205 );
  51. //
  52.  
  53. }
  54.  
  55.  
  56. // Draw a red frame while a button is touched
  57. void waitForIt(int x1, int y1, int x2, int y2)
  58. {
  59. myGLCD.setColor(255, 0, 0);
  60. myGLCD.drawRoundRect (x1, y1, x2, y2);
  61. while (myTouch.dataAvailable())
  62. myTouch.read();
  63. myGLCD.setColor(255, 255, 255);
  64. myGLCD.drawRoundRect (x1, y1, x2, y2);
  65. }
  66.  
  67. void displayTime()
  68. {
  69. DateTime now = RTC.now();
  70.  
  71. myGLCD.setFont(BigFont);
  72. myGLCD.printNumI(now.day(), 70, 30);
  73. myGLCD.print("/", 102, 30);
  74. myGLCD.printNumI(now.month(), 118, 30);
  75. myGLCD.print("/", 150, 30);
  76. myGLCD.printNumI(now.year(), 166, 30);
  77.  
  78. int current_hour = now.hour();
  79. if (current_hour > 11) {
  80. current_hour = current_hour - 12;
  81. myGLCD.setFont(BigFont);
  82. myGLCD.print("PM", 275, 90);
  83. }
  84. else {
  85. myGLCD.setFont(BigFont);
  86. myGLCD.print("AM", 275, 90);
  87. }
  88.  
  89. myGLCD.setFont(SevenSegNumFont);
  90. myGLCD.printNumI(current_hour, 20, 60);
  91. myGLCD.setFont(BigFont);
  92. myGLCD.print(":", 89, 77);
  93. myGLCD.setFont(SevenSegNumFont);
  94. myGLCD.printNumI(now.minute(), 110, 60);
  95. myGLCD.setFont(BigFont);
  96. myGLCD.print(":", 179, 77);
  97. myGLCD.setFont(SevenSegNumFont);
  98. myGLCD.printNumI(now.second(), 200, 60);
  99. myGLCD.setFont(SmallFont);
  100. }
  101.  
  102. /*************************
  103. ** Required functions **
  104. *************************/
  105.  
  106. void setup()
  107. {
  108. Serial.begin(9600);
  109. Serial2.begin(9600);
  110. Wire.begin();
  111. RTC.begin();
  112. // Initial setup
  113. myGLCD.InitLCD();
  114. myGLCD.clrScr();
  115.  
  116. myTouch.InitTouch();
  117. myTouch.setPrecision(PREC_MEDIUM);
  118.  
  119. myGLCD.setFont(SmallFont);
  120. myGLCD.setBackColor(0, 0, 255);
  121. drawButtons();
  122. }
  123.  
  124. void loop()
  125. {
  126. while (true)
  127. {
  128.  
  129. displayTime();
  130. delay(5);
  131. myGLCD.setFont(SmallFont);
  132. if (myTouch.dataAvailable())
  133. {
  134. myTouch.read();
  135. x = myTouch.getX();
  136. y = myTouch.getY();
  137.  
  138.  
  139. if ((y >= 130) && (y <= 180)) // button row
  140. {
  141. if ((x >= 10) && (x <= 150)) // Button: Fan ON/OFF
  142. {
  143. waitForIt(10, 130, 150, 180);
  144. //enter action
  145. Serial2.println("ToggleFan");
  146. Serial.println("ToggleFan");
  147. myGLCD.setFont(BigFont);
  148. myGLCD.setColor(VGA_YELLOW);
  149. myGLCD.print("Fan State Toggled ", 15, 210);
  150. delay(500);
  151. myGLCD.print(" ", 15, 210);
  152. delay(500);
  153. myGLCD.print("Fan State Toggled ", 15, 210);
  154. delay(500);
  155. myGLCD.print(" ", 15, 210);
  156. }
  157. if ((x >= 160) && (x <= 300)) // Button: Light ON/OFF
  158. {
  159. waitForIt(160, 130, 300, 180);
  160. //enter action
  161. Serial2.println("ToggleLight");
  162. Serial.println("ToggleLight");
  163. myGLCD.setFont(BigFont);
  164. myGLCD.setColor(VGA_LIME);
  165. myGLCD.print("Light State Toggled", 15, 210);
  166. delay(500);
  167. myGLCD.print(" ", 15, 210);
  168. delay(500);
  169. myGLCD.print("Light State Toggled", 15, 210);
  170. delay(500);
  171. myGLCD.print(" ", 15, 210);
  172. }
  173. }
  174. }
  175. }
  176. }
  177.  



The Arduino Mega 2560 Receiver:

Arduino Code:
  1.  
  2.  
  3. #include "VirtualWire.h"
  4. #include "DigitalToggle.h"
  5.  
  6. int led_pin = 13;
  7. int fan_pin = 8;
  8. int light_pin = 9;
  9. int dc_fan = 12;
  10.  
  11. char inData[50]; // Allocate some space for the string
  12.  
  13. void setup()
  14. {
  15. Serial.begin(9600); // Debugging only
  16. Serial.println("setup");
  17. pinMode(led_pin, OUTPUT);
  18. pinMode(fan_pin, OUTPUT);
  19. pinMode(light_pin, OUTPUT);
  20. pinMode(dc_fan, OUTPUT);
  21. // Initialise the IO and ISR
  22. vw_set_ptt_inverted(true); // Required for DR3100
  23. vw_setup(2000); // Bits per sec
  24. vw_set_rx_pin(7);
  25. vw_rx_start(); // Start the receiver PLL running
  26. }
  27.  
  28.  
  29. void loop()
  30. {
  31. digitalWrite(dc_fan, HIGH);
  32. uint8_t buf[VW_MAX_MESSAGE_LEN];
  33. uint8_t buflen = VW_MAX_MESSAGE_LEN;
  34.  
  35. if (vw_get_message(buf, &buflen)) // Non-blocking
  36. {
  37. int i;
  38.  
  39. digitalWrite(13, true); // Flash a light to show received good message
  40. // Message with a good checksum received, dump it.
  41. //Serial.print("Got: ");
  42.  
  43. for (i = 0; i < buflen; i++)
  44. {
  45. // Serial.print(buf[i], HEX);
  46. // Serial.print(" ");
  47. inData[i] = buf[i];
  48. }
  49. //Serial.println("");
  50. digitalWrite(13, false);
  51. Serial.print("The received data is:");
  52. Serial.print(inData);
  53. Serial.print(" ");
  54. Serial.print("The Length is: ");
  55. Serial.print(buflen);
  56.  
  57.  
  58. if (inData[6] == 'L') {
  59. Serial.println("Toggle the light");
  60. digitalToggle(light_pin);
  61. }
  62. if (inData[6] == 'F') {
  63. Serial.println("Toggle the Fan");
  64. digitalToggle(fan_pin);
  65. }
  66. }
  67. }
  68.  
  69.