Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h> // use Wire library for protocol i2c (A4 = SDA & A5 = SCL)
- #include <LiquidCrystal_I2C.h> // use LiquidCrystal_I2C library for control LCD on i2c protocol
- #include <VirtualWire.h> // use Virtual library for decode signal from Rx module
- byte thermometer[8] = //icon for thermometer
- {
- B00100,
- B01010,
- B01010,
- B01110,
- B01110,
- B11111,
- B11111,
- B01110
- };
- byte droplet[8] = //icon for droplet
- {
- B00100,
- B00100,
- B01010,
- B01010,
- B10001,
- B10001,
- B10001,
- B01110,
- };
- byte hi[8]= //icon for heat index
- {
- 0B00000,
- 0B00000,
- 0B10101,
- 0B01110,
- 0B11111,
- 0B01110,
- 0B10101,
- 0B00000,
- }; //(addr, EN,RW,RS,D4,D5,D6,D7,BL,BLpol)
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //change the address as per your I2C module
- // Sensors
- int humidity=0;
- int temp=0;
- int heat_index=0;
- char MsgReceived[21];
- int led = 13; //pin for LED
- void setup()
- {
- lcd.begin(20,4); // set up the LCD's number of columns and rows:
- lcd.backlight(); //backlight is now ON
- pinMode(led, OUTPUT);
- // VirtualWire
- // Bits per sec
- vw_setup(2000);
- // set pin for connect receiver module
- vw_set_rx_pin(11);
- // Start the receiver PLL running
- vw_rx_start();
- lcd.begin(20,4); // initialize the lcd for 20 chars 4 lines, turn on backlight
- lcd.backlight(); // finish with backlight on
- lcd.createChar(1, thermometer);
- lcd.createChar(2, droplet);
- lcd.createChar(3,hi);
- lcd.clear(); // clear the screen
- } // END void setup
- void loop()
- {
- uint8_t buf[VW_MAX_MESSAGE_LEN];
- uint8_t buflen = VW_MAX_MESSAGE_LEN;
- //Taking the data from the control base
- if (vw_get_message(buf, &buflen))
- {
- digitalWrite(led, HIGH);
- delay(100);
- int i;
- // Message with a good checksum received, dump it.
- for (i = 0; i < buflen; i++)
- {
- // Fill Msg Char array with corresponding
- // chars from buffer.
- MsgReceived[i] = char(buf[i]);
- //Serial.print(MsgReceived[i]);
- }
- sscanf(MsgReceived, "%d,%d,%d",&humidity, &temp,&heat_index); // Converts a string to an array
- digitalWrite(led, LOW);
- lcd_display();
- memset( MsgReceived, 0, sizeof(MsgReceived));// This line is for reset the StringReceived
- }
- }
- void lcd_display()
- { lcd.setCursor(1,0);
- lcd.print(" WEATHER STATION ");
- lcd.setCursor(4,1);
- lcd.print("TEMP");
- lcd.setCursor(9, 1);
- lcd.write(1);
- lcd.setCursor(11, 1);
- lcd.print(temp);
- lcd.write(0b11011111);
- lcd.print("C");
- lcd.setCursor(4,2);
- lcd.print("HUM");
- lcd.setCursor(9, 2);
- lcd.write(2);
- lcd.setCursor(11, 2);
- lcd.print(humidity);
- lcd.print("%");
- lcd.setCursor(4,3);
- lcd.print("HI");
- lcd.setCursor(9, 3);
- lcd.write(3);
- lcd.setCursor(11, 3);
- lcd.print(heat_index);
- lcd.write(0b11011111);
- lcd.print("C");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement