Arduino Crystal Ball

This is the 11th project in the Arduino Starter Kit. Do note that I have skipped the 9th and 10th projects because my DC motor isn’t working.

Setup

Here’s what we need:

  • Arduino UNO + Breadboard
  • Jumper wires
  • LCD Screen
  • Potentiometer
  • Tilt Sensor
  • 1 x 10 kΩ Resistor
  • 1 x 220 Ω Resistor

Layout

Here’s our schematic, as per the Arduino Projects Book.

And here’s my incredibly messy build:

Code

We will be using the LCD Display (Arduino) library to control our screen. While setting up, all we need to do is print out the initial message we want the user to see.

void setup() {
 lcd.begin(16, 2);
 pinMode(switchPin, INPUT);
 lcd.print("Crystal Ball");
 lcd.setCursor(0, 1);
 lcd.print("At your service");
}

Then, using the random() method, we will give our output.

reply = random(8);
switch(reply) {
    case 0:
    lcd.print("Yes");
    break;
    case 1:
    lcd.print("Probabale");
    break;
    case 2:
    // ...

That’s all there is to it. You can see the full code here.

Arduino Light Theremin (Starter Kit Project #6)

We will use a phototransistor as a light sensor to control a piezo and produce sound – resembling the functionality of an actual theremin.

Setup

Here’s what we need:

  • Arduino UNO + Breadboard
  • Jumper wires/cables
  • 1 10kΩ resistor
  • Piezo
  • 1 phototransistor

Layout

Here’s what the instrument should look like, as per the Arduino projects book.

And here is what I made:

Code

The calibration of the sensor is the most important part in this mini-project.

int sensLow = 1023;
int sensHigh = 0;

void setup() {
    while (millis() < 5000) {
        sensVal = analogRead(A0);
        if (sensVal > sensHigh) {
            sensHigh = sensVal;
        }
        if (sensVal < sensLow) {
            sensLow = sensVal;
        }
    }
}

The millis function returns the amount of time for which our board has been working. Thus, we calibrate for the first five seconds by taking in the minimum and maximum possible sensor input values. These will be used to scale our input values later on.

void loop() {
  sensVal = analogRead(sensPin);
  int pitch = map(sensVal, sensLow, sensHigh, 50, 4000);
  tone(8, pitch, 20);
  delay(10);
}

Here, we take in our input value and map it to the appropriate frequency. Then, using the tone function, we output sound using our piezo (which vibrates as per the frequency provided by tone()). You can play around the frequency and mapping values just for fun.

Arduino Mood Cue (Starter Kit Project #5)

Here, we will turn a potentiometer to consequently rotate a simple servo meter. The arduino will collect the data a

Setup

Here are the components we need:

  • Arduino UNO + Breadboard
  • 2 100 μF Capacitors
  • Jumper wires/cables
  • Potentiometer
  • Servo Motor (with arm)

Layout

Here’s what it should look like, as per the Arduino projects book.

And here is my build:

You might notice that there are some differences between the schematic and what I’ve made. Firstly, the potentiometer is just too large to be placed on the same strip as a capacitor and power/ground connections, which is why I have used orange jumpers to elongate the entire setup. Also note that the capacitors, if connected incorrectly, could potentially explode. I would google up how to connect these and then proceed! It took me a lot of time to find out which pin is the anode and which pin is the cathode. Turns out the pin which has a grey arrow full of zeros pointing downwards is the negatively charged electrode, or the cathode.

Code

You can find the full code here.

#include <Servo.h>
Servo myServo;

To start, we import the library required to interact with the servo motor, and create an instance of the Servo object to handle our motor. Then, all we need is 4 lines of functional code.

void loop() {
    potVal = analogRead(potPin);
    angle = map(potVal, 0, 1023, 0, 179);
    myServo.write(angle);
    delay(15);
}

Firstly, we read our analogue potentiometer value and convert it into an angle for rotating our servo motor. Then, using the servo library, we turn our motor. The delay of 15 milliseconds is to accomodate the time used up in rotating the motor.

Demo

Arduino Color Mixing Lamp (Starter Kit Project #4)

This entire thing is fairly simple. We will use phototransistors to input the RGB components of any light source to our arduino. The arduino will then convert these to digital values, and combine the RGB components to operate a four pin, RGB LED. All we have to do is input to our uno, process the data (fancy word for dividing by 4), and output.

Setup

Here’s what we’ll need:

  • Arduino UNO
  • Breadboard
  • 3 220 Ω resistors, 3 10 kΩ resistors.
  • Jumper wires/cables
  • 4 pin RGB LED
  • RGB color filters
  • 3 phototransistors

Layout

Here’s what the circuit should look like (from the arduino starter kit projects book).

And here is my build:

You can see that I didn’t use the wooden components already in the starter kit to appropriately connect the filters to the phototransistors. This is because those components were too small (probably a defect in the kit), fitting the screens caused them to fly across the room at random intervals.

Code

You can find the full code here. I’m not discussing the setup part here.

void loop() {
    redSensVal = analogRead(redSensPin);
    delay(5);
    greenSensVal = analogRead(greenSensPin);
    delay(5);
    blueSensVal = analogRead(blueSensPin);
}

Here we’re reading in the rgb components of the light source under scrutiny. A delay of five milliseconds has been taken as the arduino takes a while to process analogue inputs and convert them into digital values.

void loop() {
    // ...
    
    redVal = redSensVal/4;
    greenVal = greenSensVal/4;
    blueVal = blueSensVal/4;

    analogWrite(redLEDPin, redVal);
    analogWrite(blueLEDPin, blueVal);
    analogWrite(greenLEDPin, greenVal);
}

Now we divide by four because our analogue input corresponds to digital values between 0 and 1023. However, our output LED requires digital values between 0 and 255. Given that our output LED requires analogue inputs, we use the UNO’s built in DAC to display our combined RGB components.

Note

Many people (including me) initially thought that this entire thing wasn’t working. This isn’t the case. The fact is that the phototransistors that come with the starter kit are incredibly insensitive. They registers values of o,0,0 for room lights (and most lights), which is why there is no discernible output unless one uses a strong flashlight (built-in in smartphones) or a decent light source.

Here’s a small demo. You can visibly see that iphone flashlights have strong blue and green components.

Mini-Demo