RoomSensors

Temperature and Luminosity sensors using Arduino

Instead of sending data from Android to Arduino to perform something like all of my previous projects, this project deals with receiving data from Arduino.

Android Screen-shots:







Arduino

//Project: Temperature and Luminosity Readings

#include <SoftwareSerial.h>// import the serial library
SoftwareSerial newPorts(10, 11); // RX, TX

int potPin = 1 ; // pin for temperature sensor
int ldr = 3; // pin for ldr sensor

void setup()
{
  newPorts.begin(9600);  
  pinMode(ldr, INPUT);
  pinMode(potPin, INPUT); 
  newPorts.println("Ready...");
}

void loop()
{
  while (newPorts.available() > 0)
  {   
    char ch = newPorts.read();
    executeReceivedCommand(ch);
  }
}

void executeReceivedCommand(char command)
{
  switch (command)
  {
  case '1':
    int val;
    int dat;
    val = analogRead(potPin);
    dat = (125*val)>>8 ; // Temperature calculation formula
    newPorts.print("Temperature:\n");
    newPorts.print(dat);
    newPorts.println(" D Celcius"); 
    break;
   
 case '0':
    int ldrValue;
    ldrValue= analogRead(ldr);
    newPorts.print("Luminosity:\n")
    newPorts.print(ldrValue);
    newPorts.println(" Units");
    break;
  }
}