Go Down

Topic: Problem: TSL235R Light to pulse converter (Read 692 times) previous topic - next topic

sghazi

Hi,

I am using deumilinove ATMega328 i attached this sensor to interrupt 0 to count pulses but when i expose it to high intensity light it causes an abrupt random movement in my servo attached to pin 9, i found that the way servo library is written servos are interrupt driven could that be a problem??? Please somebody help me!!

robtillaart

PLease post your code sofar, so we can see if something is wrong ...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

Some testcode I wrote some time ago
Code: [Select]
/*
*    FILE: demo01.pde
*  AUTHOR: Rob Tillaart
*    DATE: 2011 05 16
*
* PURPOSE: prototype TSL235R monitoring 
*
* Digital Pin layout ARDUINO
* =============================
*  2     IRQ 0    - to TSL235R
*
* PIN 1 - GND
* PIN 2 - VDD - 5V
* PIN 3 - SIGNAL
*
*/

volatile unsigned long cnt = 0;
unsigned long oldcnt = 0;
unsigned long t = 0;
unsigned long last;
unsigned long msec = 0;
unsigned int cf = 1466;  // cf = 10^0.166 * 1000 (figure 1 datasheet)

void irq1()
{
  cnt++;
}

///////////////////////////////////////////////////////////////////
//
// SETUP
//
void setup()
{
  Serial.begin(115200);
  Serial.println("START");
  pinMode(2, INPUT);
  digitalWrite(2, HIGH);
  attachInterrupt(0, irq1, RISING);
}

///////////////////////////////////////////////////////////////////
//
// MAIN LOOP
//
void loop()
{
  msec = millis() - last;
  if (msec >= 1000)
  {
    last += msec;
    t = cnt;
    unsigned long hz = (t - oldcnt) * 1000 / msec;
    oldcnt = t;
    unsigned long mw = (hz * cf/1000 + 50)/100; // +50 == rounding last digit
   
    // smoothing possible...
    Serial.print("FREQ: ");
    Serial.print(hz);
    Serial.print("\t ");
    Serial.print(mw); 
    Serial.println(" mW/m2");
  }
}

// END OF FILE
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Grumpy_Mike

Are you powering the servo from the same source as the arduino. Is it USB?
Most servos take more current than the arduino can supply, most of the time you actually need to power the servos with a separate supply.
Also add some supply decoupling to your sensor.
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

Go Up