Questions tagged [pulsein]

refers to the function pulseIn().

Description

Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds or 0 if no complete pulse was received within the timeout.

The timing of this function has been determined empirically and will probably show errors in shorter pulses. Works on pulses from 10 microseconds to 3 minutes in length. Please also note that if the pin is already high when the function is called, it will wait for the pin to go LOW and then HIGH before it starts counting. This routine can be used only if interrupts are activated. Furthermore the highest resolution is obtained with short intervals.

Syntax

pulseIn(pin, value) 
pulseIn(pin, value, timeout)

Parameters

pin: the number of the pin on which you want to read the pulse. (int)

value: type of pulse to read: either HIGH or LOW. (int)

timeout (optional): the number of microseconds to wait for the pulse to be completed: the function returns 0 if no complete pulse was received within the timeout. Default is one second (unsigned long).

Returns

the length of the pulse (in microseconds) or 0 if no pulse is completed before the timeout (unsigned long)

35 questions
10
votes
4 answers

What is the work of pulseIn?

I have code for an ultrasonic sensor which I found from a site. Here is the code: #define trigPin 12 #define echoPin 13 void setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); } void loop() { int duration,…
shajib0o
  • 551
  • 2
  • 6
  • 9
8
votes
2 answers

How precise is the timing of pulseIn()?

I've been using the pulseIn() function for processing PWM-based binary data encoding. It works well for distinguishing pulses which are significantly different lengths, e.g. 500us vs. 1500us. That makes it more than sufficient for handling typical…
Peter Bloomfield
  • 10,982
  • 9
  • 48
  • 87
5
votes
2 answers

Read RC receiver channels using Interrupt instead of PulseIn

I am designing my own quadcopter control algorithm, whereby I currently read 4 RC receiver channels using PulseIn on each loop in the following manner: ch1_raw = pulseIn(rcPin1, HIGH, 25000); In other words, ch1_raw contains the length of a HIGH…
RLJ
  • 53
  • 1
  • 4
3
votes
1 answer

Pulsein() function blocks other tasks from running silmultaneously

I am using a zumo bot with a reflectance sensor used to follow a black line. I want to use an arduino to make the zumo bot stop once it gets a certain distance from an obstacle. I have an ultrasonic sensor (HC-SR04) which ive connected to the…
3
votes
1 answer

How can I replace pulseIn with interrupts?

I have an HC-SR04 sensor and I need to get the distance from it. I use this code: digitalWrite(trig, LOW); delayMicroseconds(2); digitalWrite(trig, HIGH); delayMicroseconds(10); digitalWrite(trig, LOW); duration=pulseIn(echo, HIGH,…
shurup
  • 300
  • 1
  • 8
  • 21
3
votes
2 answers

how to solve Varing duty cycle value while using Pulsein()

Well im new to coding, but i do have the basic knowledge. I'm using an UNO to measure a duty cycle. The source of pulse is a Tektronic signal generator (Duty cycle set to 50.000 with frequency of 2khz). my code is as follows, byte PWM_PIN = 3; float…
CjZ
  • 39
  • 2
2
votes
1 answer

Ultrasonic sensor confusion

Here is a code snipet for ultrasonic sensor digitalWrite(trigpin,HIGH); delayMicroseconds(10); digitalWrite(trigpin,LOW); duration=pulseIn(echopin,HIGH); Assume trigpin and echopin pins are already defined. Now according to Arduino reference guide…
2
votes
0 answers

Arduino Record pulseIn

I am currently working on a project which requires me to record IR signals. (I realize there is a library available for doing this but I want to learn how to do this myself). I tried using a simple sketch which prints out pulseIn() times on the…
DarkHorse
  • 165
  • 1
  • 9
2
votes
2 answers

How do I use two PulseIn() functions simultaneously in Arduino?

I want to connect multiple Ultrasonic sensors to my Arduino board. For that, I need multiple pulseIn() functions to work at the same time. How can I do that?
Mat_python
  • 56
  • 2
  • 4
2
votes
2 answers

Measurement of pulse duration greater than 3mins

Is it possible to measure the width of a pulse which is longer than 3 minutes? The pulseIn function can only measure duration of maximum 3 minutes accurately. I've tried using interrupts but haven't come up with a correct solution yet. I'm measuring…
1
vote
1 answer

How execution time of code instructions influences signal between Arduino and DHT11?

I am exemining code for DHT11 from CircuitGeeks, variant without using lib. The problem is a mismatch between DHT11/DHT22 protocol and signals, which are read from sensor in scetch. Despite this, sketch is working and I would like to find out…
1
vote
2 answers

Working with pulseIn() and millis()

I'm trying to use pulseIn with elapsed time using millis(), I don't want to use interrupts instead of pulseIn (I need pulseIn because I need accurate pulse time), the elapsed time doesn't need to be very accurate, so to calculate the elapsed time…
Takata
  • 89
  • 4
1
vote
1 answer

Pulsein not working when share ground

I have 3rd party device that create PWM output which I want to measure it with Arduino, the problem I have is when I shared ground between the two boards which cause the Pulsein output to become zero. (why this is happening, and how to fix it) The…
Shahreza
  • 165
  • 2
  • 9
1
vote
0 answers

Arduino 33 Nano BLE Sense not compatible with pulseIn()?

Preface Currently, I'm making an application on a Arduino 33 Nano BLE Sense. I'm trying to measure the current humidity and send it via BLE to another device. The target is to send a precise value with a high frequency, 8-10 values every second. For…
fuggerjaki61
  • 111
  • 4
1
vote
1 answer

Is it possible to use FrSky D8R-II Plus 8ch 2.4Ghz ACCST Receiver with an arduino Uno?

I'm in the process of buying a receiver and transmitter for my quad copter project. Would it be possible to use this receiver or a similar one to control the quad. I'm trying to read the signals using Pulse in. I'm inexperienced in RC and I only…
Ozymandias
  • 147
  • 1
  • 5
1
2 3