Arduino Forum

Using Arduino => Sensors => Topic started by: MaverickRF on Feb 06, 2019, 09:12 am

Title: HC-SR04 Ultrasonic sensor distance as analog value
Post by: MaverickRF on Feb 06, 2019, 09:12 am
Hi everyone,

I'm working with an Arduino MEGA 2560, an HC-SR04 Ultrasonic sensor and a softPLC (ProviewR SCADA).
Could someone please give me some hint about how to connect an Arduino to the HC-SR04 and convert the distance from the Echo pin to an analog value with the arduino to be sent to the softPLC afterwards?

Any help greatly appreciated

/Maverick
Title: Re: HC-SR04 Ultrasonic sensor distance as analog value
Post by: groundFungus on Feb 06, 2019, 10:08 am
You could convert the distance to a PWM value (map (https://www.arduino.cc/reference/en/language/functions/math/map/) distance to 0 to 255) then low pass filter the PWM (https://www.allaboutcircuits.com/technical-articles/low-pass-filter-a-pwm-signal-into-an-analog-voltage/) to get an analog voltage from 0 to some voltage.  Or use Arduino with a Digital to Analog (DAC) controller either built in or external.
Title: Re: HC-SR04 Ultrasonic sensor distance as analog value
Post by: MaverickRF on Feb 08, 2019, 05:16 pm
Hi,
Thanks a lot for your reply, I just want to ask some more questions to clarify things... the PWM is a digital output, right? So as you said, we get a digital input from the echo pin of the HC-SR04 in one digital pin, then we make a PWM output from another digital pin, and finally, we convert this signal into analog pin through a DAC, then we could take this signal back into an analog pin as an analog input into the Arduino, or a PLC... Is that correct?

/MaverickRF
Title: Re: HC-SR04 Ultrasonic sensor distance as analog value
Post by: Paul_KD7HB on Feb 08, 2019, 06:40 pm
Hi,
Thanks a lot for your reply, I just want to ask some more questions to clarify things... the PWM is a digital output, right? So as you said, we get a digital input from the echo pin of the HC-SR04 in one digital pin, then we make a PWM output from another digital pin, and finally, we convert this signal into analog pin through a DAC, then we could take this signal back into an analog pin as an analog input into the Arduino, or a PLC... Is that correct?

/MaverickRF
Just a clarification: what you get from the echo pin is a pulse that indicated the sensor received and echo. That is all.

Paul
Title: Re: HC-SR04 Ultrasonic sensor distance as analog value
Post by: DaveEvans on Feb 08, 2019, 07:19 pm
Reportedly that PLC has the ability to communicate with other computers via serial.  Wouldn't it be a lot simpler to just connect the Arduino to the PLC via serial and send the distance that way?