Why is my input always High-MEGA BOARD

Please see " Prior wire set up"....not current, later, i will take pic of the set up...

  • Completely wrong, that circuit will always be HIGH.

  • Wire up the LDR as instructed and try this sketch, the one on the left side.

  • you may have to play with the trigger point.


//================================================
#define LEDon              HIGH   //PIN---[220R]---A[LED]K---GND
#define LEDoff             LOW

#define PRESSED            LOW    //+5V---[Internal 50k]---PIN---[Switch]---GND
#define RELEASED           HIGH

#define CLOSED             LOW    //+5V---[Internal 50k]---PIN---[Switch]---GND
#define OPENED             HIGH

#define ENABLED            true
#define DISABLED           false


//                                            G P I O s
//================================================^================================================
//
const byte LDRpin                = A0;
const byte heartbeatLED          = 13;
const byte outputLED             = 12;

//VARIABLES
//================================================
//
int triggerPoint                 = 1000;
int LDRvalue;

//timing stuff
unsigned long  heartbeatTime;
unsigned long  checkSensorTime;


//                                           s e t u p ( )
//================================================^================================================
//
void setup()
{
  Serial.begin(115200);

  LDRvalue = analogRead(LDRpin);

  pinMode(heartbeatLED, OUTPUT);
  pinMode(outputLED, OUTPUT);

} //END of   setup()

//                                           l o o p ( )
//================================================^================================================
//
void loop()
{
  //========================================================================  T I M E R  heartbeatLED
  //is it time to toggle the heartbeat LED ?
  if (millis() - heartbeatTime >= 500ul)
  {
    //restart this TIMER
    heartbeatTime = millis();

    //toggle the heartbeat LED
    digitalWrite(heartbeatLED, digitalRead(heartbeatLED) == HIGH ? LOW : HIGH);
  }

  //========================================================================  T I M E R  checkSensors
  //is it time to scan our sensors ?
  if (millis() - checkSensorTime >= 100ul)
  {
    //restart this TIMER
    checkSensorTime = millis();

    checkSensors();
  }


  //================================================
  //other non blocking code goes here
  //================================================


} //END of   loop()


//                                   c h e c k S e n s o r s ( )
//================================================^================================================
//
void checkSensors()
{ 
  //========================================================================  LDRpin
  LDRvalue = analogRead(LDRpin);
  Serial.println(LDRvalue);

  //========================
  //has the LDR detected light (plus hysteresis) ?
  if (LDRvalue + 5 >= triggerPoint)
  {
    digitalWrite(outputLED, LEDon);
  }

  //========================
  //are we below the trigger point ?
  else if (LDRvalue < triggerPoint)
  {
    digitalWrite(outputLED, LEDoff);
  }


  //========================================================================  nextSensor

} //END of   checkSensors()

@LarryD

Thanks for your input, so for clarification, what was incorrect on the schematic that was posted to leave it on high?

Note, my cousin live two hours away ( not your issue, lol) but at his mercy to come and do this for me, so dont know next time he will be back in my area.....bit, i am willing to try, so asking......

Given the sensor how you stated to wire up....what or where specifically i am doing ...given , i will try it ..who is clueless...

So, given that Mega board above, it if is not too much to explain?

if you can, if not will then need to wait on him.

,
Later when I get home, or tomorrow, as instructed, I will download the provide sketch and upload it into the " the Arduino IDE " program.

  • Sometimes it is good practice to redraw a schematic to visualize problems.

  • I am sure you can see from the schematic below, 5V is always connected to the Arduino pin, hence, that pin will always read HIGH.

image

In your situation the input pin will be changed to A0 (analog), not D48 (digital).

  • As mentioned, you may have to change the trigger threshold to match your LDR.

  • The voltage divider 10k resistor may need to be changed in value for operation with your LDR.

  • Use the last schematic offered you in Post #22, I have incorporated a heartbeat LED and an output LED for visual effect.

3 Likes

Got it, okay, will keep you posted here on his input and our attempted to get this to work( not sure when, but I will try it later or tomorrow).

Again, appreciate you patience and understanding that i am clueless on the electronic of this all and relaying what was done 2nd hand from someone working in the field and trying to assist me here....

So will keep you posted !

Thanks again to the other suggestions too.

@LarryD

Sorry, we sent an incorrect drawing !

