Arduino Programming
Arduino Programming
Arduino is a platform where coding is simplified for educational purposes. We were given the Arduino Maker board which could make our coding turn to life. There are many things that we could create with creativity using the Arduino board. It could generate leg lights, melodies, control servo motors and many more!
From this lesson, we have learnt how to calculate the resistance of the resistors based on the colour stripes on it. Each colour represents a number.
Since the first line is red, the first digit will be : 2
The second line is orange, hence the second digit will be : 3
The third line is yellow, hence the multiplier is 10^4
Therefore the resistance is : 23 x 10^4 = 230 kΩ
Tolerance = +/- 10%
Arduino Practical
In this practical, our group was challenged to make a cardboard cutout unicorn's wings to flap using the Arduino motor.
We attached a single wing to the Arduino servo motor.
We were given a limited supply of 30cm metal wire to make the challenge more exciting and we have to carefully think through our ideas before executing it.
We looped the wires onto the wing of the servo and poked through holes into the internal part of the unicorn's wings. We decided to hide the servo underneath the unicorn's body as shown below.
We used the remaining metal wires to tie around the servo motor and attach it securely to the unicorn's body to keep it in place and hidden. We also added a cardboard tab with hot glue gun to add further support to the servo's weight.
Coding
In order to retrieve our desired execution of the servo, we toggled to 'File' > 'Examples' > 'Servo' > 'Sweep' and changed the delay to 3 milliseconds.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(3); // waits 3 ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(3); // waits 3 ms for the servo to reach the position
}
}
Final Product!
Post Practical
1. Input devices:
a. Interface a Potentiometer Analog Input to maker UNO board and measure its signal in serial monitor Arduino IDE
b. Interface a LDR to maker UNO board and measure its signal in serial monitor Arduino IDE
2. Output devices:
a. Interface 3 LEDs (Red, Yellow, Green) to maker UNO board and program it to perform something (fade or flash etc)
b. Interface the DC motor to maker UNO board and program it to on and off using push button on the board
1A)
Tinkercad Simulation
1B)
Tinkercad Simulation
Video on actual Arduino Board
2A)
Tinkercad Simulation
Video on actual Arduino Board
2B)
Tinkercad Simulation
Comments
Post a Comment