This week, I wanted to create a smart lamp. If there is sunlight, the lamp doesn't work. On the other side, if there isn't any light, the lamp turns on if there is anyone studying.
The theme is a Smart device for my work desk.
software
Arduino IDE
Electronics
Material
Making on Tinkercad
I used Tinker CAD to design the circuit to ensure the wiring
Hint: I used a PIR sensor instead of light sensor, which I used in the real circuit because it isn't found in TinkerCAD
Preparation of cardboard
front part
back part
right and left part
top and bottom part
The logic behind the coding process is represented by this flow chart:
wiring the circuit
relay module (output )
first, I cut one of the parts from the LED and connected it to the CM & NC
Ultrasonic sensor
the red wire connected to 5V of the Arduino
the black wire connected to the GND
the purple wire "echo" connected to pin 3
the blue wire "
Light sensor (input)
the red wire connected to 5V of the Arduino
the black wire connected to the GND
the purple wire connected to A0
LCD (output)
the white wire connected to 5V of the Arduino
the black wire connected to the GND
the blue wire" SDA" connected to A4
the green wire "SCL" connected to A5
putting them in the enclosure
I used yellow tape to fix the component
I cut part from the cardboard to pass the wires of the lamp
coding
const int echoPin = 3;
const int trigPin = 4;
// in ultrasonic sensor
const int ledPin = 8;
//which connected to relay module
const int sensorPin = A0;//light sensor
float time = 0;
float distance = 0;
//to calculate the equation of ultra sonic sensor
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(trigPin, OUTPUT);
lcd.init();
lcd.init();
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
time = pulseIn(echoPin, HIGH, 30000);
distance = time / 58.0;
//the equation of ultrasonic sensor
int sensorValue = analogRead(sensorPin);
if (sensorValue >= 900) {
if (distance <= 2) {
digitalWrite(ledPin, LOW);
Serial.println(sensorValue);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(" STUDY HARD! ");
lcd.setCursor(0, 1);
lcd.print("led on ");
delay(1000);
} else {
digitalWrite(ledPin, HIGH);
Serial.println(sensorValue);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(" Waiting you ");
lcd.setCursor(0, 1);
lcd.print("led off");
}
} else {
digitalWrite(ledPin, HIGH);
Serial.println(sensorValue);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("No need for me");
}
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(500);
}
const int echoPin = 3;
const int trigPin = 4;
// in ultrasonic sensor
const int ledPin = 8;
//which connected to relay module
const int sensorPin = A0;//light sensor
float time = 0;
float distance = 0;
//to calculate the equation of ultra sonic sensor
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(trigPin, OUTPUT);
lcd.init();
lcd.init();
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
time = pulseIn(echoPin, HIGH, 30000);
distance = time / 58.0;
//the equation of ultrasonic sensor
int sensorValue = analogRead(sensorPin);
if (sensorValue >= 900) {
if (distance <= 2) {
digitalWrite(ledPin, LOW);
Serial.println(sensorValue);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(" STUDY HARD! ");
lcd.setCursor(0, 1);
lcd.print("led on ");
delay(1000);
} else {
digitalWrite(ledPin, HIGH);
Serial.println(sensorValue);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(" Waiting you ");
lcd.setCursor(0, 1);
lcd.print("led off");
}
} else {
digitalWrite(ledPin, HIGH);
Serial.println(sensorValue);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("No need for me");
}
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(500);
}
The final project
This video describes making the origami lamp
The first challenge is the light sensor:
I changed the sensitivity of the light sensor from the potentiometer
The second challenge was the reading of the ultrasonic sensor
I found that the reading was incorrect. After a lot of searching, I discovered that the equation of the distance was wrong
Title of Media
It was amazing how we can convert a real object or person to a 3d model on a laptop . it was unexpected extra session with alot of information