Student Code
Student Code
// DHT 11 connection
int pin = A2;
DHT11 dht11(pin);
// Motor Connection
const int Motor_1_A = 12;
const int Motor_1_B = 11;
// Variables declaration
int current_temp = 0, current_humidity = 0;
long duration, distance; // Duration used to calculate distance
int buttonState = 0;
void setup()
{
void loop()
{
buttonState = digitalRead(SW); // check if button pressed
// Humidity read
read_Dht11();
// back to normal/straight
digitalWrite(Motor_1_A, LOW);
digitalWrite(Motor_1_B, HIGH);
// Stop
digitalWrite(Motor_1_A, LOW);
digitalWrite(Motor_1_B, LOW);
}
// back to normal/straight
digitalWrite(Motor_1_A, HIGH);
digitalWrite(Motor_1_B, LOW);
delay(3000);
// Stop
digitalWrite(Motor_1_A, LOW);
digitalWrite(Motor_1_B, LOW);
}
void ultrasonic_1()
{
ultra_count = 0;
final_distance = 0;
while (ultra_count != 5) // Lets average 5 readings; for better approximation
{
delay(10);
ultra_count++;
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
digitalWrite(trigPin_1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin_1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin_1, LOW);
duration = pulseIn(echoPin_1, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration / 58.2;
final_distance = final_distance + distance;
}
final_distance_1 = final_distance / 10;
}
void ultrasonic_2()
{
distance = 0;
ultra_count = 0;
final_distance = 0;
while (ultra_count != 5) // Lets average 5 readings; for better approximation
{
delay(10);
ultra_count++;
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
digitalWrite(trigPin_2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin_2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin_2, LOW);
duration = pulseIn(echoPin_2, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration / 58.2;
final_distance = final_distance + distance;
}
final_distance_2 = final_distance / 5;
}
void update_data()
{
gprsSerial.print("http://iot.theproject.in/SS_IoT_WS.asmx/");
gprsSerial.print("SQL_IoT_Insert?Userkey=IT001&Personalid=SomePiD&sensor_input=");
gprsSerial.print(current_temp); gprsSerial.print(",");
gprsSerial.print(current_humidity); gprsSerial.print(",");
gprsSerial.print(final_distance_1); gprsSerial.print(",");
gprsSerial.print(final_distance_2); gprsSerial.print(",");
gprsSerial.print(final_sensor_1); gprsSerial.print(",");
gprsSerial.println("&RetMsg=s\"");
delay(500);