Show Posts
Pages: 1 ... 14 15 [16] 17 18 19
226  Forum 2005-2010 (read only) / Interfacing / Re: Analog value for IR Photodioide? on: October 25, 2010, 03:55:46 pm
Hi RuggedC,

Thanks for the pointer - I have tried it but I just get values in the serial which slowly fall from about 500 with no response to anything?

May I check the below with you - sorry, very basic.

PhotoDiode Long leg to Arduino Analog pin 0
PhotoDiode Short leg to Arduino GND
PhotoDiode Long leg to Arduino +5v using 10K ohm resistor

Using this code:

Code:
void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(0);
  Serial.println(sensorValue, DEC);
  delay(1000);
}
227  Forum 2005-2010 (read only) / Interfacing / Analog value for IR Photodioide? on: October 25, 2010, 01:30:35 pm
Hi, I have been trying to set up an arduino to measure Infra Red  (how much) using an Osram SFH 203 FA but with ZERO results !!

http://uk.farnell.com/osram/sfh203-fa/photodiode-ir-filtered/dp/1212743

I have tried a few variations but basically I am using the AnalogReadSerial sketch with the photodioide positive going to arduino analog pin 0 and the photodiode negative going to arduino GND - clearly wrong?  I just get a bunch of values the same as if nother is connected.... any pointers would be great  smiley
228  Forum 2005-2010 (read only) / Interfacing / Re: HSM-20G analog temperature/humidity sensor on: October 01, 2010, 03:49:47 pm
Hi Itsthemedication,

Thanks for sharing your work - very much appreciated.  I have now had a go and finally got the sensor working :-)  On my arduino 328 it outputs sensible figures but when I load up onto a 168 the figures are quite a bit out - any idea why this should be?

328             168
52.2 %RH    83.3 %RH
25.4 deg C  36.8 deg C

52.2 %RH    83.3 %RH
25.4 deg C   36.8 deg C

52.4 %RH    83.3 %RH
25.4 deg C   36.8 deg C
                  

        
        

        
        
229  Forum 2005-2010 (read only) / Interfacing / Re: HSM-20G analog temperature/humidity sensor on: February 23, 2010, 06:01:29 pm
Fab again - many thanks.

I think the temp part of the sensor is duff as the value goes from 908 down to 892 when droping from 22C to 0C which is less than 1 degree resolution!!  I guess I'm stuck with just RH with this sensor.... but learnt loads so thanks for your time and knowledge :-)
230  Forum 2005-2010 (read only) / Interfacing / Re: HSM-20G analog temperature/humidity sensor on: February 23, 2010, 06:57:54 am
Ahhh-ha  I got the temp value to respond by engaging the pullup resitors on that pin - I just need to figure the formula out now as dividing the analogread value by 50 is clearly wrong !!!
231  Forum 2005-2010 (read only) / Interfacing / Re: HSM-20G analog temperature/humidity sensor on: February 23, 2010, 04:43:53 am
Hi ArduinoM,

Thanks for posting - I just learned a whole lot about excel and arduino :-).

Got RH working well with the code below based on a linear trendline (to make the maths easy) and the data provided in the data sheet.  Now for some reason I don't understand the temperture outputs on the data sheet are given in ohms and the output from arduino is showing 1023 which is presumably 60C or higher...?  One thing is for sure - it's cold and wet here today.... any ideas?

Code:
int tempsense = 0;
int rhsense = 0;
int temp = 0;
int rh = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
 
 tempsense = (analogRead(1));
 rhsense = (analogRead(2));
 temp = (tempsense/50);
 rh = ((30.855*(rhsense/204.6))-11.504);
 
 Serial.print("Temperature: ");
 Serial.print(temp);
 Serial.println(" C ");
 
 delay(100);
 Serial.print("Humidity: ");
 Serial.print(rh);
 Serial.println("% ");
                                            
 delay(1000);
}
232  Forum 2005-2010 (read only) / Interfacing / HSM-20G analog temperature/humidity sensor on: February 22, 2010, 04:57:02 pm
Hi,

