Abdelrahman Salah
Published © CC BY-NC

Smart Disk Lamp

Smart desk lamp It lights when there is a person or motion and the light is weak or there is no lighting

BeginnerFull instructions provided4 hours362
Smart Disk Lamp

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
SparkFun Qwiic Single Relay
SparkFun Qwiic Single Relay
×1
Lamp Holder, B22d Lamps
Lamp Holder, B22d Lamps
×1
Incandescent Lamp, 230 V
Incandescent Lamp, 230 V
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×2
SG90 Micro-servo motor
SG90 Micro-servo motor
×2
Test Accessory, AC Power Adaptor
Test Accessory, AC Power Adaptor
×1
Spacer, Hex
Spacer, Hex
×8

Software apps and online services

Arduino IDE
Arduino IDE
Fusion 360
Autodesk Fusion 360
Tinkercad
Autodesk Tinkercad

Hand tools and fabrication machines

Drill, Screwdriver
Drill, Screwdriver
Laser cutter (generic)
Laser cutter (generic)
3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Desk+Lamp.f3z

THE+TOP+BASE.dxf

THE+BOTTOM+BASE.dxf

THE+FIRST+SIDE.dxf

THE+SECOND+SIDE.dxf

THE+THIRD+SIDE.dxf

THE+FOURTH+SIDE.dxf

lamp cap.stl

ultra sonic cap.stl

Code

final_project_22.ino

C/C++
#include <Servo.h>
Servo myservo2;  

int potpin2 = 0;  
int val2;   

Servo myservo;  

int potpin = 0;  
int val;    
int ldr = 4;
int bulb = 3;
int trig = 5;
int echo = 2;
void setup() {
  myservo2.attach(11);
  myservo.attach(9); 
  pinMode (ldr, INPUT );
  pinMode (bulb, OUTPUT);
  pinMode (trig , OUTPUT);
  pinMode (echo ,INPUT );
  Serial.begin(9600);
}
void loop() {
  long duration, cm;
  digitalWrite(bulb, LOW);
  delayMicroseconds(echo);
  digitalWrite(bulb, HIGH);
  delayMicroseconds(trig);
  digitalWrite(bulb, LOW);
  duration = pulseIn(echo, HIGH);
  cm = duration/29/2;
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  delay(100);
  int motion ;
  if (cm < 30) {
    motion =1 ;
  } else {
    motion =0;
  }
  int brightness = digitalRead (ldr);
  if (motion){
  if (brightness) {
    digitalWrite (bulb, HIGH);
  } 
  else {
        digitalWrite (bulb, LOW);
  }
  Serial.print(brightness);
  Serial.print(",");
   
  }
  else {
    digitalWrite( bulb, LOW );
  }
  val = analogRead(potpin); 
  Serial.println(map(val, 0, 1023, 0, 180) );        
  val = map(val, 0, 1023, 0, 180);     
  myservo.write(val);   
  val2 = analogRead(potpin2);            
  val2 = map(val2, 0, 1023, 0, 180);     
  myservo2.write(val2);                  
  delay(15);                 
     
  
}

Credits

Abdelrahman Salah

Abdelrahman Salah

4 projects • 1 follower
I'm currently pursuing a bachelor of Engineering in computer engineering
Thanks to Bulent Yusuf.

Comments