This week’s assignment is to Design and program a smart device that performs a certain function or solve a problem: program Arduino UNO to read signals from multiple input components (Sensor, Switch, or variable resistor) to control multiple action components (Motor, Buzzer, LED...etc.) using Arduino C (Text Code).
Smart home with fire alarm and ultrasonic sensor for brightness:
I get inspiration from smart homes with fire alarms so I wanted to try the DHT11 to detect the temperature of the place so it can work as an alarm when the temperature exceeds a certain value and it contains LED lights turned on when an ultra-sonic sensor detects motion.
to simulate the electrical circuit before implementing it.
Jumper Wires
buzzer
DHT11 temperature and humidity sensor
arduino uno
Ultrasonic sensor
led
arduino id to run the code
resistor
Breadboard
Cardboard for enclosure
I started with simulating the circuit on Tinkercad to make sure of the connection as follows:
1- connect the ultrasonic sensor (input) with the breadboard and Arduino to union the positive and ground on the breadboard then connect ground to ground, vcc to positive, trig to pin 9, and echo to pin 10.
2- connect the led (output) leg to the resistor to ground and the other to pin 3.
3- connect the TM36 sensor instead of dht11 (input) ground to ground, VCC to positive, and data leg to pin A1.
4- connect the buzzer (output) ground to ground and positive to pin A2.
5- I used code blocks just to simulate the circuit and make sure that components work well we have two input sensors and each one of them controls a different output device so there are two conditions one for the temperature sensor and if the temperature exceeds a certain value the buzzer is on and if the ultrasonic sensor detects motion the led is turned on.
6- Except that the buzzer/LED is off.
For the code blocks, I put 2 if conditions as fellow:
- first read the temperature on pin A1 in c units.
- if the temperature value exceeds 50 c then set the buzzer pin (A2) to high to alarm us except that set the buzzer pin to low.
- if ultrasonic detects motion within 50 then set the led pin to high except that set the led pin to low.
After wiring the circuit I started to write the code as follows:
1- I coded only two components the DHT11 and the buzzer for testing first.
2- Used the dht.h test library by Adafruit to test the sensor first then I edited the code by adding the buzzer so that if the temperature exceeds a certain value the buzzer is on. I also uncomment the humidity lines as I want my output to depend only on the temperature.
3- Started a new sketch for coding the ultrasonic sensor, I googled ultrasonic sensor codes then found this code and edited it by adding the output (led) so if the ultrasonic reading is high the LED is on.
4- Finally merged the two codes to get the final code that work for all my inputs and outputs and uploaded it.
The DHT11 sensor didn’t indicate any readings on a serial monitor so I found that it was connected to the wrong pin. So I connected it to the right pin and it works well.