HOME BY THE CURFEW | DIORAMA
by amberhalvemeter in Circuits > Arduino
182 Views, 0 Favorites, 0 Comments
HOME BY THE CURFEW | DIORAMA

Home by the curfew is a game of chance programmed on Arduino.
You push the button which causes the motor and the dial to start spinning. The lightsensor is placed at the top of the clock so 12 o clock. The purpose of this game is to stop the dial at 12 o clock. If you succeed in doing this, an LED lights up.
Due to corona virus in Belgium we had a curfew starting midnight, that's why the game is called Home by the curfew.
Little side note: the ldrValue is a variable. This means you will have to check and see where you are how much light there is in the evironment. Testing with the serial monitor to determine the values is highly recommended.
What Do You Need
- Arduino Uno Board
- Small breadboard
- Pushbutton
- LED
- Light sensor
- DC motor
- Motor Driver
- 2x 10kΩ resistor
- 1x 330Ω resistor
- Various cables
Hardware


In the pictures you can see how I've set everything up.
The real life picture is a bit messy, that's why I've added a Tinkercad circuit design to make it a bit more clear.
The important thing is you kind of have 3 circuits.
1. LED circuit
2. Pushbutton circuit
3. Light sensor circuit
4. DC motor circuit
I've put most of my circuits near the ends of the breadboard. This means there is plenty of room in the middle to put your DC motor later.
Software/ Code
//setup pins motor const int standBy = 10; const int PWMA = 3; const int AIN1 = 9; const int AIN2 = 8; //setup button const int buttonPin = 13; //const variables wont change int buttonState = 0; int ldrValue = 0; //Pins const int ldrPin = A2; const int ledPin =12; void setup () { pinMode(standBy, OUTPUT); //motor A pinMode(PWMA, OUTPUT); pinMode(AIN1, OUTPUT); pinMode(AIN2, OUTPUT); //ledPin en Sensor pinMode(ldrPin, INPUT); pinMode(ledPin, OUTPUT); pinMode(buttonPin,INPUT); Serial.begin(9600); } void loop() { ldrValue = analogRead(ldrPin); Serial.print("light value: "); Serial.println(ldrValue); if (ldrValue <= 850) { digitalWrite(ledPin, HIGH); } else if (ldrValue > 850) { digitalWrite(ledPin, LOW); } buttonState = digitalRead(buttonPin); // a variable to store the button readout if (buttonState == HIGH){ forward(50); //Serial.println("MOTOR ON"); } else { stop(); //Serial.println("MOTOR OFF"); } } void forward(int spd) { runMotor(spd, 0); } void back(int spd) { runMotor(spd, 1); } void runMotor(int spd, int dir) { digitalWrite(standBy, HIGH); boolean dirPin1 = LOW; boolean dirPin2 = HIGH; if (dir == 1) { dirPin1 = HIGH; dirPin2 = LOW; } digitalWrite(AIN1, dirPin1); digitalWrite(AIN2, dirPin2); analogWrite(PWMA, spd); } void stop() { digitalWrite(standBy, LOW); }<br>
Designing the Shell


I made a shell to go around the small breadboard. It fitted around it.
Important thing when making a shell is checking where you'll put your DC motor, your lightsensor and the LED. It could also be handy to provide some room near the button.
On the shell you draw a clock.
I also made a little box around the sensor. This made the difference in values easier to tell apart.
The dial can be a very basic line or arrow. That's up to you to choose.
I added a little sign with the name of the game but thats completely optional and doesn't really serve a purpose besides decoration.
End Result



And there you have it! Your Home by the Curfew game is all done!