top of page
Search

Arduino Programming!

  • Dec 8, 2024
  • 4 min read

Hello once again and welcome back to my blog! I hope the holidays are going well for you as the christmas season is upon us!! 🎅🎄🔔🎅



Although it may be the holidays now, the grind doesn't stop I am eager and hungry to learn more about Arduino programming🔥🔥🔥 You may be thinking, what are you talking about? What even is Arduino programming? Well, Arduino programming is an exciting way to bring electronics to life by combining hardware and software! 🤖✨ It involves writing simple code in the Arduino IDE to control components like LEDs, motors, sensors, and more, all connected to an Arduino board. With just a few lines of code, you can make an LED blink, measure light intensity, or even create your own mini robot! 🛠️💡 It’s perfect for beginners and pros alike, blending creativity and logic in a hands-on, fun way. Whether you're prototyping the next big invention or just tinkering, Arduino programming opens endless possibilities! 🚀


In today's blog, I will be sharing about 2 exercises I did, and go in-depth on the code I used as well as showing you the results of my work! I will be splitting this blog into 2 parts, input and output. Without further ado, let's get into it!


Input:


Beginning with input, my first activity was to interface a LDR to Maker UNO board and measure/show its signal in serial monitor Arduino IDE.


Here's the code I wrote for this action to be completed:


int ldrPin = A0; // Define LDR pin

int ldrValue;


void setup() {

Serial.begin(9600); // Initialize serial communication

}


void loop() {

ldrValue = analogRead(ldrPin); // Read analog value from LDR

Serial.println(ldrValue); // Print the value to Serial Monitor

delay(500); // Delay for readability

}



This code reads the light intensity from a photoresistor connected to Analog Pin A0 and displays the values in the Serial Monitor.

  • analogRead(ldrPin) reads the voltage from the photoresistor, which changes with light intensity.

  • Serial.println(ldrValue) sends the readings to the Serial Monitor, helping you visualize how light levels change.

  • delay(500) creates a 0.5-second pause between readings for easy observation.




I referenced the code from the previous SDLs i went through in previous weeks, and I ran it through ChatGPT to ensure that the code I wrote was able to be applied without any issues!









An issue I faced was that because I initially did not use a secondary website/source to verify my code, it kept getting rejected whenever I typed it into the software, and I got frustrated😭 I then decided to use an AI software to check my code, and I was able to see that I did not add in the closed bracket symbol (}) to the end of my codes😅



Here's a video showing how it works! :





As you can see, although initially the number from the photoreceptor remained stationary at 54, when the amount of light received was fluctuated, the number spiked drastically, and when the amount of light kept changing, the number reflecting the amount of light read by the photoreceptor also changed.






Output:


For output, the activity was to interface 3 LEDs (Red, Yellow, Green) to Maker UNO board and program it to perform an action, as well as using the pushbutton on the Maker UNO board to start/ stop the action.


Here's the code I used for the output action:


int redLed = 8;

int yellowLed = 9;

int greenLed = 10;

int buttonPin = 2;

bool isRunning = false;


void setup() {

pinMode(redLed, OUTPUT);

pinMode(yellowLed, OUTPUT);

pinMode(greenLed, OUTPUT);

pinMode(buttonPin, INPUT_PULLUP);

}


void loop() {

if (digitalRead(buttonPin) == LOW) {

isRunning = !isRunning;

delay(300); // Debounce delay

}


if (isRunning) {

digitalWrite(redLed, HIGH);

delay(1000);

digitalWrite(redLed, LOW);

digitalWrite(yellowLed, HIGH);

delay(1000);

digitalWrite(yellowLed, LOW);

digitalWrite(greenLed, HIGH);

delay(1000);

digitalWrite(greenLed, LOW);

}

}


Once again I used the previous SDL excercises and ChatGPT to verify my code.



To be honest, I was stumped and it took me several attempts to even just get 1 LED turned on😭😫 Eventually, I managed to get the 3 LEDs blinking in sequence, but then the problem was that the push button would not work! After numerous attempts, I once again turned to ChatGPT to help me resolve the code🥴 It was made clear to me that the code was not working as I did not assign the push button a pin in the code, so when I pressed it while the code was active, it did not have a signal to go to! This is definitely a valuable lesson that I've learnt and I'll make sure to keep an eye out for sch errors in the future🤠🤠


Let me show you the video of how the action was performed! :






Working on these Arduino programming tasks has been an incredibly rewarding experience! 🛠️✨ Through hands-on practice, I’ve learned how to integrate hardware and software to create functional circuits that interact with the real world. From reading inputs like light intensity using a photoresistor to controlling outputs like LEDs with a simple pushbutton, each project challenged my understanding and expanded my skill set.

One key takeaway was the importance of debugging—both in the code and the circuit setup. There were moments when the circuit didn’t work as expected, and I had to systematically check connections and logic. This taught me patience and persistence, skills that are valuable beyond electronics. 🧩💪

I also appreciated how intuitive and beginner-friendly the Arduino platform is. Writing code to control components felt empowering, and seeing immediate results on the simulation or hardware was highly motivating. The process of translating ideas into actions reinforced the practical application of programming concepts.

Overall, this journey into Arduino programming has sparked my curiosity for exploring more advanced projects, like combining sensors, displays, and motors to create interactive systems. It’s amazing how a small board like the Arduino can unlock so much potential for creativity and innovation. 🚀🎉

 
 
 

Comments


Drop Me a Line, Let Me Know What You Think

Thanks for submitting!

© 2035 by Train of Thoughts. Powered and secured by Wix

bottom of page