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 that have 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 of the place exceeds a certain value and it contains led lights turned on when ultra-sonic sensor detects motion.
Electronic Copmonents:
Arduino IDE
Cardboard for enclosure
I started with simulating the circuit on Tinkercad to make sure of the connection as fellow:
1- connect the ultra sonic sensor (input) with the breadboard and Arduino so union the positive and ground on 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 TM36 sensor instead of dht11 (input) ground to ground, vcc to positive and data leg to pin A1.
4- connect 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 so we have two input sensors and each one of them control a different output device so there is two if conditions one for the temperature sensor and if the temperature exceeded a certain value the buzzer is on and if the ultrasonic sensor detect motion the led is turned on.
6- Except that the buzzer/led are off.
For the code blocks I put 2 if conditions as fellow:
- first read temperature on pin A1 in c units .
- if temperature value exceeds 50 c then set buzzer pin (A2) to high to alarm us except that set the buzzer pin to low.
- if ultrasonic detect motion within 50 then set led pin to high except that set led pin to low.
After wiring the circuit I started to write the code as fellow:
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 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 together to get the final code that work for all my inputs and outputs and uploaded it.
Testing the code with circuit
I started to build the enclosure by cardboard :
- made cross section in the design to show the functions in different rooms.
-build the back and sides and divide the front side to 2 levels and the second level to 2 rooms.
-put the ultrasonic sensor and led in a room and put the fire alarm in another room.
-mounted the components (Arduino, breadboard, buzzer and wires) and put them in the top of the home.
The final simulation with cardboard
DHT11 sensor wasn’t indicate any readings on serial monitor so I found that it was connected to wrong pin. So I connected to the right pin and it works well.