Programming is one of the skills I wanted to learn on my own. After looking at how complicated it looks, I decided to not learn it for now.
I did not realise that the module CP5070 would teach me how to programme, Especially Arduino.
Input Devices
Potentiometer:
By using Blocks instead of coding normally, I set it so that it will print to the serial monitor the analog pin A0 which is connected to the Potentiometer on a new line. I added a 1 sec delay to not clogup the serial monitor.
Photoresister/LDR:
By also using Blocks, it has the same setup as the Potentiometer in coding but is missing the GND connection.
Output Devices
LEDs:
The Red LED is connected to the 3 pin, Yellow for the 5 pin and Green for the 7 pin. By using blocks, The Red LED would light up for 1 second. After the delay, the Red LED would turn off at the same time as the Yellow LED turing on. After another the delay of 1 second, the Yellow LED would turn off at the same time as the Green LED turing on. After a final 1 second delay, the Green LED would turn off and the cycle continues.
DC Motor:
Honestly I don't know how it works but all I do know is the DC motor stays on and turns off when you hold the built-in button and turns back on when the button isn't pressed.
While trying to insert the input devices, I have learnt that I need to use the Analogs like A0,A1
While trying to use the output device, the pins like pin 9 or pin 7 will be mainly used to send a signal to the output devices.
All the codes will be in a .rar file and need to be unziped using 7zip or Winrar.
The main problem was trying to figure out how to code at first until I figured out I can use the blocks as a way to help me code. After that, the next problem was trying to position the components and how to connect them. The final problem was trying to toggle the DC Motor but at the end, I couldn't figure it out but looked up tutorials on how to do it. In the end, it couldn't work so I left it as it is.
Practical
We firstly import a template of codes from Arduino itself by going to File -> Example -> Servo -> Sweep
Afterwards, we removed the delay since at the time we didn't know what the purpose of adding a delay is for. After some modifications we have a code like the one below
As a side note: Our group decided to add a button to be able to on and off the servo cause I don't know maybe we were bored or something.
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
States the inital potision
int pos = 0; // variable to store the servo position
Setup pin 2 to have it's LED a light up to indicate when the servo is not powered. Pin 9 is used an output as a way to tell the servo to turn on while having the data wire connected to it.
void setup() {
//start serial connection
Serial.begin(9600);
//configure pin 2 as an input and enable the internal pull-up resistor
pinMode(2, INPUT_PULLUP);
pinMode(9, OUTPUT);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
I will be perfectly honest I have no idea how this part of the code works but all I know is this it will move/rotate from position 0 to position 180 in how many degrees like 180 for this one in I don't know how many seconds maybe 1, tell the servo to go to said position and move/rotate from position 180 to 0. The delay in between tells the servo how long to wait until the next action.
void loop() {
//read the pushbutton value into a variable
int sensorVal = digitalRead(2);
//print out the value of the pushbutton
Serial.println(sensorVal);
// Keep in mind the pull-up means the pushbutton's logic is inverted. It goes
// HIGH when it's open, and LOW when it's pressed. Turn on pin 9 when the
// button's pressed, and off when it's not:
if (sensorVal == HIGH) {
//digitalWrite(9, LOW);
} else {
for (pos = 0; pos <= 180; pos += 180) { // 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(150);
}
for (pos = 180; pos >= 0; pos -= 180) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(150); // waits 15 ms for the servo to reach the position
}
}
}
For inputting to the maker UNO. We use a USB A to Micro USB B cable to connect a laptop to the maker UNO. The USB A (the bigger one) connects to the laptop and the Micro USB B (the smaller one) connects to the maker UNO board.
For outputting from the maker UNO to the servo, we used 3 wires. A red, orange and brown wire. The red wire connects to the 5-volt pin to send power, the orange wire for sending data to pin 9 (we programmed it to the 9 pin but other pins work as long you programmed it correspondingly) and the brown wire to the GND pin which is a ground wire for the servo.
Since we used coloured wires that match the ones on the servo, we just matched them together.
Afterwards, we used a piece of wire to connect the servo to the wings of the Unicorn.
I don't know how to place the code file into wix so here is a website link to a google drive where I uploaded the code file. The file name is:
hijau.ino
Here is a video of how it looks when it is working.
We soon faced a problem where the wings did not flap as wings should do.
Let me explain
When flying, wings flap continuously and do not stop. Our wing did stop. This was a simple fix. We just needed to add a delay so after that amount of time, it would continue to move without stopping.
The video below is the outcome of adding the delay.
As you can see, the wings flap continuously now with is much more representative of actual wings flapping.
A first, I thought coding is really tough since I thought you need to memorize a huge range of commands. That was a misconception. Turns out that programmers do not actually write their own code. They just copy from an online source and just copy code. It's like every programmer is helping each other. Either helping to code or just giving codes that work.
As for trying to actaully code, the blocks from tinkercad actually help alot but it still has it's limitations.
I had some knowledge of what programmers do but did not actually do any programming at all. I wouldn't say I am good at programming after doing this. I do know that I have some competency on how to code but I do need to understand what the lines of codes mean before I ever say I am good at coding or even understand it.
Comments