Aims of the Week
- Construct the final box
- Perform the final tests on the design
- Print out the poster
- Practice the group presentation and get ready for bench inspection
Hamza's Tasks and Updates
This week saw the construction of the final design, which included putting the box together and adding each circuit one by one into the box using the laser cut holes. Once we started constructing the box, we realised that the holes were too small for the box, which meant I had to measure out and file the holes down more to allow the right room for the connections. This week also saw the power circuit's final connection, which aimed to connect the solar panels in series to the switch and output through the USB.
I then tested the power circuit and found it was a success in generating a minimum of 3V and a maximum of 8V through solar panels with different brightness lights. The test included seeing if a power bank would power the circuits, which worked.
This week, I also finished off and printed the poster for the project along with getting the documents and presentation ready for the bench inspection.
Abdulla's Tasks and Updates
In the final week, we assembled all the circuits and enclosed them in a box. This included glowing all the motors to the solar panels and tower, so they were table and putting all the wires through the laser, cut holes to the inside of the box.
We ran into an issue with the attached solar panel being too heavy for the motor, causing it to fall off. To solve this, we added a battery as a counterweight to balance out the solar panel. This taught us that in a further improved module, we add gears to bear the weight
Caesar's Tasks and Updates
In the final week, we worked together to construct the box. My tasks were to connect the sensors, which were attached to the box, to the Arduino Uno and display the data on the LCD using an i2C which allowed for simplification of the circuit.
We then tested the final device and showed how the data changed on the LCD, showing the sensors were working.
This week's outcomes
- Finished the box
- Printed Poster
Home Tasks
The Device in Action
Document Links
Circuit Diagram
Code for the Sensor LCD Circuit
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DFRobot_LTR390UV.h>
#include <DHT.h>
// LCD I2C 地址(如果 I2C 扫描到的是 0x3F,请改成 0x3F)
LiquidCrystal_I2C lcd(0x27, 20, 4);
// LTR390 传感器
DFRobot_LTR390UV ltr390(LTR390UV_DEVICE_ADDR, &Wire);
// DHT22 传感器
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
// 时间变量
unsigned long previousMillis = 0;
int seconds = 00;
int minutes = 30;
int hours = 6;
int days = 27; // 默认从 1 天开始
int months = 2; // 默认从 1 月开始
int years = 2025; // 默认从 2024 年开始
void setup() {
Serial.begin(115200);
// 初始化 LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Initializing...");
// 初始化 LTR390 传感器
while (ltr390.begin() != 0) {
Serial.println("LTR390 Init Failed!");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("LTR390 Init Failed!");
delay(1000);
}
Serial.println("LTR390 Ready!");
// 初始化 DHT22
dht.begin();
// 设置 LTR390 参数
ltr390.setALSOrUVSMeasRate(ltr390.e18bit, ltr390.e100ms);
ltr390.setALSOrUVSGain(ltr390.eGain3);
ltr390.setMode(ltr390.eALSMode); // 设置为环境光模式
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sensors Ready!");
delay(2000);
}
void loop() {
// 时间更新
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 1000) { // 每秒更新一次
previousMillis = currentMillis;
seconds++;
if (seconds >= 60) {
seconds = 0;
minutes++;
}
if (minutes >= 60) {
minutes = 0;
hours++;
}
if (hours >= 24) {
hours = 0;
days++;
}
// 简单的月份天数计算(不考虑闰年)
if (days > 30) { // 这里假设所有月份 30 天
days = 1;
months++;
}
if (months > 12) {
months = 1;
years++;
}
}
// 读取 DHT22 传感器数据
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// 读取 LTR390 光照数据
float alsData = ltr390.readALSTransformData();
Serial.print("Date & Time: ");
Serial.print(years);
Serial.print("/");
Serial.print(months);
Serial.print("/");
Serial.print(days);
Serial.print(" ");
Serial.print(hours);
Serial.print(":");
Serial.print(minutes);
Serial.print(":");
Serial.println(seconds);
Serial.print("Temp: ");
Serial.print(temperature);
Serial.print(" C, Humidity: ");
Serial.print(humidity);
Serial.println(" %");
Serial.print("ALS: ");
Serial.print(alsData);
Serial.println(" Lux");
// 在 LCD 显示数据
lcd.clear();
// 第 1 行:时间 + 日期
lcd.setCursor(0, 0);
lcd.print(years);
lcd.print("/");
lcd.print(months);
lcd.print("/");
lcd.print(days);
lcd.print(" ");
lcd.print(hours);
lcd.print(":");
lcd.print(minutes);
lcd.print(":");
lcd.print(seconds);
// 第 2 行:温度
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C");
// 第 3 行:湿度
lcd.setCursor(0, 2);
lcd.print("Humidity: ");
lcd.print(humidity);
lcd.print(" %");
// 第 4 行:光照
lcd.setCursor(0, 3);
lcd.print("Light: ");
lcd.print(alsData);
lcd.print(" Lux");
delay(1000); // 每秒更新
}
Code for the LDR Motor Circuit
#include <Servo.h>
//defining Servos
Servo servohori;
int servoh = 0;
int servohLimitHigh = 160;
int servohLimitLow = 20;
Servo servoverti;
int servov = 0;
int servovLimitHigh = 160;
int servovLimitLow = 20;
//Assigning LDRs
int ldrtopl = 2; //top left LDR green-LDR 3
int ldrtopr = 1; //top right LDR yellow-LDR 2
int ldrbotl = 3; // bottom left LDR blue-LDR 4
int ldrbotr = 0; // bottom right LDR orange-LDR 1
void setup ()
{
servohori.attach(10);
servohori.write(0);
servoverti.attach(9);
servoverti.write(0);
delay(500);
}
void loop()
{
servoh = servohori.read();
servov = servoverti.read();
//capturing analog values of each LDR
int topl = analogRead(ldrtopl);
int topr = analogRead(ldrtopr);
int botl = analogRead(ldrbotl);
int botr = analogRead(ldrbotr);
// calculating average
int avgtop = (topl + topr) / 2; //average of top LDRs
int avgbot = (botl + botr) / 2; //average of bottom LDRs
int avgleft = (topl + botl) / 2; //average of left LDRs
int avgright = (topr + botr) / 2; //average of right LDRs
if (avgtop < avgbot)
{
servoverti.write(servov +1);
if (servov > servovLimitHigh)
{
servov = servovLimitHigh;
}
delay(10);
}
else if (avgbot < avgtop)
{
servoverti.write(servov -1);
if (servov < servovLimitLow)
{
servov = servovLimitLow;
}
delay(10);
}
else
{
servoverti.write(servov);
}
if (avgleft > avgright)
{
servohori.write(servoh +1);
if (servoh > servohLimitHigh)
{
servoh = servohLimitHigh;
}
delay(10);
}
else if (avgright > avgleft)
{
servohori.write(servoh -1);
if (servoh < servohLimitLow)
{
servoh = servohLimitLow;
}
delay(10);
}
else
{
servohori.write(servoh);
}
delay(50);
}
//LCD display
Comments
Post a Comment