Given he is working and a mistake was made, here is the correct schematic of what we did :

  • Your Mega has Digital pins and Analog pins.

  • An LDR is a component that should be used with an analog pin.

  • An ON/OFF switch is used with a Digital switch.

  • Your LDR can be used with a Digital pin with the help of a voltage comparator circuit.

IMG_3279

  • For your Digital pins, hardware in the Mega look at the pin voltage and determine if this voltage is a HIGH or LOW.

  • A HIGH is a voltage > 3V i.e. VIH.

  • A LOW is a voltage < 1.5v i.e. VIL.

  • When the voltage on the pin is >= 3V, the Arduino says the pin is a HIGH, that’s what is happening with your pin.

  • You must use an Analog pin with your LDR voltage divider circuit.

2 Likes

Isn't there a Schmitt trigger in the digital system so a >3V input could need to go considerably lower than 3V before it would flip to logic low?

2 Likes
  • Well, .6Vcc is a HIGH, but I’m not going to quibble. :older_man:

  • Well, .3Vcc is a LOW, but I’m not going to quibble. :older_man:

  • The point being, an analog voltage really has no place on a Digital pin.

A lot here, okay, will present this to him.

What I am getting from this is

  1. I will try that sketch you provider

  2. An LDR is a component that should be used with an analog pin.

  3. if using an Digital pin, 46,47,48,etc.....my LDR should be used with voltage comparator circuit.

  4. Circuit noted that you provide

BTW, I am doing the same steps as this video, not to bore you, but from time stamp 15 min to 17:30, he is using a LDR and went into the digtal side of the board on pin 48....LOL, he made it so easy.....

Again, no idea what he is doing in the background, but i am sure you know a lot of ppl like to keep things secret and then pretend it is easy...1..2..3..

and i assume it is. The poster on the video claim he is a non-tech guy ,,...just playing around with a software that he got to work, hence i tried the same approach, Mega board....and this is a monumental task.....all that you stated above, from what i see, he is doing something totally different and i am using the same software, same sensors, etc....

https://www.youtube.com/watch?v=E0meGf5eS2M&t=1214s

But, i guess, nothing is easy.

thanks again

These aren't LDRs:

From that video, it looks like he is hooking a two terminal LED-like sensor (phototransistor?) directly to a ground and Mega pin 48.

Right, prior to switching to the current LDR that i am using now, i tried these, phototransistor, same issue. Actually, i tried three types.

Stuck with, or kept the LDRs because i didnt need something called a gantry and i could used the room lights .

Was just pointing out the process.

What i am using now, think i got them from Mouser Electronics..... eitherway, will give it a try what you suggested.

https://www.amazon.com/gp/product/B0D21X1SX8/ref=ox_sc_act_title_4?smid=A2183UWDBUMPG&th=1

IMG_3279

  • Suggest a better OP Amp i.e. LMV358, or the voltage comparator i.e. LM339

  • Measure the resistance of your LDR in darkness, then in full light.

  • From the video those are not LDRs (Light dependant resistors).

  • They could be an IR LED/Detector pair.

image

  • Due to the lack of a proper schematic, proper component identification, circuit images, this volunteer has left.
1 Like

@LarryD

Given he live 2 hours away from me, this is what he had me do to get it to work


He suggested to " me " that i am getting caught up on sensors and that from " his " electronic perspective, that is not the issue, the sensors ( regardless if LDR, phototransistors, etc).

What he was stating like yourself and others is the High, low, High.

From my first post, he is stating we need to address why when assigned, the board is showing high!

So what he had me do is on pin 48 , i placed a 10k resistor in, the other end he had me ground it.
then he had me place a 5k6 resistor in the same 48 pin, he then had me go from that 5k6 to a 5v, showing like 1.3 v. he then had me assigned the wire coming off the sensor to Start Lane 1 in the program, then I connected that sensor wire to other end of 5k6 r vs leaving it on the 5v.

Once i did that, the light on the board went from green to red.

Did the same for pin 44 , Finish Lane 1.

Once i did that it worked, data ( reaction time &ET ) showed up.

I asked him what specifically was the issues, he stated we had to assigned the program to go from low to high, etc ...and that the end result is we assigned a pull down resistor to get it to work.

we stuck with the original sensors , phototransistor, not the LDR ones.

hopefully i captured all he said.

I sincerely appreciate all the input.

Thanks.
Mike

Once i wire up the other lane will report back.

Good you got it going! Thanks for reporting back.

The phototransistors are better anyway, since ldrs can be pretty slow. And with your application that would not be good.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.