Arduinos and their uses

Today, after we built a contraption, we took to coding it. This mainly consisted of using tester code for different functions but also understanding what the different parts of the code does. Firstly, this needs to be run in the Arduino IDE (integrated development environment) and allow the software to see the board through the COM3 or COM4 port on your pc (usually the USB inputs).After connecting everything, we started off simple and slow and gradually built up to the more developed and complex code that Daemon (our Arduino) can do.

 

We first started with just lighting an LED:


This means that the LED is plugged into the D3 pin (the pin doesn't matter, just make sure to link up your code with where component is actually plugged in). This turns the LED into an ON state, waits 1000ms then turns it into the OFF state for 1000ms, then loops until broken or halted. All in all, a simple bit of coding.



We then moves to a button operated LED:



This code is a bit more hefty as includes conditions. We first determine the pin number of all the components being used (button and LED). We then set the baud rate (rate at which we send the impulse) up to the highest the Arduino can handle  for a more responsive test and labelled out INPUT and OUTPUT, this being out button and LED respectively. We then set our button states as 1 and 0 corresponding to ON and OFF. This now monitors our button state with OFF (0) being the base state at which it is checking. When this changes, if we press the button and change the state to ON (1), then it moves to the 'if' section, allowing our LED to light up, otherwise it remains off. This loop then repeats ever 0.1 seconds.

 

Whilst still being more advanced, it was still pretty rudimentary in what it could achieve, so we set our sights for better things, the buzzer:



I've cut out some of the code that we've gone over. This piece of code tells our buzzer at which frequency to vibrate at and the delay in between each of its noises. These pitches control the start of Happy Birthday with 42 lines of code for it but this can dramatically increase to well over 200 for some more complex songs like the DOOM intro.




Still, not reaching Daemon's full potential so we though to look for some more advanced
features, the LCD display:



Wire.h in this case is a library containing assets in which this grabs from. In our case, it would be the design for all the letters, punctuation and numbers the screen can display. For this display, the co-ordinates range from 0,0 (the top left) to 1,16 (bottom right). This code grabs the asset from the library and fits it into the co-ordinates (with spaces counting as taking a co-ordinate) to display our desires message.




 

Next was our test at environmental variables, using a photoresistor to control an LED:



This does the same startup with pins and baut rate. We then create a loop which reads the value detected our photoresistor, in this case it's lux. This then tells the Arduino what it is (hence the need for it to be in the A pin and not D) and the Arduino makes the decision to allow the signal to carry on to the LED by some simple maths. If the value is < 300, then it is dark and the LEED turns on. If the number does not fall under this category, then the value it rejected. This then repeats ever 0.1 seconds.

 

Now that we had tested environment dependence, we could measure the environment conditions, the DHT11: 



This uses an almost conversion called 'dht11.h' in order to make sense of the inputs it receives from its surroundings. We then put it in a loop of gathering the data from the humidity and temperature, then taking out any anomalies and taking a mean which is generally constant if left alone. This then displays our data in two columns of 'Temperature' and 'Humidity' in ℃ and % respectively in the serial monitor included in the IDE.



 Our final test before combining a selection of these projects for our final Daemon was testing the servos that hold up our solar panel:



This creates a loop for the servo in which it turns to 0, 90 and 180 degrees on a plane in which it has set up by taking the resting place as (0,0). This then has a second display between each movement. This does it in pulses as to not break any of the other structure and the servo itself.






And so it was time to test Daemon's full potential:


Links to the code:

Turning the LED on and off
https://create.arduino.cc/editor/keyestudio/3f820d9f-be53-4021-9ecf-d7a8f58aa70c/preview

Controlling the LED using the button 
https://create.arduino.cc/editor/keyestudio/43da7298-8784-4ecd-88c1-aee6caa8fc02/preview

The Buzzer
https://create.arduino.cc/editor/keyestudio/6801389a-2348-4d65-8289-25611aa71f27/preview

LCD Display
https://create.arduino.cc/editor/keyestudio/d68f8412-0000-4b1f-ac58-a7f312f4f2a2/preview

Photoresistor LED
https://create.arduino.cc/editor/keyestudio/0427b858-2b13-455b-a7ed-62364647f2d3/preview

DHT11
https://create.arduino.cc/editor/keyestudio/7fbc2fb4-73ba-45ae-abaa-2eea9919f5b4/preview


Comments

Popular Posts