The final circuit to build in the light-projects set combines everything learned in the first 3 circuits and more with the introduction of an RGB LED. As mentioned previously, the RGB LED has a different connection convention due to its four legs and, hence, 3 inputs (Red, Green, Blue). Different input combinations to the LED’s pins will allow for a wide spectrum of colours to be produced; this will be the focus of this circuit.

Transcript

Hey guys, it's Christian here from core electronics. Today we're going to be building the final circuit for Project Set 1 circuit 1D.

Now, what we're going to be doing in this circuit, is a combination of everything that we did in our previous circuits, plus we're going to be using an RGB LED, which is a red, green, blue, light-emitting diode. So as opposed to just being single coloured, like the red one that we've been using in the previous tutorials. We're going to be able to control the amount of red, green and blue that appears at that diode. So, it's slightly different to a normal diode, as you can tell in the guide, it has a red, a common or ground, a green and a blue pin. So, it's got a total of four pins instead of two. So, for this, we've got to make sure that we connect it the right way because although it's got a different polarity, the polarity is still polarity. So, with that said let's start building our circuit and get it underway.

So, as they demonstrate in the book it's probably a clever idea since we have red, blue and green jumper wires to use them appropriately to determine which colour is which. So, we're going to plug the RGB LED in first, we're going to connect using one of the red wires, through a 330 resistor. So, we're going to bridge E6 to F6, with one of those. We're going to bridge E4 to F4, with another one and once again we're going to bridge E3 to F3, with the other one. That way all the resistors are connecting through there to limit the current through each of the assorted colour segments.

So now that that's done we will connect the red jumper from J6 to Pin 9.
We will connect the ground from E5 to the negative power rail.
We will connect J4 to pin 10 using the green jumper.
And will use a blue jump up to connect J3 to pin 11.
Now the reason that we're using 9, 10 and 11, is so that we can output an analog write signal, which will become apparent later.

Okay, we're going to connect the potentiometer, once again we want the flat side facing the centre column and the top pin, we're going to connect to the positive rail of our bus. We're going to connect the bottom one to the ground bus and we're going to connect the middle pin to A1

Then we're going to have the same voltage divided that we did in the last project set, with the Photoresistor and the normal resistor.
So, we're going to connect A24 - C26 using the Photoresistor
And we're going to connect A26 to 30C or whatever really works for you guys, using the normal resistor.
Then the same convention we're going to connect the positive part of the Photoresistor to the positive power rail.
We're going to connect the other side of the normal 10k resistor to the negative power rail, and we're going to connect where they overlap or in row 26 for me to A0.
Then once that's done the only thing left is to connect the ground and power rails to ground and power.
So, we're going to connect that up there so ground to the negative rail and 5 volts through the positive rail.
Now that it's all connected, we can connect the red board to the computer and I'll run the program that was previously on there.

Now it's at this point an appropriate time to mention that down here on the tutorial page we have the Sparkfun Inventors kit code and that's linked to their website. I would highly recommend doing that for this Project Set here, just for this circuit because it is a hefty amount of code as you're about to see. So it's all more commented to which makes it really easy to read and understand but, essentially what's happening is we're getting a global variable up here called Photoresistor, it's saying that the Photoresistor is connected to A0, it's saying that the potentiometer is connected to A1 and it's saying the threshold that they are set for this is 700.

So, it's also defining pin assignments, so in the event where we need to change something later, they've said that Red Pin is Pin 9 and if we wanted to make Red Pin, Pin 8 along the way, instead of changing everywhere it says a red pin. What we can do is we can just call it red pin everywhere and then change it up here there's something else. So, 9, 10 and 11 is connected here, they're starting using the serial port so you're able to print data or print values, to the serial port to read what they're outputting and will refer to this in a second.

So, they've to find the pin modes for the red, the green and the blue pin which, 9, 10 and 11 respectively. Then they've read in the value of the Photoresistor and they've read in the value of the potentiometer. So, this is the loop in section, so it'll do that continually and essentially, we're going to print out to the serial port the value of the photoresistor and the value of the potentiometer. This is more for debugging purposes and to kind of see if your code doing what you want it to do. Then here they've got a conditional if statement and they've got a few of them that will run different functions. So, they've got a function called "red", a function called "orange", "yellow", "green", "cyan", "blue" and magenta and essentially all those are is different combinations of colours, using that pulse width modulation that was discussed earlier.

So pulse width modulation is a little digital trick, where a square wave with a different duty cycle, so instead of putting out five volts, if we want to put out two and a half volts, what we can do is we can analog write a value of 511 or 512 to the pin specified and what that's going to do is instead of having a constant 5 volts, it's going to have 5 volts for half the time and 0 volts for half at the time and digitally that will be averaged to 2.5 volts.

So here it's important to note that these are only 8-bit, it's an 8-bit microcontroller, so we go from 0 to 255 here. So, a value of 100 for a red, is what it's going to output and then it's going to put 0 green, 0 blue, for the red. Similarly, in orange, it's going to put out a hundred in the red, but now it's going to use 50 in green and 0 in blue and it's similar for all of these it's just different colour combinations, to create different colours.

The only change is where we use the turn off function. Now the turn off function happens if the light in the room, the ambient light is above the threshold. So here these run if it's below the threshold, if light is dark enough in the room but, if it's too light then it will run the turn off function, which is essentially just writing a zero value or an average of zero so no current, no voltage, to each of these pins which means that no light appears at the LED.

So, we'll just hit compile sketch folders disappear. Cool, so it's compiling the sketch and once it compiles the sketch, it'll upload it to the board and hopefully now that it's done uploading if we cover this to a certain extent, the lunch turns on. Currently, it's not.

So, what we can do is we can use the serial port to see what the value is at the Photoresistor. So, it's an 800 and it's dropping down, so it should be turning on but it's not. So, since we see that uncovered it's about eight hundred and covered it's about seven hundred and twenty, what we can do is we can change this threshold up here and by changing this threshold up here, what we can do is we can modify the code to work in this specific light setting. So, what I'm going to do is I'm going to change it from 700 to 750 to be safe and then we'll re-upload that and hopefully, this should output a value. So, it should light up a little easier and there we go we have a red light, if we change this dial and cover it again, we should get a green light and so on and so forth as we go across the board, so now I've got a cyan light. If I were able to cover it with one hand and twist it would change colour as it's done.

What we can do here, the beauty of microcontrollers is we can reverse this sign here to show you what it means. So now it'll only turn on if the light is above the threshold. So now it's not a Nightlight, it's just an ON light.

So, uploading that we get a cyan light and as we scroll across it changes, so we have magenta, then we have blue, then cyan, then green, then yellow, then orange and then red.

So that their guys are our final circuit for Project Set 1. If you have any questions or comments please consult our forum and get in touch with us and I'll do my very best to help you guys out. I hope you enjoyed this video and we will see you guys in the next project set which is sound.

Catch you later.

Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.