I recently bought one of these: http://www.seeedstudio.com/depot/humidity-temperature-sensor-module-p-75.html?cPath=6 expecting that I would be able to work it out from the data sheet once I had it in my hands :-)

Looks like I'm wrong - I'm simply trying display the output in degrees C and %RH but I can't find the relevant info on how to convert the numbers.

Has anyone else had success with this sensor?

Cheers.
233  Forum 2005-2010 (read only) / Interfacing / Re: Sensitron SHT15 and SHT75, what is the difference? on: June 23, 2010, 04:40:54 am
I think its more than just size :-)  Energy consumption is much lower for sure.

This is what they say:

SHT21, the new humidity and temperature sensor of
Sensirion is about to set new standards in terms of size
and intelligence: Embedded in a reflow solderable Dual
Flat No leads (DFN) package of 3 x 3mm foot print and
1.1mm height it provides calibrated, linearized signals in
digital, true I2C format.
With a completely new designed CMOSens® chip, a
reworked capacitive type humidity sensor and an
improved band gap temperature sensor the performance
has been lifted even beyond the outstanding level of the
previous sensor generation (SHT1x and SHT7x). For
example, measures have been taken to stabilize the
behavior at high humidity levels.
Every sensor is individually calibrated and tested. Lot
identification is printed on the sensor and an electronic
identification code is stored on the chip – which can be
read out by command. Furthermore, the resolution of
SHT21 can be changed by command (8/12bit up to
12/14bit for RH/T), low battery can be detected and a
checksum helps to improve communication reliability.
With made improvements and the miniaturization of the
sensor the performance-to-price ratio has been improved
– and eventually, any device should benefit from the
cutting edge energy saving operation mode. For testing
SHT21 a new evaluation Kit EK-H4 is available.

SHT15
Energy consumption: 80uW (at 12bit, 3V, 1 measurement / s)  
RH operating range: 0 – 100% RH
T operating range: -40 – +125°C (-40 – +257°F)
RH response time: 8 sec (tau63%)
Output: digital (2-wire interface)

SHT21
Energy consumption: 3.2uW (at 8 bit, 1 measurement / s)
RH operating range: 0 – 100% RH
T operating range: -40 – +125°C (-40 – +257°F)
RH response time: 8 sec (tau63%)
Output: I2C digital, PWM and SDM/analog Volt interface
234  Forum 2005-2010 (read only) / Interfacing / Re: Sensitron SHT15 and SHT75, what is the difference? on: June 22, 2010, 03:26:53 am
Looks like the SHT21 will be available here soon: http://misenso.com/2010/05/arduino-humidity-sensor-sht21/  I emailed and was told next week :-)
235  Forum 2005-2010 (read only) / Interfacing / Re: Shield for Tx/Rx RS485? on: June 21, 2010, 12:19:18 pm
Maybe this is worth a look too?

http://www.dfrobot.com/index.php?route=product/product&path=35_39&product_id...
236  Forum 2005-2010 (read only) / Interfacing / Re: Arduino reading Modbus data/RS485. on: June 21, 2010, 11:00:06 am
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#include <ModbusMaster.h>

// instantiate ModbusMaster object as slave ID 1
// defaults to serial port 0 since no port was specified

//  $2010.04.27$ change 2=>1  because device default address is 1; you can change it to your slave address.
ModbusMaster node(1);  

//  $2010.04.27$  code add {{{{{
union uint16_float_convert{
  uint16_t uint16_data[2];
  float    float_data;
}uint_to_float;

unsigned char Time_Is_4Sec_After_Last_Read_From_Device;
float CO2_Measurement;
float Temperature_Measurement;
float Humiture_Measurement;
//  $2010.04.27$  code add }}}}}}}

//-----------------------$2010.06.10$ code add---------------------------
uint32_t counter_at_least_4s;
//---------------------------------------------------------------------------

