Arduino Intro

hhh

For my Arduino Introduction project, I decided to create an alarm that will tell me when to turn on the heater in my house. My house is weird in that the coldest room in the house is the bathroom, rather than the living room which has the windows and is closest to the door. This creates a weird dilemma for me, as I do not know whether to turn on the heater or put an extra layer of clothes on. This device will let me know when it is too cold and it is time for me to turn the heater on. Below is the storyboard for my idea.

For this to work I went with a speaker and a KY-028 temperature sensor module. Since I am not using the analog aspect of the module, I did not connect any power line for the analog to the arduino board. I found a tutorial online for connecting the KY-028 temperature module and what it can actually do. The tutorial also gave me the code for a different project than turns on a led if the temperature is too high, and turns the led off if temperature is normal. The Code is shown below.

int led = 13; // define the LED pin
int digitalPin = 2; // KY-028 digital interface
int analogPin = A0; // KY-028 analog interface
int digitalVal; // digital readings
int analogVal; //analog readings

void setup()
{
  pinMode(led, OUTPUT);
  pinMode(digitalPin, INPUT);
  //pinMode(analogPin, OUTPUT);
  Serial.begin(9600);
}
void loop()
{
  // Read the digital interface
  digitalVal = digitalRead(digitalPin); 
  if(digitalVal == HIGH) // if temperature threshold reached
  {
    digitalWrite(led, HIGH); // turn ON Arduino's LED
  }
  else
  {
    digitalWrite(led, LOW); // turn OFF Arduino's LED
  }

  // Read the analog interface
  analogVal = analogRead(analogPin); 
  Serial.println(analogVal); // print analog value to serial

  delay(100);
}

Above is a picture of the serial monitor to show that the code is working. For me to play a buzzer sound when the temperature is low, I added conditions and made it so instead of turning off the led, it makes a sound. The edited code is shown below.

int led = 13; // define the LED pin
int digitalPin = 2; // KY-028 digital interface
int analogPin = A0; // KY-028 analog interface
int digitalVal; // digital readings
int analogVal; //analog readings

void setup()
{
pinMode( 8, OUTPUT);
pinMode(led, OUTPUT);
pinMode(digitalPin, INPUT);
//pinMode(analogPin, OUTPUT);
Serial.begin(9600);

}

void loop()
{
// Read the digital interface
digitalVal = digitalRead(digitalPin);
if(digitalVal == LOW) // if temperature threshold reached
{
tone( 8, 33, 500);//C1
delay(1000);
}
else
{
noTone( 8);
}
analogVal = analogRead(analogPin);
Serial.println(analogVal); // print analog value to serial

delay(100);
}

Overall, this project was a lot of googling, and knowing what exactly I want to do beforehand. What materials I want to work with, what kind of devices I need, and what kind of conditional statements I will be using. I got baited by the fact that we are coding and how we were given a kit, so the project is all doable from home. I thought we did not need to borrow any devices, which proved to be wrong very quickly. If I had to redo this project, I think I would make it so the device plays music I like, instead of a buzz.

Below are the tutorial I used for the temperature module and the speaker.

KY-028 Digital Temperature Sensor Module

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on pinterest
Pinterest