Old Town Night
Old town night is a diorama I made for school.
It is a town with 4 houses, and behind the houses are different lights that flicker. 3 of the 4 houses flicker randomly. 1 house you can choose the lights by a potentiometer.
These are the steps I took to make the project:
1. I first designed the houses in Onshape and then printed them with a 3d printer
2. I then started making each part of the hardware and software first.
3. I then added those pieces together.
4. I made a hole in the box from behind, this way I could insert the cables into the breadboard and make easy adjustments to the hardware.
Downloads
Supplies
In the front
- 4 3D printed houses
https://cad.onshape.com/documents/14c737f99d6d69ac...
- A shoe box
In the back
- Ardiuno UNO
- 8 leds
- 4 yellow
- 2 green
- 2 blue
- 7 1k ohm resistors
- 1 servomotor
- Breadboard
- 1 potentiometer
- lightsensitive sensor
Code for Ardiuno Uno
This is the code I made for in the file. You can copy and paste it directly.
Details
- I made the light sensor on top. Then when the box opens the sensor is covered and the star starts spinning.
- I made another platform myself so I could stick the potentiometer in there.
- When my cables touch each other put a piece of paper between them.
const int ldrPin = A1; //the number of the LDR pin
//Vallende ster #include
Servo myservo;
//potentiometer const int analog_ip = A0; const int LED1 = 8; const int LED2 = 9; int inputVal = 0;
//flikkerlichtjes #define delay50 1000
int myled[] = {2, 3, 4, 5}; int num_of_leds;
void setup() { Serial.begin(9600); pinMode(ldrPin, INPUT); //initialize the LDR pin as an input //vallende ster myservo.attach(11); //potentiometer pinMode (LED1, OUTPUT); pinMode (LED2, OUTPUT); //flikkerlichtjes num_of_leds = sizeof(myled) / sizeof(int); for (int i = 0; i < num_of_leds; i++) { pinMode(myled[i], OUTPUT); }}
void loop() { int ldrStatus = analogRead(ldrPin); //read the status of the LDR value Serial.print("LDRvalue: "); Serial.println(ldrStatus);
//check if the LDR status is <= 300 //if it is, the LED is HIGH
if (ldrStatus <= 200) { potentiometerLeds(); //Vallende ster myservo.write(0); delay(2000); potentiometerLeds(); myservo.write(180); delay(5000); potentiometerLeds();
//flikkerlichtjes delay(2000); potentiometerLeds(); for (int i = 0; i < 50; i++){pattern11();} potentiometerLeds(); }
else { Serial.println("---------------"); }}
//RANDOM EFFECT 1 void pattern11() { int randomnum = random(0, num_of_leds + 1); digitalWrite(myled[randomnum], HIGH); potentiometerLeds(); delay(delay50); digitalWrite(myled[randomnum], LOW); potentiometerLeds(); delay(delay50);} void potentiometerLeds () { //potentiometer inputVal = analogRead(analog_ip); Serial.print("potval: "); Serial.println(inputVal); analogWrite (LED1, inputVal/4); analogWrite (LED2, (1023-inputVal)/4);}