This document provides a detailed overview of the Levitating Sphere Control System. The system uses an Arduino UNO microcontroller to control a fan, ultrasonic sensor, potentiometer, pushbutton, LCD display, and a buzzer. The fan speed is controlled based on the potentiometer input, and the sphere's position is displayed on the LCD. The system can be started or stopped using a pushbutton.
Arduino UNO
Pushbutton
NPN Transistor (EBC)
HC-SR04 Ultrasonic Sensor
Resistor (1k Ohms)
Resistor (10k Ohms)
16x2 I2C LCD
Potentiometer
Piezo Buzzer
Fan
// Levitating Sphere Control System
// This code controls a levitating sphere using a fan, ultrasonic sensor,
// potentiometer, pushbutton, LCD display, and a buzzer. The fan speed is
// controlled based on the potentiometer input, and the sphere's position is
// displayed on the LCD. The system can be started/stopped using a pushbutton.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#include <Button.h>
// Define pin numbers
#define POT_PIN A0
#define BUZZER_PIN 3
#define START_STOP_PIN 2
#define FAN_CONTROL_PIN 9
#define TRIG_PIN 10
#define ECHO_PIN 11
// Define LCD dimensions
#define LCD_COLS 16
#define LCD_ROWS 2
// Variables
int airSpeed = 0;
int spherePosition = 0;
bool isRunning = false;
// Initialize LCD (Check the address using I2C scanner if unsure)
LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS);
Button startStopButton(START_STOP_PIN);
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize LCD
lcd.begin(LCD_COLS, LCD_ROWS);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Initializing...");
// Set up button and buzzer
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW);
pinMode(START_STOP_PIN, INPUT_PULLUP);
pinMode(FAN_CONTROL_PIN, OUTPUT);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
// Display ready status
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Air Speed: ");
lcd.setCursor(0, 1);
lcd.print("Sphere Pos: ");
}
void loop() {
// Read and map potentiometer value
airSpeed = map(analogRead(POT_PIN), 0, 1023, 0, 255);
// Update air speed on LCD
lcd.setCursor(12, 0);
lcd.print(airSpeed);
lcd.print(" ");
// Handle button press to toggle system state
if (startStopButton.pressed()) {
isRunning = !isRunning;
digitalWrite(BUZZER_PIN, isRunning ? HIGH : LOW);
if (!isRunning) {
analogWrite(FAN_CONTROL_PIN, 0);
}
while (startStopButton.pressed()) delay(10);
}
if (isRunning) {
// Control fan speed
analogWrite(FAN_CONTROL_PIN, airSpeed);
// Measure sphere position using ultrasonic sensor
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
long duration = pulseIn(ECHO_PIN, HIGH);
spherePosition = duration * 0.034 / 2;
// Update sphere position on LCD
lcd.setCursor(12, 1);
lcd.print(spherePosition);
lcd.print(" cm ");
}
delay(100);
}
This code initializes the necessary components and continuously reads the potentiometer value to control the fan speed. It also measures the sphere's position using the ultrasonic sensor and displays the information on the LCD. The system can be toggled on and off using the pushbutton, and the buzzer indicates the system's running state.