This week assignment idea was about designing and programming a smart device
I made a device that will show the current temperature in Celsius degrees on the LCD , and the LEDs will lit each one according to three different temperature ranges. The piezo will play an alarm signal when the temperature goes above above degrees.
input components (Temperature Sensor, on/ off Switch) action components (LCD, Buzzer, LED)
using Arduino C (Text Code).
FOR INSPIRATION:
i googled to find inspirations and see how can i make my code, here's a link of my inspiration:
https://create.arduino.cc/projecthub/GioMac/lcd-thermometer-with-leds-and-alarm-signal-8b152d
i make some edits for the circuit i found;
i added on/off switch for the circuit,
i used liquid crystal display 12C (2x16) using 12C interface which has 4 pins: vcc, gnd, sda, scl pins.
https://arduinogetstarted.com/tutorials/arduino-lcd-i2c
software:
i used tinkercad wibsite to create my circuit diagram and Arduino IDE to write the code and transfer the code to the Arduino Uno through the USB cable.
tools:
cardboard
cutter
glue gun
component:
Temperature sensor
Arduino UNO
Buzzer
jumpers
crocodile jumpers
breadboard
ON/OFF switch
LCD 2x16 with 12C interface
LEDs
resistors
i googled to know more about the datasheet of the LCD and to make the code of it, i used this link to inspire me: https://arduinogetstarted.com/tutorials/arduino-lcd-i2c
it has 4 pins:
GND pin; needs to be connected to the ground of the arduino.
VCC pin; the power supply for the LCD, needs to be connected to VCC (5V).
SDA pin; I2C data signal.
SCL pin; I2C clock signal.
ON ARDUINO IDE from tools choose manage libraries.
searching about the library using 'LiquidCrystal I2C' to find the library of frank de bradander, then installing it.
coping the code on Arduino IDE then upload it on the Arduino UNO just to make sure that it woks.
connecting the GND of the LCD to the ground of the Arduino UNO, the VCC of the LCD to the 5V power of the Arduino UNO, SCL Pin to A5, SDA Pin to A4.
Then i made the connections on TINKERCAD .
i sued slide switch on TINKERCAD, but physically i used ON/OFF switch.
arduino code:
i made the code step by step, also i searched on every component to make sure that the text was correct, so i could upload it on arduino uno.
installing the library of LiquidCrystal I2C
using float function so the temperature could be displayed in decimal form.
making the LCD initialized.
and finally i made some calculations so the temperature could be able to display in correct number on the LCD.
texting the pinMode as output for the three leds; 7 for yellow, 8 for green and 13 for red.
9 for piezo and 2 for the on/odd switch.
then i used void loop to make if/else conditions for leds and buzzer.
i used while condition for the switch
connecting the LCD , breadboard and Arduino UNO together through male/male jumpers.
adding ON/OFF switch to the circuit one of the two terminals is connected to the breadboard's ground and the other terminal is connected to Pin2 of the Ardunio UNO.
connecting the buzzer; the negative side to the ground of the breadboard and the positive side to pin9 of Arduino UNO through male/male jumpers
adding Temperature sensor to the circuit one of the three connections(ground) is connected to the breadboard's ground and other one is connected to Pin9 of the Ardunio UNO, the power one is connected to the power of breadboard.
connecting the three leds to the circuit;
the cathode of the 3 leds is connected to 220 ohms resistors cause there is 5v power in the circuit.
the anode of the green one is connected to pin number 8.
the anode of the yellow one is connected to pin number 7.
the anode of the red one is connected to pin number 13.
NOW, when the temperature is more than 40 c the buzzer makes sound and the red led emits light.
cutting the cardboard into 6 parts ;
4sides, top, and bottom.
when i made the switch on;
the LCD will display the temperature degrees on the screen and the green led would emit light when the temperature is less than 35 ,when the temperature less than 40 and more than 35the yellow led emits light, and when the temperature is more than 40 the red led would emit light and the buzzer would make noise.
when the switch was off;
the LCD wouldn't display anything , the leds and buzzer wouldn't be worked .
Yes I had a feedback in the midweek session , and asked about the problems I had during the midweek exercise.
i also had a problem the lcd displayed negative temperature, i asked my friends and they advised me to check the circuit and i found out that one of the jumpers wasn't connected.
i faced a problem in making the smart home exercise the relay didn't work with me, but the instructor helped me, he also told me that i can check if the problem was from the connections or from the arduino by making every component work alone ae first then mix them together, especially if i used components i never used before.
I found out that my temperature sensor wasn't working well!
-it gave my wrong temperature degrees the temperature was 445 , at first i thought the problem was with my code so i asked my instructor and she advised me to use the temperature sensor alone with arduino and upload the code of it and the senor gave me the same readings.
i used that code to check the readings of the sensor;
int tempPin = 0;
void setup(){
Serial.begin(9600); }
void loop() {
float temp = (5.0 * analogRead(tempPin) * 100.0) / 1024;
Serial.print(temp,1);
Serial.println(" degrees C ");
delay(1000); }
so i used new temperature sensor and it worked.
i used pinMode (2, INPUT);
to define my on/off switch and i had a problem when i click on it works only one time
so my instructor advised my to use this instead;
pinMode(2, INPUT_PULLUP);
now i can make it on and off too many times.
i used wrong calculations for the temperature than displayed on the LCD, so i googled to search about more ideas to inspire me, then found out the mistake and i corrected it.
so i advised you to make sure that your calculations are correct especially when you used the LM35 Temperature Sensor.
i will be able to make the arduino code on Arduino then upload it to the Arduino UNO.