What exactly does pulseIn function do, from a little bit of internet research I found out it counts the duration of high or low cycle in a pulse. To test it I sent a normal pulse
digitalWrite(3, HIGH);
delay(10);
digitalWrite(3, LOW);
delay(10);
from one arduino and just to avoid any timer issues on safer side I used another arduino to read it through
pulse = pulseIn(11, HIGH, 5000);
Serial.println(pulse);
But the serial monitor does not show anything other than "0.00"
What about pulseIn I did not understand or where I am getting it wrong while implementing?
Did you connect the GNDs of the two Arduinos ?
As per me as well as most of the internet, this circuitry should work to find out inductance value of unknown inductor. Circuit as attached in the image below.
with one arduino as
#define pulse_out 9
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(pulse_out, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(pulse_out, HIGH);
delay(10);
digitalWrite(pulse_out, LOW);
delay(10);
}
and another as
/* Main.ino file generated by New Project wizard
*
* Created: Mon Feb 10 2020
* Processor: Arduino Uno
* Compiler: Arduino AVR (Proteus)
*/
// Peripheral Configuration Code (do not edit)
//---CONFIG_BEGIN---
#pragma GCC push_options
#pragma GCC optimize ("Os")
#include <core.h> // Required by cpu
#include <cpu.h>
#include <TimerOne.h>
#pragma GCC pop_options
// Peripheral Constructors
CPU &cpu = Cpu;
TimerOne &timer1 = Timer1;
void peripheral_setup () {
}
void peripheral_loop() {
}
//---CONFIG_END---
double pulse, frequency, capacitance, inductance, pul;
void setup () {
peripheral_setup();
// TODO: put your setup code here, to run once:
Serial.begin(9600);
pinMode(11, INPUT);
delay(200);
}
void loop() {
peripheral_loop();
// TODO: put your main code here, to run repeatedly:
pulse = pulseIn(11, HIGH, 5000);
Serial.println(pulse);
if (pulse > 0.001) { //if a timeout did not occur and it took a reading:
// #error insert your used capacitance value here. Currently using 2uF. Delete this line after that
capacitance = 2.E-6; // - insert value here
frequency = 1.E6 / (2 * pulse);
inductance = 1. / (capacitance * frequency * frequency * 4.*3.14159 * 3.14159); //one of my profs told me just do squares like this
inductance *= 1E6; //note that this is the same as saying inductance = inductance*1E6
//Serial print
Serial.print("High for uS:");
Serial.print( pulse );
Serial.print("\tfrequency Hz:");
Serial.print( frequency );
Serial.print("\tinductance uH:");
Serial.println( inductance );
delay(10);
}
}
but it isnt working as expected. the serial monitor gives output as "0.00" everytime.
Where am I getting it wrong?
@UKHeliBob
No, I did not connect the ground of two arduinos. Should I?
And how will it matter, since both are working independently powered through two different laptops, one is sending a wave another one is reading it.
No, I did not connect the ground of two arduinos. Should I?
Yes, otherwise the 2 systems do not have a common point of reference for the signal level
@UKHeliBob
I tried after connecting grounds of both arduinos, it didn't fix the issue, the output is same as before "0.00"
Please post the full code running on both Arduinos and confirm how you have connected them
Did you remember to connect the grounds this time?
Did you fix the timeout, as suggested in your other topic?
Duplicate post reported
changing the timeout worked, thank you @souvlakia.
@TheMemberFormerlyKnownAsAWOL
Yes, I posted this to be sure about the combination of circuit and arduino, I did apply those changes again on simulation through proteus as well as tried it physically for the whole circuit, the result hasn't changed, it still shows 0.00 on serial monitor.