void setup()
{
 // initialize serial communications at 9600 bps:
  Serial.begin(9600);

  //  $2010.04.27$  code add {{{{{
  Time_Is_4Sec_After_Last_Read_From_Device=0;  
  CO2_Measurement=0;
  Temperature_Measurement=0;
  Humiture_Measurement=0;
  //  $2010.04.27$  code add }}}}}}}
  
  //-----------------------$2010.06.10$ code add---------------------------
  counter_at_least_4s=0;
  //---------------------------------------------------------------------------
  
   // initialize Modbus communication baud rate
  node.begin(19200);
  
  //-------------------------$2010.06.10$ code add{{{{{{-----------------------------------
  //TODO:initialize a timer at here ,use the timer to generate a 4 second timing cycle in the timer's interrupt handle function.
  //initialize timer's every control and mode register at here
  //.......

  //$2010.06.10$-2010-06-10-15:44 code add
  //I suppose that your CLKcpu=8MHZ,you should recalculate the timer2 register value according to your real CLKcpu.
  OCR2A=70;                        //set timer2 interrupt cycle to 70*4US=280US
  TCCR2A=0x0b;                     //Timer mode 8M  Clock Division Factor=32��CS21=CS20=1�� CTC      
  TIMSK2=2;                       //Enable timer2 CTC interrupt

  sei();
  //-------------------------$2010.06.10$ code add}}}}}} ------------------------------------
  
}

//-------------------------------$2010.06.10$ code add{{{{{{-------------------------------------
 //use the timer to generate a 4 second timing cycle in the timer's interrupt handle function.
 //i have no idea on which timer you may use. so i suppose timer2 is used.
 //i don't know how long each timer interrupt you will set. so you should calculate the value of TIMING_CYCLE_4S by yourself.
 //the method of calculating the value of TIMING_CYCLE_4S : ((4Second)/(each timer interrupt cycle)+1)
#define TIMING_CYCLE_4S    (28000)     //$2010.06.10$-2010-06-10-15:44 code add

ISR(TIMER2_COMPA_vect) {
  //at here, you may count to generate  at least 4 second timing cycle.
  counter_at_least_4s++;
  if(counter_at_least_4s>=TIMING_CYCLE_4S)
  {
      counter_at_least_4s=0;
      Time_Is_4Sec_After_Last_Read_From_Device=1;
  }
};
//---------------------------------$2010.06.10$ code add}}}}}}  ------------------------------------------

