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 sun direction . so I chose to make the input with an (LDR ) and the output from the servomotor
software used : Tinker cad
To create circuits and simulate it before making it physically
Arduino
On tinker ad
Servo+ photoresistor
The required is to make the servomotor rotate as the light intensity increases (Moving servo with Photoresistor )
As the steps of week 6 :
Firstly I started to connect the photoresistor to the arduino :
-Terminal 2 to pin A0 to be an input for the servomotor
-And terminal 1 to the 3.3v and Ground with a resistor to prevent it's damage
-Then I connected the servomotor with the 5v, ground and with pin 10 , to be an output
- after this I added a slider button on pin 9 to control the device
Coding
To start coding I started to think for the following :
Moving servo with Photoresistor
-Input : Read analog A0 (Photoresistor )
-Output : Pin 10 (Servomotor )
-Coding tools :
.Print serial or the photoresistor (A0) to determine it's range which was from 0 to 500
. Mapping (To make the servo rotate according to the values from A0 ) , and the scale of mapping to be from 0-->180
-First block was reading A0 to read the photoresistor , then mapping it to scale it's range to be within the angles of the servo motor
-Then those two blocks are inserted in (Rotate servo motor on ) to make it rotate with these values .
, After this I added an IF condition ( to make it controlled by the slider button ) , when the slider is HIGH then the previous code starts , else servo is set to zero .
-Then to make it be controlled not only by the arduino , when pressing 'a' on the keyboard it starts , and the serial monitor starts to print the servo motor values ,
but at this point I had an ERROR , and I couldn't find it .
After this I started processing ,
firstly to understand it , I searched for the label and button library , to know how to wite it's code
-Then I wrote the code from these two libraries , and changed the text in the label to be servo angles , and when I press on the toggle it writes (Press)
Processing code after linking with the Arduino
Servo +Photoresistor physically
After finishing the simulation on tinker ad ,
-I started to make the same connections physical using a breadboard
-Then I opened Arduino program , and copied the text code to it then uploaded it on the Arduino which is already connected to the servomotor and photoresistor .
Coding
-Yes I had a feedback in the midweek session ,
I had problems in the arduino code specifically in the serial monitor part , due to this problem the whole exercise was not good , and each part the arduino and proessing are not connected to each other , because the GUI cannot find the arduino port (because of it's error )
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