element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Sensor Interference
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 12 replies
  • Subscribers 391 subscribers
  • Views 922 views
  • Users 0 members are here
Related

Sensor Interference

aureta
aureta over 10 years ago

Hi, I am working with TSL235 light to frequency converter sensors using an Arduino MEGA ADK. When working with one sensor at a time there is no problem with sensing. When two sensors are simultaneously connected they interfere with each other. How can i fix this problem ?, I am attaching the code being used for the simultaneous reading of two TSL235 sensors. Regards. Alejandro.

 

 

# define TSL235Two 21 // Out of TSL235 connected to Digital pin 21

# define TSL235One 3 // Out of TSL237 connected to Digital pin 3

 

 

int period = 101; // Miliseconds of each light frecuency measurement

 

 

unsigned long counterTwo = 0; // Counter of measurements during the test

unsigned long counterOne = 0; // Counter of measurements during the test

 

 

unsigned long currentTime = millis();

unsigned long startTime = currentTime;

 

 

volatile long pulsesTwo = 0; // Counter of measurements of the TSL235R

volatile long pulsesOne = 0; // Counter of measurements of the TSL235R

 

 

unsigned long frequencyTwo; // Read the frequency from the digital pin (pulses/second)

unsigned long frequencyOne; // Read the frequency from the digital pin (pulses/second)

 

 

 

 

void setup()

{

 

 

  Serial.begin(115200); // Start and configure the serial port

  attachInterrupt(2, PulseCountTwo, RISING);

  attachInterrupt(1, PulseCountOne, RISING);

  pinMode(TSL235Two, INPUT); // Declare the pin such as an input of data

  pinMode(TSL235One, INPUT); // Declare the pin such as an input of data

  setup_parallax();

}

 

 

void loop()

{

 

 

counterTwo++; // Increase the number of measurement

counterOne++; // Increase the number of measurement

getfrequencyTwo(); // Request to measure the frequency

getfrequencyOne(); // Request to measure the frequency

pulsesTwo = 0; // reset the pulses counter                                      

pulsesOne = 0; // reset the pulses counter

parallax_output();

                  

}

 

 

 

 

void PulseCountTwo()

{

pulsesTwo++;

}

 

 

void PulseCountOne()

{

pulsesOne++;

}

 

 

 

 

void parallax_output()

{

   

    Serial.print("DATA,DATE,TIME,");

    Serial.print(frequencyTwo); Serial.print(","); Serial.println(frequencyOne);

   

}

 

 

void setup_parallax()

{

   Serial.println("LABEL,Date,Time,Frequency Two, Frequency One");

}

 

 

 

 

unsigned long getfrequencyOne ()

{

noInterrupts();

frequencyOne = pulsesOne *1000 / period; // Calculate the frequency (pulses/second)

interrupts();

return (frequencyOne);

}

 

 

 

 

unsigned long getfrequencyTwo ()

{

noInterrupts();

frequencyTwo = pulsesTwo *1000 / period; // Calculate the frequency (pulses/second)

interrupts();

return (frequencyTwo);

}

  • Sign in to reply
  • Cancel
Parents
  • neilk
    0 neilk over 10 years ago

    aureta Hi Alejandro

     

    I've been out of town for a few days, so I've only just looked at this problem again.

     

    I can now see one significant problem with your code - but this probably doesn't affect the interference image

     

    You define:

     

    int period = 101; // Miliseconds of each light frecuency measurement

     

    And then use it to calculate your pulse fequency:

     

    frequencyOne = pulsesOne *1000 / period; // Calculate the frequency (pulses/second)

     

    However, your main program loop runs "free" ie it is not controlled so that it executes:

     

    getfrequencyTwo(); // Request to measure the frequency

    getfrequencyOne(); // Request to measure the frequency

     

    at intervals of "period", ie 101 mS ! This means that your sampling period is actually quite short - basically, the execution time of the loop image

     

    have you looked at this:

     

    http://playground.arduino.cc/Main/TSL235R

     

    This uses a call to the millis() function every time the main loop is executed. This controls the pulse reading period.

     

    Another observation is that perhaps the overall light level to which you are exposing the sensors is too high. The frequencies reported in your post #7 are quite high, considering the short (and unknown) sampling period you are ACTUALLY using.

     

    Hope this helps

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • neilk
    0 neilk over 10 years ago

    aureta Hi Alejandro

     

    I've been out of town for a few days, so I've only just looked at this problem again.

     

    I can now see one significant problem with your code - but this probably doesn't affect the interference image

     

    You define:

     

    int period = 101; // Miliseconds of each light frecuency measurement

     

    And then use it to calculate your pulse fequency:

     

    frequencyOne = pulsesOne *1000 / period; // Calculate the frequency (pulses/second)

     

    However, your main program loop runs "free" ie it is not controlled so that it executes:

     

    getfrequencyTwo(); // Request to measure the frequency

    getfrequencyOne(); // Request to measure the frequency

     

    at intervals of "period", ie 101 mS ! This means that your sampling period is actually quite short - basically, the execution time of the loop image

     

    have you looked at this:

     

    http://playground.arduino.cc/Main/TSL235R

     

    This uses a call to the millis() function every time the main loop is executed. This controls the pulse reading period.

     

    Another observation is that perhaps the overall light level to which you are exposing the sensors is too high. The frequencies reported in your post #7 are quite high, considering the short (and unknown) sampling period you are ACTUALLY using.

     

    Hope this helps

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube