top of page
Search

BLOG 2 : ARDUINO

  • dhasna22
  • Dec 4, 2023
  • 4 min read

1.Input devices: Interface a potentiometer analog input to maker UNO

board and measure/show its signal in serial monitor Arduino IDE


a.Below are the code/program I have used and the explanation of the code.

​Code/program in writeable format ​

Explanation of the code

// Define the analog pin for the potentiometer

const int potPin = A0;


void setup() {

// Start serial communication

Serial.begin(9600);

}


void loop() {

// Read the analog value from the potentiometer

int potValue = analogRead(potPin);


// Print the value to the Serial Monitor

Serial.print("Potentiometer Value: ");

Serial.println(potValue);


// Add a small delay for stability

delay(100);

}


First line of code defines constant variable.Serial.begin(9600) initiates communications between laptop and Arduino.int potValue reads analog value from potentiometer and serial.print, prints value to serial monitor.

b. Below are the hyperlink to the sources/references that I used to write the
code/program.

Name of AI Tool

Chat GPT

Input prompt

Interface a potentiometer analog input to maker UNO board and

measure/show its signal in serial monitor Arduino IDE

Date generated

2 December 2023

Output generated

// Define the analog pin for the potentiometer

const int potPin = A0;

void setup() {

// Start serial communication

Serial.begin(9600);

}

void loop() {

// Read the analog value from the potentiometer

int potValue = analogRead(potPin);

// Print the value to the Serial Monitor

Serial.print("Potentiometer Value: ");

Serial.println(potValue);

// Add a small delay for stability

delay(100);

}



Impact on submission

Allowed me to get the code to complete task


c. Below are the problems I have encountered and how I fixed them.

I didn't face much issues except that I couldn't see the readings of the potentiometer on my Arduino IDE which I then found out that I have to click on the magnifying glass at the top right hand corner of the IDE which allowed me to see the serial output on the IDE.


d. Below is the short video as the evidence that the code/program work.


2. Interface a LDR to maker UNO board and measure/show its signal in

serial monitor Arduino IDE

a.Below are the code/program I have used and the explanation of the code

​Code/program in writeable format

Explanation of the code

int LDR = A0;

int ledPin = 13;

int LDRvalue = 0;

void setup()

{

pinMode(ledPin,OUTPUT);

}

void loop()

{

LDRvalue = analogRead(LDR);

if(LDRvalue > 1000)

digitalWrite(ledPin, HIGH);

else

digitalWrite(ledPin, LOW);

}



Ledpin13 will light up when it is dark and turn off when there is light.The LDR detects the light intensity which causes ledpin to either light up or turn off.

b. Below are the hyperlink to the sources/references that I used to write the
code/program.

Brightspace : Maker UNO Edu Kit Module


c. Below are the problems I have encountered and how I fixed them.

On brightspace the initial code was if(LDRvalue>600) . However that code did not work on my uno maker board and the light on Pin13 was still on as I slowly increased the digits I found that at 1000 it worked


d. Below is the short video as the evidence that the code/program work.



3. Interface 3 LEDs (Red, Yellow, Green) to maker UNO board and program it to perform something (fade or flash etc)

a.Below are the code/program I have used and the explanation of the code

​Code/program in writeable format

Explanation of the code

// Define LED pins

const int redLedPin = 10;

const int yellowLedPin = 11;

const int greenLedPin = 9;

void setup() {

// Initialize LED pins as outputs

pinMode(redLedPin, OUTPUT);

pinMode(yellowLedPin, OUTPUT);

pinMode(greenLedPin, OUTPUT);

}

void loop() {

// Call the fade function for each LED

fadeLed(redLedPin);

fadeLed(yellowLedPin);

fadeLed(greenLedPin);

}

// Function to fade the LED connected to the specified pin

