DIY PROJECT
This INSTRUCTABLE will go through my ENTIRE DIY PROJECT and each step of the journey and process. I will also be stating what type of resources and supplies you will need to build your DIY project ( That is similar to mine ). My DIY Project is basically a simple game that can be played with two players. It basically asks a question and it waits for one of the LDR ( Light Dependent Resistant ) to be covered. The LED will turn on, and this will allow either player 1 or player 2 to answer a true or false question. After it goes through all the questions, the game is complete.
Supplies
The Supplies Needed Are:
BreadBoard
Raspberry Pie
Cardboard
Tape
Markers
Male Male Wires
2 LED ( Different Colours )
2 Resistors ( 330 K Ohm )
2 LDR Sensors
2 10 V Capacitors
2 Caps to cover something.
First Step ( Putting Together the Circuit )
Let's go through the process of building the circuit together
Before we do this quickly review the supply list to see what you need to set up this complex / basic circuit
Now that you have everything let's start
First of all put your two LDRS and Capacitors together and make sure they work with code
Connect the LDR to the Negative part of the Capacitor ( For both ). After doing this, connect the other leg of both LDRS to power ( 5 Volts ). After this connect the leg of the LDR connected to the Capacitor to a GPIO Pin ( For me in this case, it is GPIO 5 Player 2 and 16 Player 1).
Then connect the other leg of the Capacitor to ground ( Both Capacitors ).
This is how you set up the LDR, now connect the Two LEDS and make sure they work with code as well.
Connect the Negative Leg OF the LED to ground ( Both ). After this, connect the positive leg of both LEDS with a 330 Ohm Resistor, and then connect that resistor to a GPIO Pin ( In this case GPIO Pin 19 Player 2 and Pin 12 Player 1 )
After this your circuit should look something like the picture I have here ( Ignore the circuit beside it )
Second Step ( the Code )
Making the Code will be the more difficult part of this DIY Project, so follow along carefully
First of all write all import LED, LightSensor and Sleep:
from gpiozero import LED, LightSensor
from time import sleep
Then Import your variables
LDR1 = LightSensor (16,5,1)
LDR2 = LightSensor (5,5,1)
LED1 = LED(12)
LED2 = LED(19)
Now Make Your First Question to make the Question Appear and having the Player 1 or 2, cover their sensor to turn their LED on, this will look like this:
print("Ram and Rom are the same thing")
while True:
if ldr2.value == (0):
print("Player 1 Answer:)
led2.on():
answer=input ( "True or False")
if answer == "F" ( Or T depending on the question )
print("Player 2 you are correct!)
p1() ( This will be important later )
else:
print("Sorry, Incorrect")
p1()
Do the same with Player 2 ( Just have to Change 1 to 2 )
while True:
if ldr1.value == (0): print("Player 1 Answer:) led1.on(): answer=input ( "True or False") if answer == "F" ( Or T depending on the question ) print("Player 1 you are correct!) p1() ( This will be important later ) else: print("Sorry, Incorrect") p1()
What p1() means is that, when doing this same code for other questions, the questions will be defined ( this basically means after answering the question it will go to that question. So for example:
The Next Question
def p1()
print('\n') ( This basically gives space between questions )
print("2.Best way to cool off a computer is to put it outside")
Then you would the same code with LDR ( Which is above )
Then you would instead put p2() instead of p1(), to go to the next question ( Of course using the define code in Python ).
And that is it. That is the Coding part of the Circuit to make everything work.
Putting It All Together ( With Testing and Launching )
After the circuit is done and the Code is done, launch and test your code and see if it is working, if it isn't then it might be a variety of these problems:
Faulty Breadboard or Bad Wires
LED is Broken or the LDR is not working properly
Something wrong with your code or circuitry
After doing testing and such, configure your code and make it as smooth as possible.
Now let's talk about putting it together
Get your supplies of Cardboard and Tape.
1. Cut the Cardboard enough for each side of the breadbroad, and then cut a sqaure for where the light resistor is so you can put your had over it ( For both Sides , and mark the square with a marker)
2. Cut Cardboard for the end of the Breadboard to have the box completed
3. Now you can run your game and play it.