mbed mini project - Arduino Remote Weather Sensor

Description

For Lab 3, we decided to do a mini design project with an Arduino Uno microcontroller board. The Arduino is used as a remote/outside weather device. The 2 devices connect over an ad hoc network using a WiFly interface.

Components

  • mbed LPC1768
  • Arduino Uno
  • WiFly Module
  • LCD Display
  • I/O Expander
  • Phidgets 1125 Temperature/Humidity Sensor

Arduino

/media/uploads/hpatel71/img_1412.jpg /media/uploads/hpatel71/img_1414.jpg

The Arduino is placed at a remote location for temperature and humidity sensing with the Phidgets 1125 sensor attached. In order to send the analog data to the mbed for LCD display, the WiFlyHQ library by harleqin-tech for Arduino found on GitHub were used:

WiFiHQ Library for Arduino Uno

The temperature sensor is connected to pin 0, and humidity to pin 1. The WiFly receive and send signals are connected to pins 2 and 3.

Arduino Code to send data to mbed

#include <SPI.h>
#include <SoftwareSerial.h>
#include <WiFlyHQ.h>

#define rxPin 2
#define txPin 3

const static char tempPin = 0;
const static char humidPin = 1;


SoftwareSerial wifiSerial(rxPin, txPin);

char ssid[] = "ADHOC";

WiFly wifly;
float temp;
float humid;

void setup()
{
  Serial.begin(9600);
  Serial.println("Wifly Adhoc");
  wifiSerial.begin(9600);
  wifly.begin(&wifiSerial);

  if(!wifly.createAdhocNetwork(ssid,2)) 
  {
    while(1) 
    {
     Serial.println("Failed to create network, handle error properly?");
    }
  }
  Serial.println("Network Created");
  Serial.print("UpTime: ");
  Serial.println(wifly.getUptime()); 

  
  char buf[64];
 
    Serial.print("MAC: ");
    Serial.println(wifly.getMAC(buf, sizeof(buf)));
    Serial.print("IP: ");
    Serial.println(wifly.getIP(buf, sizeof(buf)));
    Serial.print("Netmask: ");
    Serial.println(wifly.getNetmask(buf, sizeof(buf)));
    Serial.print("Gateway: ");
    Serial.println(wifly.getGateway(buf, sizeof(buf)));
    Serial.println(wifly.getSSID(buf, sizeof(buf)));
    wifly.setIpProtocol(WIFLY_PROTOCOL_TCP); 

 
}


void loop()
{ 
   while(!wifly.open("169.254.1.2",8042)){
     Serial.println("Trying..");
   }
    while(wifly.isConnected()){
      temp =  ((analogRead(tempPin) * 0.22222) - 61.11)  * 1.8 + 32.0; //convert reading to temp Fahrenheit
      humid = (analogRead(humidPin) * 0.1906) - 40.2; //convert reading to relative humidity (%)
      wifly.print("Temperature: ");
      wifly.print(temp);
      wifly.println("^");
      wifly.print("Humidity: ");
      wifly.print(humid);
      wifly.println("$");
      Serial.print("Temperature:");
      Serial.println(temp);
      Serial.print("Humidity:");
      Serial.print(humid);
      Serial.println("%");
      
      delay(250);
    }
    wifly.close();
}

The Arduino code creates a local TCP connection to the mbed and sends the adjusted analog temperature and humidity data so that it can be printed to the LCD Display.

mbed

/media/uploads/hpatel71/img_1415.jpg

The mbed is connected directly to a WiFly module and an LCD Display module. In the code below pins 27 and 28 are connected to pins 2 and 3 on the module.

Pinout for LCD Display in code below:

mbed p26: RS, mbed p25: E, mbed p24-21: d4-d7

Import programmbed_Arduino_sensor

lab 3 remote weather sensor

The code receives the temperature and humidity information in a buffer until there's enough data to parse (15 bytes in our code). In the Arduino code, break characters (the carat and dollar sign) are sent in order to parse the values correctly. The data is received as characters, so they are converted back into integers before being printed onto the LCD just in case any manipulation of the values is required.

Demonstration

/media/uploads/hpatel71/img_1416.mov

Problems Encountered

  • The temperature values seem to be off

The datasheet for the sensor was used to convert the analog values according to specification, but the value is still off sometimes.

  • When one device is disconnected, both of the devices must be rebooted in order to reestablish the connection

A TCP connection issue is addressed in the WiFly libraries for the Arduino.


Please log in to post comments.