Challenge Week 6 Iron Chef Motor Resistor

1. Explanation of the project- Create a project using the motor and transistor. My challenge has a motor that is controlled by a POT. When turned up, it turns on an LED and when turned down it turns the other one on and the first one off. 

2. Code





3. Picture of the circuit including Arduino and Breadboard



4. Electronic Diagram: 


5. Video Explanation: 



6. Challenge Thinking:

I started by just getting the motor and the resistor set up. Once I got my board set up, I started on the code. I started with the MotorOnThenOff code, which turns it off and on like a blinking LED. I typed in all typed in all the code and got an error message that no port was provided. It kept saying to choose a port. I guess my computer has finally reached its limit. I had actually bought a new one and was waiting until this class was over to start using it since all my ardurino program was already on my old one. I had to go ahead and download it to my new computer. Once I did that, I opened a new sketch, typed in all the code again, then hooked up my board, and uploaded my sketch.  I did not work, so I double checked my board. It turns out after some looking online, my kit came with a MPS 2222A resistor but the code called for a P2N222A. It says if I flip it backwards it should work because the MPS is emitter base collector and the P2N is collector base emitter.

Video Motor:





 Then I thought back to all the projects we had done, and it took me a while to think about what I could add to my motor. After reflecting back to all the projects, I really liked controlling the LEDS with the POT. So, I decided to first try to control my motor with the POT, then try by looking at my POT LED code to put all 3 together. 

I added all the wires to the board for my POT, connecting it to A0, anode and diode. For the code I added the analog, sensor val,  and output. To connect the Pot to the sketch I added SensorPin A0. The pinMode needs to stay pinMode (motorPin, OutPut) Then  add the void loop like from the POT  LED but repalce the LED pin with the motorPin! The I took out the rest of the Motor code. It compiled. I tried adding a pinMode sensorPin, INPUT to the set up. It did not work. Time to turn to the internet. I found circuitdigest.com https://circuitdigest.com/microcontroller-projects/dc-motor-speed-control-using-arduino-and-potentiometer

They did not have a resistor connected to the diode. I checked the POT with an LED and it worked. I rewired it like the diagram I found on the website but it did not work. 

Video Attempt with motor and POT:



I found code on instructables.com that had a motor, POT, and 2LEDS. I am going to try that now. 

I added all the wires and typed in the code. I was right with all the setup with the integer pins ( analog, sensor Value, output Value, and a transistor pin) Each pin needed a pin mode OUTPUT. For my loop I put Sensorvalue to analog read, output value to Map sensor Value, analog Write with transistor pin and sensor value, and an if sensor value and else value. My wires I Kept my wires for what I orginally had for the Motor and Transistor, then added the POT to A0 again, and the LEDs with resistors  connected to digital ports. I compiled it and noting happened, then  I realized I had switched the motor pin and then POT pin ports. I was able to control the motor with the POT, but my LEDs were not lighting up. I realized I needed to add the inialize the LED pins in my setup and also forgot you have to name one ledPin2. It still did not work, so I double checked the code and I realized I did not have my digitalWrite for my LED pins opposite, I had the same ones on HIGH and LOW. I tried it again, and they still did not work. Then I realized the LED pins were not connected to the negative ground power, so I added wires to connect those. With out power they will not turn on! I gave them power and it all works. 

I then realized that I could take out the LED code to make my POT just control my motor turning on and off, so I did that and it worked. 

Here is the code:



Video POT controlled Motor:



7. Final reflection: This one threw me for a loop. I really struggled with the entire project from the beginning to the end. I really thought I would easily be able to do this because when I tried to add the POT to the multiple LEDs, I got it on my first try and really understood the code and board. Once, I was able to finally create a project by combining several different challenges we have completed, I literally shouted woo hoo when I got it to work. It finally all made sense. As this is my final Arduino project, I have really enjoyed all the projects we have done.  I have learned so much from completing these and even more from having to combine projects together this week. I have definitely come out of my comfort zone and have accomplished much more than I ever imagined I could do with coding! Before starting this class, I was worried about how I would complete the challenges each week and honestly thought I would have to drop the class. Now, I have gained a great deal of knowledge, and cannot wait to share this type of making with my students. At times, I really tried to look at things through my students eyes and think how they might try to figure a problem out. I realized that we do have to help each other out, and this is something I really encourage in my classroom. I am always having my students share their ideas with each other before they ask me or share with the class. They learn so much from each other and I have learned so much from my peers during this course. 

8. Extensions: An extension of this would be a race car that is controlled by a remote with lights that turn on and off with the speed. 

Comments

Popular posts from this blog

Challenge Week 5 Photo Resistor