void loop()
{
  static uint32_t i;
  uint8_t j, result;
  uint16_t data[6];
  
  i++;
  /*   //$2010.04.27$  deleted. i suppose you will only read the device data.
  // set word 0 of TX buffer to least-significant word of counter (bits 15..0)
  node.setTransmitBuffer(0, lowWord(i));
  
  // set word 1 of TX buffer to most-significant word of counter (bits 31..16)
  node.setTransmitBuffer(1, highWord(i));
  
  // slave: write TX buffer to (2) 16-bit registers starting at register 0
  result = node.writeMultipleRegisters(0, 2);
  
  // slave: read (6) 16-bit registers starting at register 2 to RX buffer
  result = node.readHoldingRegisters(2, 6);
  */
  
 // $2010.04.27$  added. for read the CO2 , Temperature and Humiture measurement data from device.
 // !!!!NOTE!!!!: the interval time between twice reading from device must be at least 4 seconds,
 //               Too little interval time between twice reading will probably do damage to device!!!
 //Time_Is_4Sec_After_Last_Read_From_Device  is a flag ,mcu can set it to 1 in a timer when 4 seconds has reached.  
 if(1==Time_Is_4Sec_After_Last_Read_From_Device)    
 {  
     Time_Is_4Sec_After_Last_Read_From_Device=0;  //only after 4 seconds , mcu can again run to here and read device .
     //slave: read (6) 16-bit registers starting at register 0 to RX buffer
     result=node.readInputRegisters(0,6);
     if (result == node.ku8MBSuccess)
     {
        for (j = 0; j < 6; j++)
        {
            data[j] = node.getResponseBuffer(j);
        }
        //for example: compiler is gcc ,Big-endian
        //the device sends datas :0x41 0x7C 0x33 0x30 ....., the 0x41 is sent at first.
        //the ModbusMaster Class will return datas to variable data[], then data[0]=0x417C ,data[1]=0x3330  ,they are CO2 measurement=24.899994
        //in union uint16_float_convert , gcc  sets uint16_data[1] at higher address and uint16_data[0] at lower address .
        //float value 24.899994 ,in memory, gcc saves it as 0x417C 0x3330 ,0x417C is at higher address , 0x3330 is at lower address.  
        //so the code will be like this:
        //uint_to_float.uint16_data[0]=data[1];
        //uint_to_float.uint16_data[1]=data[0];
        
        //data[0] data[1]   :CO2 measurement, float type.
        //data[2] data[3]   :Temperature measurement, float type.
        //data[4] data[5]   :Humiture measurement, float type.  
        
        //decode the readed data,and get CO2 measurement
        uint_to_float.uint16_data[0]=data[1];
        uint_to_float.uint16_data[1]=data[0];
        //The readed CO2 measurement from device is put into CO2_Measurement .
        CO2_Measurement=uint_to_float.float_data;
        
        //decode the readed data,and get Temperature measurement
        uint_to_float.uint16_data[0]=data[3];
        uint_to_float.uint16_data[1]=data[2];
        //The readed Temperature measurement from device is put into Temperature_Measurement .
        Temperature_Measurement=uint_to_float.float_data;
        
        //decode the readed data,and get Humiture measurement
        uint_to_float.uint16_data[0]=data[5];
        uint_to_float.uint16_data[1]=data[4];
        //The readed Humiture measurement from device is put into Humiture_Measurement .
        Humiture_Measurement=uint_to_float.float_data;
        
        //now you can use CO2_Measurement, Temperature_Measurement and Humiture_Measurement to deal with the other task.
        
    
     lcd.setCursor(0, 0);
     lcd.print("Temp     : ");
     lcd.print(Temperature_Measurement);
     lcd.setCursor(0, 1);
     lcd.print("Humidity : ");
     lcd.print(Humiture_Measurement);
     lcd.setCursor(0, 0);

  }
}
237  Forum 2005-2010 (read only) / Interfacing / Arduino reading Modbus data/RS485. on: June 21, 2010, 10:55:31 am
Hi,

I have been trying for a while now to get this code working but now really stuck.... any helping hand much appreciated :-)

The sensor is sending information automatically every 3 seconds via Modbus - I am trying to use the shield below to recieve the data and print it out via an LCD.  At the moment I am getting 0.00 values for all three outputs: CO2, temp & RH.  I have had help with the code and it is quite well documented by I'm no programmer and there apears to be a risk of damaging the sensor if I do something wrong... so far it is still working :-)

The shield is: http://www.dfrobot.com/index.php?route=product/product&path=35_39&product_id=54

The rest of the code is on the next post as it wouldn't fit here.

Code:
//-----------------------$2010.06.10$-2010-06-10-15:44 code add-----------------------------------------
// i have initialize the timer2 interrupt for you ,but i suppose that your CLKcpu is 8M.
//so you should recalculate the timer2 register value and the value of TIMING_CYCLE_4S.
//you must guarantee that the timer2 interrupt cycle is at least 4 second.
//you can find the code of initializing the timer2 by finding the string  "$2010.06.10$-2010-06-10-15:44"

// ------------------------$2010.06.10$ is the flag of changed code.--------------------------------------
//At First,read the following context,please.
// Pay attention to the variable "Time_Is_4Sec_After_Last_Read_From_Device"  in the process "loop".
//the process "loop" will not run to read the device ,until "Time_Is_4Sec_After_Last_Read_From_Device" is set to 1.
// !!!!NOTE!!!!: the interval time between twice reading from device must be at least 4 seconds
//So "Time_Is_4Sec_After_Last_Read_From_Device" can not be always setting to 1;

//you should do:
//1.setup a timer,use the timer to generate a 4 second timing cycle.
//2.only when 4 second timing cycle is reached ,you set the "Time_Is_4Sec_After_Last_Read_From_Device" to 1.

//in the process "loop",mcu will find the "Time_Is_4Sec_After_Last_Read_From_Device"==1,
//then mcu set "Time_Is_4Sec_After_Last_Read_From_Device" to  0, and run to read the device.
//the next 4 second timing cycle will lead to the next read from device.
//---------------------------------------------------------------------------------------------------------------------