void fadeLed(int ledPin) {

// Fade in

for (int i = 0; i <= 255; i++) {

analogWrite(ledPin, i);

delay(1);

}

// Fade out

for (int i = 255; i >= 0; i--) {

analogWrite(ledPin, i);

delay(1);

}

​The LEDS are connected to the pins shown in the code and will blink as output. Void loop codes will allow the lights to blink before moving on to the next LED so the LED will turn on for 1ms and the fade to the next within 1ms.



b. Below are the hyperlink to the sources/references that I used to write the
code/program

Name of AI Tool

Chat GPT

Input prompt

Interface 3 LEDs (Red, Yellow, Green) to maker UNO board and program

it to perform something (fade or flash etc)

Date generated

2 December 2023

Output generated

const int redPin = 9;

const int yellowPin = 10;

const int greenPin = 11;


void setup() {

// initialize pin modes

pinMode(redPin, OUTPUT);

pinMode(yellowPin, OUTPUT);

pinMode(greenPin, OUTPUT);

}


void loop() {

// Red LED

fadeLED(redPin);


// Yellow LED

fadeLED(yellowPin);


// Green LED

fadeLED(greenPin);

}


void fadeLED(int pin) {

// Fade in

for (int i = 0; i <= 255; i++) {

analogWrite(pin, i);

delay(10);

}


// Fade out

for (int i = 255; i >= 0; i--) {

analogWrite(pin, i);

delay(10);

}

}


Impact on submission

Allowed me to get the code to complete task



c. Below are the problems I have encountered and how I fixed them.

Initial code I used was delay(10) which took a long time for the LEDs to change colour so I reduced the delay and changed code to delay(1) . Connections of the LEDs to the pins were also bit messy so after trial and error I used the PIN numbers as stated in part(a).


d. Below is the short video as the evidence that the code/program work.

4. Include the pushbutton on the MakerUno board to start/stop part 2.a.

above.

a.Below are the code/program I have used and the explanation of the code

​Code/program in writeable format

Explanation of the code

onst int greenLedVehicle = 5;

const int yellowLedVehicle = 6;

const int redLedVehicle = 7;

const int greenLedPedestrian = 3;

const int redLedPedestrian = 4;

const int pushButton = 2;

void setup()

{

pinMode(greenLedVehicle, OUTPUT);

pinMode(yellowLedVehicle, OUTPUT);

pinMode(redLedVehicle, OUTPUT);

pinMode(greenLedPedestrian, OUTPUT);

pinMode(redLedPedestrian, OUTPUT);

pinMode(pushButton, INPUT_PULLUP);

digitalWrite(greenLedVehicle, HIGH);

digitalWrite(redLedPedestrian, HIGH);

}

void loop()

{

if(digitalRead(pushButton) == LOW)

{

digitalWrite(greenLedVehicle, LOW);

digitalWrite(yellowLedVehicle, HIGH);

delay(2000);

digitalWrite(yellowLedVehicle, LOW);

digitalWrite(redLedVehicle, HIGH);

delay(1000);

digitalWrite(redLedPedestrian, LOW);

digitalWrite(greenLedPedestrian, HIGH);

delay(5000);

digitalWrite(greenLedPedestrian, LOW);

digitalWrite(redLedPedestrian, HIGH);

delay(1000);

digitalWrite(redLedVehicle, LOW);

digitalWrite(greenLedVehicle, HIGH);

}

}



Green Led will turn on first , when button is pressed yellow LED turns on followed by red LED then returning back to the green LED being turned on.


b. Below are the hyperlink to the sources/references that I used to write the
code/program.

Brightspace: Maker UNO Edu Kit Module (traffic light)


c. Below are the problems I have encountered and how I fixed them.

I did not encounter much problems except for being careless with how I placed my resistors and I also removed 2 LEDs from the initial tutorial.


d. Below is the short video as the evidence that the code/program work.



5. Learning Reflection

coding - anything that had to do with the play of configurations on computer scared me . So imagine the intimidation that overtook me when i realised there were plenty of tasks i had to complete using Arduino . Starting with the pre-practical tasks , although codes were already given to us i still had trouble making it work , especially when i had to modify the codes and i was still faced with MULTIPLE errors in my codes . Trial and error along with plenty of youtube and Chat GPT searches did aid me a lot . So i completed the pre-practical tasks although it was not very successful , in-practical was even more hectic . Time constraint and the lack of knowledge did affect my partner a lot . But we didnt give up and eventually managed to code the push button which could only start the flapping but not stop it HAHA . The practical taught me that my foundation for coding was lacking badly . So the tasks for this blog overwhelmed me , but as i type this i am more than satisfied and i feel accomplished . I can now code and modify them to the required needs . I wont say i am good at coding , im barely there .However, the 2 days of effort did pay off . It was a collective effort ,my friend who had knowledge on coding was of tremendous help to me . He helped me with understanding the codes and setting-up the resistors and wires ! I can now say i am no longer afraid of coding and this experience has urged me to always try things before i conclude that it is difficult or impossible to comprehend . I came into Arduino clueless and although i am not the best , i leave wanting to know more about this application and the wonders it can do . I enjoyed the process of learning and figuring out Arduino :) and I am sure this skill will come in handy when I embark on my own projects and our Final Year Project.


If the videos above don't load please take a look at them in this google drive: https://drive.google.com/drive/folders/1-0fO_dsOmjKbybmR6cVUBsqB0mPnMbcf


With that, thank you for reading my blog!





 
 
 

Comments


bottom of page