My projects is all about tracking a red laser beam. The LDR looks to be adequate. I really need the many Boolean inputs from the Mega 2650 board, but the LDRs are analogue only. There might be a little module, complete with a trigger for a yes/no signal. Any thoughts? For example, with another project I was using a Hall detector. This guy came with a little module generating a Boolean output.
A couple of possibilities.
Use an analog input to read the value and compare it with a reference. Use the result to set a boolean.
boolean readSensor(int pin, int reference=511) { // default to half scale on UNO
value = analogRead(pin);
return ( (value > reference) ? true:false);
};
Alternatively use a hardware comparator to generate a digital output. If you need multiple something like this. Dual and single versions are also available.
You can replace the Rref/R1 combination in figures 2 & 3 with a pot if you need adjustment. There are probably modules that already do this available.
A digital pin will go from LOW to HIGH when the pin V hits close to 2/3 of VCC (2.8V on most Unos, forum member tested) and drop from HIGH to LOW at 1.1V or maybe under 1.1V.
It's digital about what you get but it is entirely about pin voltage!
You can tune your Input circuits with voltage dividers.
LDR's are slow, a phototransistor will make a faster, stronger response.
They are pretty cheap by the bag. The IR version has a black bulb to block out visible light, but red leds put out IR that IR detectors can sense.
The speed difference is like oxcart LDR to bullet PT.
I have a laser on a huge compass needle. I have a radius of fifteen feet. Is magnetic north moving? Speed and even sensitivity do not seem to be issues. My preliminary data indicates that I need a broad range. And high precision, at least for now, is not critical. I need the 54 digital I/O pins from the Mega 2560. That is the constraint. I understand what you mean by “it is entirely about pin voltage”. I suspect that the LDR will not give a voltage high enough to be Boolean HIGH. I just found module LM393. One module for each LDR? Maybe. Maybe there are tricks with resistors to bring the LDR output up to the HIGH/LOW range.
Spend a dollar on a bag of photo-transistors. Light switches them on, they are TRANSISTORS, If you give one 5V and laser light on the bulb, you should get 5V out. Not a module, it looks like an led with a clear bulb. Buy 10 or more, the price should be around 10 cents each.
The pole moving... if you are on or close to Nova Scotia then over days you might see a tiny change unless something local is affecting your compass.
The poles have reversed many times in the past and there have not been the mass extinctions that go with the hype. The poles flip, not the planet.
Make a compass sensitive enough, a truck going by will affect it.
You are telling me that tricks with resistors/ voltage dividers should work. cool. The laser beam has a 450 cm radius. I have a scale in minutes, where 60 minutes is a degree. My preliminary data regularly shows ten minute variation (about a centimeter) .... (GitHub - mrphysh/magnetic-north: Is magnetic north constant?)
Makes no sense.
If you connect the LDR between pin and ground, and enable internal pull up with pinmode, then you should be able to detect a boolean LOW when the laser shines on the LDR.
pinMode(ldrPin, INPUT_PULLUP);
Leo..
Yes, it is. Its current pace is about 34 miles per year, or about 15cm per day
I did the math in radians.
pi * radius / ( 180 * 3600 ) gives me arc-second tip to tip.
Is the radius 450 cm to what measure error/tolerance?
Edit Arc-minutes is less insane. I went for mm.
pi * 4500 / ( 180 * 60 ) = 1.31 mm rounded.
“to what measurement tolerance?” Never been asked that before. The 450 might have an error of 10%.
I have been banging around like this all my life. I have never had a peer review. Your mathematical approach was certainly more elegant.
Is your compass inside with low lighting or outside in the sumlight?
in a basement. The light is completely controlled. I know that the LRDs do not respond well to red light, but I think they will be fine. This latest prototype has the laser on the compass needle.
Here is demo code for using a LDR in digital mode with state change detection so that one can perform an action only on the light to dark or dark to light transition (state change). Add hysteresis to avoid chatter around the threshold with a slow moving signal.
// analog input state change detection with hysteresis by groundFungus
const int sensorPin = A0;
const int threshold = 650;
const int hysteresis = 50;
bool SensorState = true;
bool lastSensorState = true;
void setup()
{
Serial.begin(115200);
Serial.println("analog state change example");
Serial.println("hysteresis added");
}
void loop()
{
int sensorReading = analogRead(sensorPin);
if (sensorReading < threshold - hysteresis)
{
SensorState = true;
}
else if (sensorReading > threshold + hysteresis)
{
SensorState = false;
}
if (SensorState != lastSensorState)
{
if (SensorState == true)
{
Serial.println("light on");
// add the count here if you need it.
}
else
{
Serial.println("light off");
}
lastSensorState = SensorState;
}
}
This is more for the OP!
Phototransistors are BJTs that open by light.
Give the collector 5V through 1K ohms and a bright light. emit pin safe 5V.
But why a laser? The beam may be 2-5 mW and though it is focused tightly, it is no straighter than led light.
What beam to want is a narrow set of light beams that can reach a detector, regardless of source. One lamp can serve many detectors as blocked or not. The shadow of the needle doesn't touch the needle but watch for angles or use them.
Have you even seen an old-style vernier caliper?
I
I appreciate your input. But a simple circuit is fine: LDR ; one side 5v -- the other side at ground through a 5k resistor. The signal is pulled off between the resistor and the LDR pin.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.