This week was to learn the Arduino and how to think about codes and create them , So for the assignment I thought of trying something related to my final project as a part of the project was to move the shading device (Wooden strips) with a servo motor according to the motion of people passing by (microwave sensor) and to make this appear on an LCD to know at which condition it is whether it's shade mode or seat mode , The second thing was to make them manually select a button to open the seat .
Arduino
Automatic
The required is to make the LCD write shade when the wooden strips is in the shade mode and write seat when it's on the seat mode this is according to the microwave sensor
Firstly I started to connect the microwave sensor to the Arduino (connected to pin 3 )
---In the text code :
in the loop setup I defined the sensor as an input
Then I started to search for LCD code and how to connect it's wires , I took the reference from maker guides
reference :https://www.makerguides.com/character-i2c-lcd-arduino-tutorial/
---In the text code :
- I copied the code of the LCD in the text code and started to edit on it :
To make the LCD write ( shade ) when the microwave sensor doesn't sense motion , and to write (seat ) when the microwave senses motion ;
so I started to put an if condition for it and to make sure that these components work together , I printed the values on the serial monitor .
For adding the servo motor : I searched for servo motor code and how to connect it to arduino
reference : https://www.allaboutcircuits.com/projects/servo-motor-control-with-an-arduino/
---In the text code :
Defined the servo to be named as servo
then in the void setup , I defined that it's connected to pin 7 ,
to make it connected to the microwave sensor ;
-IF condition : when the microwave sensor doesn't sense motion servo is on 0 degrees ,when the microwave sensor senses motion servo is on 180 degrees
This was the automatic mode and how it worked
Manual mode
To add to the previous code a manual mode :
I need one slide switch ( choses if it's manual or automatic mode )
-push button ( (to turn on the seat mode (motor moves to 180 degree , LCD writes seat mode) or turns off (shade mode ) )
---In the text code :
I defined both buttons to be as a selector , and on_off
-then in the void setup , I defined the selector as INPUT and the on_off as INPUT_PULLUP
-in the void loop : if condition : if the selector is 1 or automatic mode then it makes the previous code , if not : on_off is low and will start to move the servo and write on the LCD (seat mode )
On tinker cad
Error in simulation is due to the missing of the library (ON TINKER CAD ) , but physically it worked good and the code was right ( will be discussed in the videos )
Automatic mode
After finishing the code , I uploaded it to the arduino and started the project
Automatic mode
Automatic and manual mode
-Yes I had a feedback in the midweek session , and asked about the problems I had during the midweek exercise
I had problems in my project , So i asked about it in the open time and I got them solved by the instructor :
-The first problem was that not all charachters appear on LCD , it was solved by updating the code version
The second was that the second part of the code in the if condition didn't work , and it was a small problem in the wires
At this week , I learned More about Arduino , and in the exercise I tried to make one of the functions that I want to make in the final project , so this helped me to think of it will work