I have written a code for a project that will use the known distance to something and an ultrasonic distance sensor to record the speed of light. I have combined a known code for that with another code for the DHT11 humidity and temperature sensor. I am getting an error message which states: "error: expected initializer before 'const' ". Can someone help me with what the error is trying to say?
Here are all the error messages:
Science_Research_Code:7: error: expected initializer before 'const'
Science_Research_Code.ino: In function 'void setup()':
Science_Research_Code:17: error: 'trigPin' was not declared in this scope
Science_Research_Code.ino: In function 'void loop()':
Science_Research_Code:24: error: 'trigPin' was not declared in this scope
Science_Research_Code:41: error: 'DHT' was not declared in this scope
Science_Research_Code:41: error: 'DHT11_PIN' was not declared in this scope
Here is the code:
#include <dht.h>
dht DHT
#define DHT11_PIN 7
const int trigPin = 13; //Sensor Trip pin connected to Arduino pin 13
const int echoPin = 11; //Sensor Echo pin connected to Arduino pin 11
float pingTime;
float speedOfSound;
float distanceMeasurement;
int targetDistance = 6; //Distance to Target in cm, must input before running program
void setup() {
//Put your setup code in here to run once
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
//put your main code here to run repeatedly
digitalWrite(trigPin, LOW); //Set trigger pin low
delayMicroseconds(2000); //Let signal settle
digitalWrite(trigPin, HIGH); //Set trigger pin high
delayMicroseconds(2000); //delay in high state
digitalWrite(trigPin, LOW); //ping has now been sent
pingTime = pulseIn(echoPin, HIGH); //pingTime is presented in microseconds
distanceMeasurement = (343*100) * (pingTime/1000000)/2; //this is the distance that the computer calculates with adjusted speed of sound
speedOfSound = (targetDistance*2)/pingTime*(1000000)/100; //finds speed in m per s
Serial.print("The Speed of Sound is: ");
Serial.print(speedOfSound);
Serial.println("m/s. ");
Serial.print("The measured distane is: ");
Serial.print(distanceMeasurement);
Serial.print("cm.");
int chk = DHT.read11 (DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
delay(1000);
}
Science_Research_Code.ino (1.45 KB)