Introduction
Hi everyone! I was gone for some time being busy with my finals, but most of them passed, so I finally have some free time. In the meanwhile I did some research and reading on connecting the Raspberries via Bluetooth as well as a custom gamepad controller for my project, but all of that will come in the later updates. For this update I have another head module! This is the second module I've made so far and it is the head type again. There will probably be one more head module, which will house the Raspberry Pi camera, but that will come a little later. The last module was focused on detecting the distance using the ultrasonic sensor, as the name suggests this module will be focused on light!
Functionality
This module is focused on light. In terms of its functionality it is much simpler than the last module. The module detects is the major light source from. To achieve this I used 5 standard photoresistors places in five corners of a regular polygon. There are 2 output wires. One of them is 1 and the other is 0 if for example the light source is one the left of the leading sensor, if it's on the right, the first one would be 0 and the second one would be 1, if its centered within the tolerances the output signal for both wires is 1.
Design
I took a similar approach when it comes to the design, but a different when it comes to how I made it. While in the first one I went with 3D printing, for this module I went all hand made. For the outer shell I firstly wanted to go with a light bulb head again as I did for the first module, but I had trouble finding a transparent light bulb that wasn't made out of glass, which obviously was a no. So I went to the local supermarket and just went through all of the aisles looking for products in small transparent plastic containers. I bought a few which seemed the appropriate size and went home to test and see which one would work. Another thing to keep in mind is that I had follow some guidelines which I've set with the first module, those guidelines are mostly focused on connector placement and what is connected to what part of the connector, since my goal is to make these modules plug n play with the rest of the system. So i pulled up the pictures of the wiring I had taken last time on the ultrasonic head module and copied it for the most part on the light head module. Now, let's start of with the materials since they give us some guidelines on how the module can look and than go to the looks and the construction of this module.
Materials
Here is a list of all of the materials I will be using in this build, besides the one underneath I am also using the standard 3mm thick plywood which is used in schools.
{gallery} Materials |
---|
Q tips package: This is the best thing I've found in the supermarket as the shell for the module, it is made of pretty transparent plastic, its not as strong as I would like to, but its pretty flexible unlike some other things I've tried so no cracks will appear if it falls or something similar happens to it. |
LED-s: What project is complete without some LED-s, specially a module that is based around light, the LED-s will mostly be used for looks but will also have some functionality to it! |
Potentiometers: I love these potenitometers, they are really small with and I can just glue them to the walls of anything and just drill a small hole so you can use it. I will be using 2 of these, I already described the function of the first one, while the second one will be used for some animations which we will see later in this blog! |
Arduino Nano: Just like last time, the brain for this module will be a small, low cost, Arduino Nano. The Nano will handle of the sensors as well as the outputs, it will be powered through the 3.5 mm pins just like the first module. |
3.5 mm connectors: As I've said, to keep up with the footprint of the last module I am again going with the 3.5 mm connectors, 4 of them to be precise. |
Push switch: This is a small switch I got when I took apart an old speaker, the important thing is it functions like a switch, and not a button. |
Button: A standard small button, which has a thread on itself so you can use a nut on it. |
Bottle cap: This is what I'll be using as the top of the button, of course, it needs a painjob! |
Photoresistors: The main sensor in this module, the photoresistor, I will be using 5 of these guys connected to the Arduino Nano. |
Experimental Board: I used some pieces that I had laying around, besides the single point ones I also used the ones where the 3 adjacent dots are connected, but the first kind is more than enough. |
Machine screws and distancers: I went with 3 mm for this module, mostly because I had a lot of them around, as for the distancers, I went with metal ones that are both 15 mm and 20 mm. |
Wires: And of course to connect it all together, a lot of wires, as well as some 10k and 220 ohm resistors. |
Looks
Now let's get to the looks of this module. The shape of it is of course determined by the Q tips packaging. The diameter of it is a bit bigger than that of the light bulb I previously used, but nothing to drastic. I was thinking of cutting it down a bit, but in the also stuck with the height of it. Firstly let's turn it upside down. I will try to utilize the already existing cap as an easy way to access the electronics when the module is finished if anything is needed. One of the things I want to do is give some character to it, and since it is a head module, it needs a face. I could have went with the easier route of just mounting the sensors, but since I am trying to design this to be attractive to kids it needs to look like a toy. To accomplish this I planned on adding a mouth which will consist of 5 LED-s which can be animated, as well as 2 eyes which will have bright white LED-s which will have functionality of a standard light on the robots that can be built with this module. I will get into the animations later on, but I wanted to allow the user to control them in 2 different ways. Firstly to choose which animation they would like to perform, this will be done with a big red button on the top of the module (this is where the bottle cap comes in), as well as the second potentiometer which will be used to determine the speed of the animations. Of course since it is all controlled by an Arduino, the user can always go and write their own animations for the 5 LED-s. As for the eye LED-s, they will be part of like mask that will sit on the front of the module, the mask will be connected to the push switch I listed in the materials, so by pressing the mask on the module the user can activate the headlights of the module. Of course this all needs some color here and there, mostly yellow to stay in the theme with the last module as well as some other stuff I have prepared for later on! Now there's only one small thing left and that is to make all of this, so let's go!
Construction
To make it easier on myself, I've split the construction into a few individual parts, which will then need some minimal altering to fit together:
- Crown - This holds the top mounted button as well the photoresistors
- Cap - This is the bottom part of the module which holds the connectors
- Eyes - The headlight LED-s
- Mouth
- Assembly
Crown
This is the first thing I started making was this crown, of course since the crown is the part that holds all of the photoresistors, I firstly had to wire up a small test and test a simple version of the program which would detect the direction of the light source, so let's start with that, and then continue on to the construction itself.
Light Source Detection
Here is how I wired up this part of the build:
All of the photoresistors all connected to the analog pins on the Arduino as shown in the schematic, as for the the 3 "free" wires that can be seen in the picture, I've used them to test out the program on a small jig I've made out of an Arduino Uno, a servo and a small plastic box. But first let's go to the software:
void setup() { pinMode(A1, INPUT); pinMode(A2, INPUT); pinMode(A3, INPUT); pinMode(A4, INPUT); pinMode(A5, INPUT); pinMode(4, OUTPUT); pinMode(6, OUTPUT); Serial.begin(9600); } int l[10], maximum; void loop() { // put your main code here, to run repeatedly: l[0] = analogRead(A5); l[1] = analogRead(A4); l[2] = analogRead(A3); l[3] = analogRead(A2); l[4] = analogRead(A1); Serial.print("Sensor 1: "); Serial.println(l[0]); Serial.print("Sensor 2: "); Serial.println(l[1]); Serial.print("Sensor 3: "); Serial.println(l[2]); Serial.print("Sensor 5: "); Serial.println(l[3]); Serial.print("Sensor 5: "); Serial.println(l[4]); Serial.println("______________________________________"); delay(500); maximum = 0; for (int i = 1; i < 5; i++) { if (l[i] > l[maximum]) { maximum = i; } } switch (maximum) { case 0: if (-15 <= l[1] - l[2] <= 15) { digitalWrite(4, HIGH); digitalWrite(6, HIGH); } else if (l[2] > l[1]) { digitalWrite(4, HIGH); digitalWrite(6, LOW); } else if (l[1] > l[2]) { digitalWrite(4, LOW); digitalWrite(6, HIGH); } break; case 1: digitalWrite(4, LOW); digitalWrite(6, HIGH); break; case 2: digitalWrite(4, HIGH); digitalWrite(6, LOW); break; case 3: digitalWrite(4, LOW); digitalWrite(6, HIGH); break; case 4: digitalWrite(4, HIGH); digitalWrite(6, LOW); break; } }
This is the first version of the code I am using on this module, and even though it's extremely simple, when there is a strong light source it really works great. The way it's programmed is it reads the values from all of the photoresistors (It is important to use the same photoresistors, before hand even though they are all the same I went and compared them one to another and also looked at the stability, and they were all in the range of +/- 5 of a certain value, but just to be safe I went with a tolerance of around 15, all of this can of course be adjusted by the user), when it reads all of the values it determines which one has the maximum value, and depending on the position of that sensor relative to the leading sensor it sends either a signal to go left, or a signal to go right, but if the first (leading) sensor has the maximum value of them all, the program goes on trying to balance out the adjacent ones to get the best possible accuracy. I will probably upgrade this program by comparing all of the values in the first place and sensing if there are maybe multiple strong light sources, or is the room just too evenly lit for the module to give a good call for the direction. Here is a short video of me testing out this part of the build. The code on the second Arduino is to turn the servo by 5 degrees to one side or the other depending on the signal.
As you can see this setup works pretty well, now it's time to mount all of this and more into the module:
Build
Let's start of with the base of this, an experimental board, to fit inside the shell it needed to be round, as for attaching to the shell, the shell already had 3 holes drilled in it, so I used those with screws and distancers, here is how the build went:
{gallery} Crown Build |
---|
Experimental Board: Firstly I cut out a rough circle shape using a small hand saw, I cut it just about so it can fit, but now let's go over to refining the shape. |
Refining the shape: To refine the shape I drilled a whole through the center of the circle I've cut out and mounted it using a screw and a nut to the drill. Then I just hit some sand paper with it until I was happy with how it all fir together. One more thing I did is mark where the holes are on the outer shell and drilled them out for the mounting screws to fit. |
Test Fit: Here is a picture of a test fit I did to see how it worked out before mounting the sensors and the button. |
Button: I've colored the bottle cap red, so it just looks inviting to press, I didn't have this kind of a size for the drill bit, so I went on and drilled a lot of tiny holes in a circle and just refined the edge afterwards using a dremel. |
Test Fit 2: Here we can see the second test fit with the whole button. For mounting the button I just widened the hole I used for refining the shape, put on the nut over the button and that was that. As for mounting the bottle cap on top I went with a pretty straight forward method, I filled the bottle cap entirely with hot glue, when it cooled off I hit up the center of it again and pushed the actual button top into the button. I did this while the small button was mounted on to the shell, to assure that the bottle cap move freely, since my measurements weren't perfect, this was a great way to make it all work together. |
Soldering: Now comes the part of soldering all of that together and running the wires down to be connected to other parts.(IMPORTANT NOTE, this picture is badly soldered which I found out later, the wires from the sensors need to before the resistors, and not after) |
Finished Crown: And here in the end we can see how the finished crown looks! |
That would be the whole build of the crown. I've made a small mark with marker on the board to which sensor is the leading one, to know how to connect them later on to the Arduino. These are all of the sensors that will be inside this module, but again, I want to give it some character so it needs a cool looking enclosure! Next up is the Cap.
Cap
I wanted to keep the functionality of the cap as is, in other words I wanted it to pop into place when closing it, but I also had to mount the 3.5 mm connectors to it. The cap is made out of same plastic as the rest of the container so the plastic is pretty thin and flexible, while that doesn't affect the outer shell, I wanted to reinforce the cap a bit. To do that I cut out a small piece of plywood and attached it with screws to the plastic cap. I then drilled the holes for the 3.5 mm connectors in both the cap and the plywood and drilled some additional holes for the distancers for the later coming inner structure. It was much more tedious to put in the connectors than the last time. When I was putting them last time I would just melt the plastic a bit and push in the connector which proved to be really precise and extremely easy to do. That wasn't the case here since I had a wooden layer. I had problems from drilling too small holes to widening them so much that connector falls in, but in the end I reinforced the connectors with some hot glue so everything is really sturdy right now. The precision isn't as perfect as the 3D printed part, but will work without a doubt, here are the pictures of the construction of the cap part!
{gallery} Cap Build |
---|
Cap Build 1: The plywood insert |
Cap Build 2: Soldering |
Cap Build 3: Hot glue reinforcment |
Cap Build 4: Underside |
Cap Build 5: Balancing the Ultrasonic module on the pins of the new module, it's not perfect but it's pretty good! |
That would be it for the cap build, it's pretty simple, with nothing too special to it, the only thing it required was some precision when it comes to the connectors. I managed to keep the cap snapping on to the outer shell. That would be 2 down and 4 more to go. So let's go to the eyes.
Eyes (Headlights)
This is the first part based of LED-s. It is the simpler one of the 2. It's mounted directly to a switch, so to activate it you have to press the mask which activated the headlights. For the headlights I used 2 really bright white LED-s so they shine really good! To make this I used thin plywood where I layered 3 pieces as a base for everything. To that I mounted to pieces of a black plastic pipe, put the LED-s in and some clear plastic over it. To mount it, I drilled a hole halfway through and just glued in the speaker switch. Here is the build process:
Build
{gallery} Eyes Build |
---|
Mouth
This is the second part based on LED-s the mouth of the module. In the core of it are 5 small red LED-s, which are connected to the digital pins on the Arduino. The first module had the option of changing the actual antennas which were small LED-s, the idea here is to have unlimited options and alter this segment using software or the button and potentiometer. This part of the build will utilize the big red button on top of the head. The big red button will be used to go and cycle through all of the animations. But before we get into the animations them selves we need to make the module first.
Build
To do this I used a small 12x12mm wooden plank. I drilled holes through one side of it wanting to make space for the LED-s to sit in. Since I was drilling pretty big holes compared to the thickness of the plank all the way down pretty much I expected it to break in half at one point, and it did!!! I could have got another piece and started over being slower and more delicate, but I decided to stick with this one since I can now hand file it down easier, when that was done I put the two pieces back together, the LED-s inside, and filled the hole with hot glue. I could have just used super glue or wood glue to glue the wood, but I precisely wanted to go with the hot glue since it went all around the LED-s and make a great diffusion effect on the lights. For the finishing touches I used some black electrical tape to tidy it up as well as piece of clear plastic which went in the front. Here are the pictures of the build:
{gallery} Mouth Build |
---|
That would be it with the build of this part, the only thing left is connecting it to the rest of the module, as I've said it will be using the big red button from the crown, as well as a small potentiometer which will be mounted on the back of the module.
Animations
First off all we need to connect it to the Arduino Nano, here is the schematic for that:
This is something that can easily be altered by the user, adding different animations, or just altering the already loaded ones. There are few things we need to consider in programming the animations. Animations are easily made using the delay function on the Arduino, but because we use a button to switch between them we need to listen for the button press during the delay, as well as adjusting the timing with the potentiometer. To overcome this instead of delay I used millis, which is a function that returns the number of milliseconds from powering the Arduino. I programmed 5 animations on it:
- All off
- All on
- All blinking - Blinking adjusted by the potentiometer
- Going from side to side - Speed of it adjusted by the potentiometer
- Starting from both ends and "bouncing" from the middle - Speed of it controlled by the potentiometer
void setup() { pinMode(2,OUTPUT); pinMode(3,OUTPUT); pinMode(4,OUTPUT); pinMode(5,OUTPUT); pinMode(6,OUTPUT); pinMode(8,INPUT); pinMode(A0,INPUT); digitalWrite(2,LOW); digitalWrite(3,LOW); digitalWrite(4,LOW); digitalWrite(5,LOW); digitalWrite(6,LOW); Serial.begin(9600); } int val,x,t,button=1,a=0,t0,button_state,lastbutton_state=0; int buttonAndDelay() { t0=millis(); while (millis()-t0<=t) { x=analogRead(A0); val=constrain(x,500,1000); Serial.println(val); t=map(val,500,1000,25,200); button_state=digitalRead(8); if(button_state != lastbutton_state) { if(button_state) { if(button==5) button=1; else button++; lastbutton_state=1; return 1; } lastbutton_state=0; } } return 0; } void loop() { x=analogRead(A0); val=constrain(x,500,1000); //Serial.println(val); t=map(val,500,1000,25,200); switch(button) { case 4: digitalWrite(2,LOW); digitalWrite(3,HIGH); a=buttonAndDelay(); if(a) { a=0; break; } digitalWrite(3,LOW); digitalWrite(4,HIGH); a=buttonAndDelay(); if(a) { a=0; break; } digitalWrite(4,LOW); digitalWrite(5,HIGH); a=buttonAndDelay(); if(a) { a=0; break; } digitalWrite(5,LOW); digitalWrite(6,HIGH); a=buttonAndDelay(); if(a) { a=0; break; } digitalWrite(5,HIGH); digitalWrite(6,LOW); a=buttonAndDelay(); if(a) { a=0; break; } digitalWrite(5,LOW); digitalWrite(4,HIGH); a=buttonAndDelay(); if(a) { a=0; break; } digitalWrite(4,LOW); digitalWrite(3,HIGH); a=buttonAndDelay(); if(a) { a=0; break; } digitalWrite(3,LOW); digitalWrite(2,HIGH); a=buttonAndDelay(); if(a) { a=0; break; } break; case 3: digitalWrite(2,HIGH); digitalWrite(3,HIGH); digitalWrite(4,HIGH); digitalWrite(5,HIGH); digitalWrite(6,HIGH); a=buttonAndDelay(); if(a) { a=0; break; } digitalWrite(2,LOW); digitalWrite(3,LOW); digitalWrite(4,LOW); digitalWrite(5,LOW); digitalWrite(6,LOW); a=buttonAndDelay(); if(a) { a=0; break; } break; case 2: digitalWrite(2,HIGH); digitalWrite(3,HIGH); digitalWrite(4,HIGH); digitalWrite(5,HIGH); digitalWrite(6,HIGH); a=buttonAndDelay(); if(a) { a=0; break; } break; case 1: digitalWrite(2,LOW); digitalWrite(3,LOW); digitalWrite(4,LOW); digitalWrite(5,LOW); digitalWrite(6,LOW); a=buttonAndDelay(); if(a) { a=0; break; } break; case 5: digitalWrite(3,LOW); digitalWrite(5,LOW); digitalWrite(2,HIGH); digitalWrite(6,HIGH); a=buttonAndDelay(); if(a) { a=0; break; } digitalWrite(3,HIGH); digitalWrite(5,HIGH); digitalWrite(2,LOW); digitalWrite(6,LOW); a=buttonAndDelay(); if(a) { a=0; break; } digitalWrite(3,LOW); digitalWrite(5,LOW); digitalWrite(4,HIGH); a=buttonAndDelay(); if(a) { a=0; break; } digitalWrite(3,HIGH); digitalWrite(5,HIGH); digitalWrite(4,LOW); a=buttonAndDelay(); if(a) { a=0; break; } break; } }
Here is a video showcasing all of the animations and controls for them!
Assembly
Now that all of the smaller parts are done, all that's left is to alter the outer shell a bit and solder everything together. Most of the things came together with screws but some parts needed to be glued. The only other thing that needed work is the outer shell which needed some cuts and holes here and there. Also adding the potentiometer by using some glue on the crown part.
And it the end I ended up with this:
(The module is a bit rough because I had to take it apart, which will be explained in the next section)
FUN
And now we come to the last part which I called fun, this will also explain why this is the first part of this module. I was extremely happy with how the final assembly went, with all of the soldering, it even showed some signs of life from the source of light detection program, so there was one last thing left to do, and that is try out if the animations work, so naturally plugged in the board and clicked upload, when:
I looked for solutions all over, and nothing worked, if anyone has any suggestions please tell me, but for now, the plan is to get a new Arduino Nano, and just solder it all together again, which isn't that big of an issue. What exactly happened with the board i really don't know, this issue can be caused by multiple reasons, from RX and TX pins being connected to something to the chip itself just being dead, I also tried methods with pushing the button when uploading the empty sketch and most of the things I've read online, but none of them worked for me unfortunately. This is where the story of the light head module ends for now! I will certainly finish it in one of the upcoming blogs.
Summary
Everything was going great but in the end what happened happened, and ill work on fixing it. Since I used a 3D printer last time, I wanted to try all handmade this time, and while I love making things by hand, the 3D printer is an extremely powerful tool, which would have sped up this module a lot, and made it look much nicer, so in the second part for this module I might go with some 3D printed parts to go with the rest of it that is already finished, specially around the mouth part, since the only way I can attach that is by using glue. But in the end I am happy with how the parts that worked turned out, now it's time to get down to bluetooth. I will follow up this pretty soon with connecting the Raspberries while this will have to get pushed a bit back while get back on track with the blogs. Thanks for reading the whole blog, hope you like it!
TO BE CONTINUED...
Milos
Top Comments