//-------------------------$2010.04.27$   is a flag of changed code. you can search the flag to find the changed code. -----------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------
/*
  Basic.pde - example using ModbusMaster library
  This file is part of ModbusMaster.
  ModbusMaster is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  
  ModbusMaster is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with ModbusMaster.  If not, see <http://www.gnu.org/licenses/>.
  
  Written by Doc Walker (Rx)
  Copyright ?2009, 2010 Doc Walker <dfwmountaineers at gmail dot com>
  $Id: Basic.pde 39 2010-02-10 02:12:21Z dfwmountaineers $
  
*/

Thanks.

238  Forum 2005-2010 (read only) / Interfacing / Re: IR photodiode to read LED pulse from meter? on: June 11, 2010, 04:35:58 am
Hi,

It's WORKING :-)  I now understand a little bit more thanks to the kind help of you good folk and the logger is recording our power usage as I type.

One of the problems I was having turned out to be the power supply - I was running the Stalker off the Seeedstudio Solar Sheild with LiPo battery - this casued the sensor to flicker on and off very quickly.  Swapping to a 9V battery straight in to the Stalker has solved this, I guess it must be noise of some kind?  Not sure if I can solve this - the solar shield is very neat - ideal for a data logging application.

Cheers.

239  Forum 2005-2010 (read only) / Interfacing / Re: IR photodiode to read LED pulse from meter? on: June 10, 2010, 10:51:32 am
HeHe.... yeah, this is a UK torch..... we would call a US Torch a Blow Torch or Blow Lamp.... that mean anything in the States? :-)

OK.... with your kind help I now have the sketch below successfully picking up the LED pulse, albeit with a different sensor :-)

I think the last hurdle to jump is amalgamating this test sketch with the original and I should be there?  CRS8291 has his sensor on Digital Pin 3 but I cannot see how its done?

The IR sensor is connected to digital pin 3 and is declared in the attachInterrupt statement:

  
Code:
attachInterrupt(1, wattSensorInterrupt, FALLING);  //interrupt1 - digital pin 3 - If we detect a change from HIGH to LOW we call wattSensorInterrupt

My working test code is below, I have the sensor on analog pin 1 with a threshold value.... how would I transpose this into the Stalker code? (shown right at the bottom).

Sorry, I am slowly learning with much help :-)  it is certainly appreciated.


Working code for sensor on analog pin 1

Code:
int ledPin =  13;    // LED connected to digital pin 13
int sensorPin = 1;   // SFH203FA connected to analog pin 1
int sensorState = 0;

// The setup() method runs once, when the sketch starts

void setup()   {                
  // initialize the digital pin as an output:
  pinMode(ledPin, OUTPUT);
  pinMode(sensorPin, INPUT);
 Serial.begin(9600);
}

// the loop() method runs over and over again,
// as long as the Arduino has power


