Measuring Frequency of a sensor in a Wheatstone bridge

I am doing a project and setup a wheatstone bridge with a photoresistor as on of the sensors for the bridge. I cant figure out a code to measure the frequency of a light flashing on and off on the photoresistor. I currently have the Voltage input on the A4 pin on the Arduino nano.

This is the circuit:

Post the code you are working with (using code tags "</>" editor button), and explain what should happen, and what happens instead.

float floatmap(float x, float in_min, float in_max, float out_min, float out_max) {
return (x- in_min)*(out_max - out_min)/(in_max - in_min) + out_min;
}

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(0, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
float analogValue = analogRead(A4);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = map(analogValue, 0, 1023, 0, 5);
analogWrite(0, voltage);

// print out the value you read:
Serial.println("Analog: ");
Serial.print(analogValue);
Serial.print(" Voltage: ");
Serial.print(voltage);
}

this code only measures voltage.
I am having trouble coming up with a code instead of voltage it is frequency that is measured.

Your circuit is wrong, you short one branch of bridge with yellow jumper, you need separate battery for bridge, what frequency you are talking about, this is DC or AC bridge ?

This is an AC bridge, plus if i run the code that i have now it works perfectly fine. It just gives me the reading in bits due to the analog. The Yellow jumper is needed for the plotter to read due to being connected to ground.

To measure frequency, you need to measure the time between points where the value of the waveform repeats. Or, you can count repeats during a given time period.

Google "arduino frequency measurement" for some ideas.

1 Like

Thanks

It is not clear, on the picture you have left side of the bridge connected to +5V and right side to ground = DC supply to the bridge = DC bridge. Resistor under photoresistor - left side through yellow jumper to ground, right side trough orange jumper also to ground = that is a miracle that the bridge is working.
Bridges also need to be balanced ......

======================
your circuit is working as a voltage divider not as a bridge, two resistors on the bottom are useless

if you are using for light source incandescent light bulb the frequency is 50 or 60 Hz. Connect oscilloscope to A4.

You can’t use float in the map function, only integers .
You should use integers throughout , you can’t write a float to analog , it will only set part of the number if it works at all .

Bear in mind a LDR has a limited frequency response

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