Hello;
I'm trying to solve the problem here:
Realize a system measuring an ultrasonic distance, and taking into account the temperature for the ultrasonic propagation speed (other assumptions: altitude 0 and dry air). Distance and temperature will be displayed on the serial monitor.
Attention: for more precision you will take two temperature sensors and you will do their average. If you detect a problem in the sensors (more than 0.5 ° C difference), switch on a red LED.
Material: HC-SR04 + TMP36 + 74HC151 + Arduino
To solve the problem, I propose the following algorithm:
int Value1;
int Value2;
int S0=1;
int S1=2;
double temps;//Or time
double distance;//Distance
double vitesse=0.034;//Speed
void setup()
{
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
digitalWrite(S1,LOW);
digitalWrite(S0, LOW);
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
Serial.begin(9600);
pinMode(2, OUTPUT);
}
void loop()
{
digitalWrite(S1,LOW);
digitalWrite(S0, LOW);
pinMode(7, OUTPUT);
digitalWrite(7, HIGH);
delay(15);
digitalWrite(7, LOW);
digitalWrite(S0, HIGH);
digitalWrite(S1,LOW);
Serial.print("Capteur");
pinMode(7, INPUT);
temps=pulseIn(7, INPUT);
distance=(float)((vitesse*temps)/);
Serial.println("La distance est:")//The distance is
Serial.print(distance);
digitalWrite(7, LOW);
digitalWrite(S0, LOW);
digitalWrite(S1,HIGH);
pinMode(7, INPUT);
Value1=analogRead(7);
digitalWrite(S1,HIGH);
digitalWrite(S0,HIGH);
pinMode(7, INPUT);
Value2=analogRead(7);
Serial.println("Premier capteur");
Serial.print(Value1);
Serial.println("Second capteur");
Serial.print(Value2);
if ( abs( Value1- Value2)<0.5)// Connected to led for blinking it
{
pinMode(2, OUTPUT);
digitalWrite(2,HIGH);
}
To answer your question I posted on the English and French forum. To have answers more quickly.
In addition I initialize the function PulseIn with signature "double" with the variable "time".
I just saw that the pin 1 does not correspond to what I ask him to do. I would choose another. Pin 2, for example. Apart from that, do you think that the program will work ?
And i saw on the Website that , i can use "analogRead" even the port isn't analog .
Or it's false ?
That is not true. analogRead() ONLY operates on analog pins. digitalRead() will work on the analog pins, though, since the analog pins are also digital pins.
PaulS:
That is not true. analogRead() ONLY operates on analog pins. digitalRead() will work on the some* analog pins, though, since the some* analog pins are also digital pins.
*On products where the A6 and A7 pins are present, these are analogue-only inputs.