void loop(){
  // read the state of the sensor value:
  sensorState = analogRead(sensorPin);

  // check if the sensor is receiving IR.
  // if it is, the ledState is HIGH - have guessed a theshhold value of 100?
  if (sensorState > 100) {    
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
  Serial.println(sensorState);
}


CRS8291's Stalker code using sensor on digital pin 3:

Code:
//Meter reading program using Itron smart meter
//Added LED that turns on/off with each watt

#include "FileLogger.h" // http://code.google.com/p/arduino-filelogger/
#include <Time.h>  
#include <Wire.h>  
#include <DS1307RTC.h> // a basic DS1307 library - http://www.arduino.cc/playground/Code/Time

const int ledPin = 14; // LED watt indicator initialization. Turns on or off each time a watt is measured
int ledState = LOW;

volatile unsigned long wattSensor=0;  //Counts power pulses in interrupt, 1 pulse = 1 watt
unsigned long wattSensorTemp=0;  //Temporary power pulse counts for printing - watts
unsigned long totalWatts=0; //Temporary total power used for printing - watts

byte start[7]= {
  'B','e','g','i','n',0x0D,0x0A};
byte Buffer[31]; //Buffer for printing to SD card
time_t oldtime=0; //last time loop has ran
int result; //status of SD card write - 0 = "OK", 1 = "Fail initializing", 2 = "Fail appending"
unsigned long loggingRate=5; //logging rate in seconds
int length; //length of buffer string

void setup(void)
{
  pinMode(ledPin, OUTPUT);  // LED watt indicator initialization
  attachInterrupt(1, wattSensorInterrupt, FALLING);  //interrupt1 - digital pin 3 - If we detect a change from HIGH to LOW we call wattSensorInterrupt

  do
  {
    result = FileLogger::append("data.txt", start, 7);//Initialize the SD Card
  }
  while(result != 0);

  // the next two lines can be removed if the RTC has been set
  //  setTime(17,05,0,1,3,10); // set time to 17:05:00  1 Mar 2010
  //  RTC.set(now());  // set the RTC to the current time (set in the previous line)

  // format for setting time - setTime(hr,min,sec,day,month,yr);

  setSyncProvider(RTC.get);   // the function to get the time from the RTC

  Serial.begin(9600);
}

void loop(void)
{
  time_t t = now();
  //  if(t >= oldtime + loggingRate) //proceed with loop if loggingRate seconds have elapsed
  if( minute(t) != oldtime) //use this if 1 minute intervals is desired
  {
    wattSensorTemp=wattSensor; //number of watts for interval
    wattSensor=0; //reset watts counter
    totalWatts=totalWatts+wattSensorTemp; //total watts counter
    oldtime = minute(t); //use this for one minute interval
    //oldtime = t; //or this for loggingRate interval

    do
    {
      Buffer[0]='A'; //start packet/Site ID
      Buffer[1]=','; //start of data string
      //format of printDigits - printDigits(tempBuffer,bufferPntr,numberDigits)
      printDigits(t,2,10); //t = now()
      Buffer[12]=',';
      printDigits(wattSensorTemp,13,5); //wattSensorTemp
      Buffer[18]=',';
      printDigits(totalWatts,19,8); //totalWatts
      Buffer[27]=',';
      Buffer[28]='>'; //end data packet
      Buffer[29]=0x0D;
      Buffer[30]=0x0A;

      length=sizeof(Buffer);
      result = FileLogger::append("data.txt", Buffer, length);
    }
    while( result != 0);

    for (int i=0; i < length ;i++) {
      Serial.print(Buffer[i]); //Serial print buffer string to serial monitor or xBee
    }
  }
}

void wattSensorInterrupt() //Interrupt1 counter routine for counting watts
{
  wattSensor=wattSensor+1;  //Update number of pulses, 1 pulse = 1 watt
  if (ledState == LOW) //Cycle LED on or off each time one watt is counted
    ledState = HIGH;
  else
    ledState = LOW;
  digitalWrite(ledPin, ledState);
}

void printDigits(unsigned long tempBuffer, int bufferPntr, int numberDigits) //assign data to output array
{
  unsigned long modDivide = 1;
  for (int i = 0; i < numberDigits; i++) {
    Buffer[bufferPntr+numberDigits-1-i]=((tempBuffer%(modDivide*10))/modDivide)+'0';
    modDivide=modDivide*10;
  }
}
 
240  Forum 2005-2010 (read only) / Interfacing / Re: IR photodiode to read LED pulse from meter? on: June 09, 2010, 01:06:30 pm
Ah... that makes all the difference - thanks mike.  Thanks also Richard.

In total darkness I am getting a value of 75 and with a torch on the sesnor I am getting 120 - setting the threshold to 100 produces good results even with a tv remote :-)

Now I need to get it to see an LED pulse from the meter of about 100ms!!  I'm not feeling hopefull as I can't get it to register a full on red LED let alone a small LED with a short pulse?  Perhaps I am barking up the wrong tree with this sensor?... although it does seem to have a very fast response time.  To be honest I'm not sure why an IR sensor is recomended, I expect there is a good reason.

Pages: 1 ... 14 15 [16] 17 18 19