Arduino: a revamped tiny Sketch

Couple of days ago I wrote a post about how I got started with an Arduino UNO and wrote my first Sketch (a Sketch is an App written using Arduino IDE and and uploaded to the board via Serial). Click here to read it.

The Starter Kit had an LED attached to a a very small PCB with four pins. Picking it up I realized it was an RGB LED with three resistors printed on it. Neat!

IMG_20151227_085209
RGB LED board

I knew what I wanted to do with it.

Adjust RGB

This sketch is a follow up to my last one ‘AdjustBrightness.ino’ and allows you to pick what colour you want the LED to be! Like this colour (one of my favourites), for example:

IMG_20151227_090442
Turquoise Green LED

What you need:

  • Arduino or Genuino Board
  • 10k ohm potentiometer
  • RGB LED with resistors
  • hook-up wires
  • 4 male to female jumper wires

No need for a breadboard!

IMG_20151226_130208409

Connect the pins on the LED board to the Arduino:

  1. R -> 9
  2. G -> 10
  3. B -> 11
  4. (-) -> GND

Connect three wires from the potentiometer to your board:

  1. to ground from one of the outer pins of the potentiometer
  2. to 5 volts from the other outer pin of the potentiometer
  3. to analog input 0 from the middle pin of the potentiometer

IMG_20151226_130157617

You’re good to go …

What about the code? Since I didn’t want to take up much space here, I put it on a GitHub repo. Find it inside the ‘AdjustRGB‘ folder.

IMG_20151226_125136620
Powering it from batteries

That’s it for now. Hope you find it useful …

Advertisements

Arduino: a tiny Sketch

A friend of mine gifted me an Arduino UNO starter kit a while ago. I didn’t have the time and motivation back then to dabble in it.

Fast forwarding to this day, I watched Massimo Banzi’s TED Talk in the morning, one of the guys who helped invent the Arduino. It was inspiring.

So, what is it anyway? Arduino is a credit-card sized micro-controlled board that can be be used for a whole lot of purposes,  so much that one could dedicate his life on researching the everyday potential of it.

IMG_20151222_243554612

IMG_20151222_243624450

The beautiful thing about this tiny device is that it is so easy to get started once you have the starter kit. In fact, I only started in the morning. Even more beautiful is that the whole project is open-source, from the hardware to software to everything in between. You could even make your own board!

What can you do with it? Like I said, the possibilities are endless. Many tech startups (and older ones) use this as a rapid prototyping tool. Pebble designed their awesome smartwatch using this, for example.

For starters, its good to try out stuff with LEDs. In fact, that’s exactly what I did.

Adjust Brightness

My tiny project is in fact a mashup of two examples that are provided by Arduino themselves. It ‘Works just like the light dimmer at you home!’

This is one of the easiest projects you could find. The reason I am sharing this information with you is to illustrate how simple it is to get started.

What you need:

  • Arduino or Genuino Board
  • 10k ohm potentiometer (that dimmer thing)
  • LED
  • 220 ohm resistor
  • hook-up wires
  • breadboard

Connect three wires from the potentiometer to your board:

  1. to ground from one of the outer pins of the potentiometer
  2. to 5 volts from the other outer pin of the potentiometer
  3. from the middle pin of the potentiometer to analog input 0

Next, you have to connect the anode (the longer leg) of your LED to digital output pin 9 on your board through a 220 ohm resistor. Connect the cathode (the shorter leg) directly to ground.

IMG_20151222_071834837
The whole thing could also be powered by a battery back of six 1.5 V cells.

And here is my AdjustBrightness.ino code:


/*
  Adjust Brightness - Works just like the light dimmer at you home!
  
  A little sketch I came up with after going through a couple of examples.
  This code receives the analog sensor value of the potentiometer from analog pin 0 
  and uses this value to set the brightness of the output of pin 9.

  Based on the following example projects:
  Read Analog Voltage - https://www.arduino.cc/en/Tutorial/ReadAnalogVoltage
  Fade - https://www.arduino.cc/en/Tutorial/Fade

 created  21 Dec 2015
 by Muhammad Muhsin
*/

const int ledPin = 9; //the pin that connects to the LED
int brightness; //stores the brightness level of the LED
int sensorValue; //stores the analog input from the potentiometer

void setup() {
  // initiliaze the PWM pin as an output
  pinMode(ledPin, OUTPUT);

  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

void loop() {
  // read the input on analog pin 0
  sensorValue = analogRead(A0);

  //brightness ranges from 0 - 255, so
  brightness = sensorValue / 4;

  //for monitoring purposes
  Serial.println(brightness);

  //light up the LED
  analogWrite(ledPin, brightness);
}

What I learned

Apart from the obvious knowledge one gains from working with an Arduino, I saw that there is great potential, especially for children! I think this would make for an excellent hobby for anyone with the willingness!

Like Massimo Banzi  says, “You don’t need anyone’s permission to make something great.”