test_Code / weather_Reciver / weather_Reciver.inoon commit Added readme code notes (00df5ca)
   1// receiver.pde
   2//
   3// Simple example of how to use VirtualWire to receive messages
   4// Implements a simplex (one-way) receiver with an Rx-B1 module
   5//
   6// See VirtualWire.h for detailed API docs
   7// Author: Mike McCauley (mikem@airspayce.com)
   8// Copyright (C) 2008 Mike McCauley
   9// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
  10#include <VirtualWire.h>
  11#include <stdio.h>
  12#include <string.h>
  13#include <LiquidCrystal.h>
  14
  15double Temp;
  16
  17LiquidCrystal lcd(12, 10, 5, 4, 3, 2); //LCD Pins
  18int LCDpin =9;  //LCD backlight Pin
  19int Humid; // Value
  20#define pir A0 //Pin for the PIR input
  21
  22//Varaible to store the recoverd values
  23String TempC; //Temp in C
  24String Vocht; //humidity
  25String Druk;  //pressure
  26
  27void setup()
  28{
  29  Serial.begin(9600); // Debugging only
  30  Serial.println("setup");
  31
  32
  33  ////Setting pins for backlight
  34  pinMode(pir, INPUT);
  35  pinMode(LCDpin, OUTPUT);
  36
  37  //LCD
  38  lcd.begin(20, 4); //Setting rows an colums
  39
  40  lcd.setCursor(0, 0); //Set Cursor at begining
  41  lcd.print("####################"); //Drawing
  42
  43  lcd.setCursor(0, 1); //Set cursor at next line
  44  lcd.print("#      Bram's      #"); //Drawim 
  45
  46  lcd.setCursor(0, 2); //Set cursor at next line
  47  lcd.print("# Weather  station #"); //Drawim 
  48
  49  lcd.setCursor(0, 3); //Set cursor at next line
  50  lcd.print("#######-V1.0-#######"); //Drawim 
  51
  52  //Show on Screen, if this isnt called, screen would be empty
  53  lcd.display(); 
  54
  55  //Set back color to full brightness
  56  digitalWrite(LCDpin,255);
  57
  58  //Wait a seccond
  59  delay(1000);
  60
  61  //For Receiving  Data
  62  // Initialise the IO and ISR
  63  vw_set_ptt_inverted(true); // Required for DR3100
  64  vw_setup(2000);      // Bits per sec
  65  vw_rx_start();       // Start the receiver PLL running
  66}
  67
  68
  69
  70void loop()
  71{
  72  //IF PIR sensor if HIGH, LCD backlight is on
  73  //The Sensitivity  and duration is adjusted ON the PIR
  74  digitalWrite(LCDpin, digitalRead(pir));
  75
  76  ////Receiving  DATA
  77  uint8_t buf[VW_MAX_MESSAGE_LEN];
  78  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  79  if (vw_get_message(buf, &buflen)) // Non-blocking
  80  {
  81    int i;
  82    digitalWrite(13, true);  //onboard LED ON 
  83    char Chars[buflen]; 
  84    for (i = 0; i < buflen; i++)
  85    {
  86      Chars[i]  = char(buf[i]); //from buffer to Char Arry
  87    }
  88
  89    Serial.println(Chars); //Debug only
  90    Decode(Chars); //Send to deconder
  91    digitalWrite(13, false); //onboard LED OFF 
  92  }
  93}
  94
  95void Decode(char* Raw)
  96{
  97
  98  String Code = (String)Raw; //From Char Array to string
  99  if (Code.startsWith("#C")) //Looks if Code starts With #C
 100  {
 101    TempC = Code.substring(2,7); //get 2 to 7 char and put in int TempC string
 102  }
 103
 104  if (Code.startsWith("#H")) //Looks if Code starts With #H
 105  {
 106    Vocht = Code.substring(2,4);//get 2 to 4 char and put in int Vocht string
 107  }
 108
 109  if (Code.startsWith("#P")) //Looks if Code starts With #P
 110  {
 111    Druk =  Code.substring(2,8);//get 2 to 8 char and put in int Druk string
 112  }
 113
 114  SetScreen();  //Call Funtion
 115}
 116
 117//Herbouw scherm
 118void SetScreen()
 119{
 120
 121  lcd.clear(); //Cleas LCD
 122  lcd.begin(20, 4); //set screen res
 123
 124  if (TempC != "")
 125  {
 126    lcd.setCursor(0, 0); //Set Cursos
 127    lcd.print(((String)"  Temp = " + TempC + " oC")); //Writes text with received value
 128  }
 129
 130  if (Vocht != "")
 131  {
 132    lcd.setCursor(0, 1); //Set Cursos
 133    lcd.print(((String)"    Vocht = " + Vocht +  "%")); //Writes text with received value
 134  }
 135
 136  if (Druk != "")
 137  {
 138    lcd.setCursor(0, 2); //Set Cursos
 139    lcd.print(((String)"  Druk = " + Druk +  " HPA"));//Writes text with received value
 140  }
 141  lcd.display();
 142}
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174