element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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 Help please. Trying to set a timed threshold
  • 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 3 replies
  • Subscribers 402 subscribers
  • Views 245 views
  • Users 0 members are here
Related

Help please. Trying to set a timed threshold

Former Member
Former Member over 13 years ago

Hello, I am trying to have an arduino uno control 2 cameras and ensure that they constantly stay on and constanlty record. I have wired the arduino to internal parts of the camera such as the rec button, the power button, an internal power line and i have setup a LDR to the blinking LED on the camera that flashes when it records. I have had a lot of help with the software and I believe it was working fine; but it has sat in my basement for a few years due to having kids and work, but I am trying to get it back up and running now so I can attach these to a weather balloon this Sunday. I have powered it up but it seems like it is only taking the reading of the blinking LED on the camera for a split second but I would like it to monitor the blinking LED for a few seconds (perhaps anywhere from 5-10) and if the LED does not come on I would then like it to send a signal to the REC Button to record; but like i said it seems to just be taking 1 reading and if it happens to take that reading while the LED is blinking and in the off state it hits the REC button. any help would be GREATLY APPRECIATED. Like I said I don't really know what I'm doing here so if i have left out any information that you may need just let me know. Also I can provide pictures or video or anything you may need or we could even video conference if that makes it easier. Please let me know.

 

// These constants won't change:
const int PWRsensor2 = A2;     // was "analogpin" pin - camera PWR sensor is attached to
const int LDR2 = A3;           // was "analogpin1" pin - LDR
const int PWRled2 = 13;        // was "ledpin" pin - camera PWR button is attached to
const int RECled2 = 9;         // was "ledpin1" pin - camera REC button is attached to
const int PWRsensor1 = A0;     // was "analogpin" pin - camera PWR sensor is attached to
const int LDR1 = A1;           // was "analogpin1" pin - LDR
const int PWRled1 = 12;        // was "ledpin" pin - camera PWR button is attached to
const int RECled1 = 8;         // was "ledpin1" pin - camera REC button is attached to
const int threshold = 400;    // threshold for the Camera PWR
const int ledIsOnLevel = 20;  // threshold for the REC LED
const int blinkTime = 5000;

void startRecording1 ()
{

  Serial.println("                                                 Pressing REC BUTTON on Camera 1");
  digitalWrite(RECled1, HIGH);
  delay(500);
  digitalWrite(RECled1, LOW);
  delay(500);
}
void startRecording2 ()
{

  Serial.println("                                                 Pressing REC BUTTON on Camera 2");
  digitalWrite(RECled2, HIGH);
  delay(500);
  digitalWrite(RECled2, LOW);
  delay(500);
}

//---------------------------

void setup()
{
  pinMode(PWRled1, OUTPUT);   // init Camera 1 PWR button = output:
  pinMode(RECled1, OUTPUT);   // init Camera 1 REC button = output:
  pinMode(PWRled2, OUTPUT);   // init Camera 2 PWR button = output:
  pinMode(RECled2, OUTPUT);   // init Camera REC 2 button = output:
  Serial.begin(9600);         // init serial comms:
}

void loop()
{ 
  int PWRValue1 = analogRead(PWRsensor1);  // read camera PWR
  int LDRValue1 = analogRead(LDR1);        // read LDR LED
  int PWRValue2 = analogRead(PWRsensor2);  // read camera PWR
  int LDRValue2 = analogRead(LDR2);        // read LDR LED
  // if the analog value is too low, "Press" the PWR button:

  Serial.println("                         Power Reading Camera 1");
  Serial.println(PWRValue1);
  Serial.println("                         Power Reading Camera 2");
  Serial.println(PWRValue2);
  Serial.println("LDR Reading Camera 1");
  Serial.println(LDRValue1, DEC);
  Serial.println("LDR Reading Camera 2");
  Serial.println(LDRValue2, DEC);
  delay(500);

  // if the analog value is too low, "Press" the PWR button:
  if (PWRValue1 < threshold)
  {
    Serial.println("Pressing PWR on Camera 1 in 2 secs; then delay for 5 secs");
    delay(2000);
    digitalWrite(PWRled1, HIGH);
    delay(500);
    digitalWrite(PWRled1, LOW);
    delay(5000);
    Serial.println("Resuming");

  }
  else
  {
    digitalWrite(PWRled1,LOW);
  }


  if (PWRValue2 < threshold)
  {
    Serial.println("Pressing PWR on Camera 2 in 2 secs; then delay for 5 secs");
    delay(2000);
    digitalWrite(PWRled2, HIGH);
    delay(500);
    digitalWrite(PWRled2, LOW);
    delay(5000);
    Serial.println("Resuming");

  }
  else
  {
    digitalWrite(PWRled2,LOW);


  }

  // if the analog value is too low for 3 seconds on Camera 1, "Press" the REC button:
  bool recording1 = false;
  unsigned long blinkStart = millis();
  while(millis() - blinkStart < blinkTime)
  {
    if(analogRead(LDR1) > ledIsOnLevel)

    {
      recording1 = true;
      Serial.println("                                                  Camera 1 is RECORDING");
      break;
    }
  }

  if(!recording1)
  {
    Serial.println("                                                 Camera 1 is  NOT RECORDING");                                  // r_p    
    startRecording1();
  }

 

 

  // if the analog value is too low for 3 seconds on Camera 1, "Press" the REC button:
  bool recording2 = false;

  while(millis() - blinkStart < blinkTime)
  {
    if(analogRead(LDR2) > ledIsOnLevel)

    {
      recording2 = true;
      Serial.println("                                             Camera 2 is RECORDING");
      break;
    }
  }

  if(!recording2)
  {
    Serial.println("                                                 Camera 2 is NOT RECORDING");                                   // r_p    
    startRecording2();     
    // print the analog value:
  }                                 // r_p

  Serial.println("End of Loop");
}


  • Sign in to reply
  • Cancel
Parents
  • chgus
    0 chgus over 13 years ago

    Hm. I would probably let the ldr drive a transistor and a RC timing circuit. Lets say it blink every second, set the RC timing to 3-5 seconds.

     

    image

    Every time it blinks, it will discharge the electrolytic Capacitor C. So You would read a "LOW" while it blinks, but after a few seconds of not blinking it would become "HIGH".

    My schematic is conceptual, You might need to add to it depending on Your choice of components.

     

    R=2.2k and C=22uF would result in approx 5S timing. Typical choice for the transistor would be BC548CGBC548CG or equivalent.

     

    You might also replace the LDR+Transistor with a Photo Transistor.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 13 years ago in reply to chgus

    I like the shadows aroung the device symbols on your illustration.  What application does that?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • billabott
    0 billabott over 13 years ago in reply to chgus

    I like the shadows aroung the device symbols on your illustration.  What application does that?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • chgus
    0 chgus over 13 years ago in reply to billabott

    OmniGraffle, There are several Omni* products.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
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