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 909 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
  • clem57
    0 clem57 over 10 years ago

    When working with interrupts (more than 1) you need to be very careful to masking them. When one comes in while masked, you will loose it. I see you start the two almost same time. Good chance they will interrupt nearly same time. When you handle one, the other is masked off. I suggest you put a small delay between enabling them.

    Clem

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

    Hi Clem, where at the code should I do this and how?

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

    Your processor is running at 8 or 16Mhz and these sensors output at 200-300 Hz (250 ave):

     

    void loop()

    {

    counterTwo++; // Increase the number of measurement

    counterOne++; // Increase the number of measurement

    getfrequencyTwo(); // Request to measure the frequency

    delay(.000025);     // delay for measurements between the two for 1/250/16

    getfrequencyOne(); // Request to measure the frequency

    pulsesTwo = 0; // reset the pulses counter                                      

    pulsesOne = 0; // reset the pulses counter

    parallax_output();

    }                 

     

    Try this and let me know. This is an estimate and may need adjusting.

    Clem

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

    Hi Clem, I did try. there still interference, I include a snapshot of the SM. Under the same light conditions, when the sketch starts there is a high count number from sensor at  timer 2 (read before delay), not the results shown by the other one (right column). After a while I obstruct the sensor plugged at timer 1 without any significant change in the output from either one of these.  I then obstruct the sensor plugged at timer 2, this time the readings from sensor at timer one drops quite dramatically while the reading from the sensor plugged at timer two increases (?¿). I added a final delay at the loop but it didn´t have any effect. image

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

    Interesting. Would you like to try changing sensor one to a falling signal and leaving sensor two to a rising signal?

    Clem

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

    i was trying just that but the behavior is basically the same...

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

    Need to go back to thinking...

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

    I appreciate very much your help.

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

    I appreciate very much your help.

    • 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