Color Gyro

SRJT10201

Jugaadu and Chandan went together to see a magic show. Chandan was fascinated by the art of magician, as he saw some great magic tricks. After the show got over, Chandan challenged Jugaadu to perform some good tricks with his tinkering skills. Jugaadu decided to make the magic box. How will Jugaadu make a magic box with his tinkering kit?

  1. Arduino UNO UNO
  2. Scissor
  3. Triple Axis Accelerometer
  4. USB Cable
  5. Jumper cables
  6. RGB LED
  7. Cardboard
  8. Glue gun
  9. Tape
  10. 12V Battery
  11. Cutter
  12. Paper
Let us do some magic with the help of LED. We will tilt the box and it will change the colour giving an effect of magic. With the help of accelerometer, it will sense the tilt and further it can change the colour of the LED.

    int r=3;int g=5;int b=6;
int x=A0;int y=A1;int z=A2;

void setup() {
// put your setup code here, to run once:
pinMode(r,OUTPUT);
pinMode(g,OUTPUT);
pinMode(b,OUTPUT);
analogWrite(4,255);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print(analogRead(x));
Serial.print(" . ");
Serial.println(analogRead(y));
if(analogRead(x)>375){
digitalWrite(r,0);
digitalWrite(g,1);
digitalWrite(b,1);
}else if(analogRead(x)<320){
digitalWrite(r,1);
digitalWrite(g,0);
digitalWrite(b,1);
}else if(analogRead(y)>375){
digitalWrite(r,0);
digitalWrite(g,1);
digitalWrite(b,0); 
}else if(analogRead(y)<320){
digitalWrite(r,1);
digitalWrite(g,1);
digitalWrite(b,0); 
}else{
digitalWrite(r,0);
digitalWrite(g,0);
digitalWrite(b,0); 
}
}