Hii ni kazi ya mradi (Project work) ya kumaliza elimu ya ngazi ya Stashahada (Diploma) katika chuo cha Fedha (IFM - Main campus)
Mradi huu una mlengo wa kuongeza usalama wa majumbani kwa kufanya na kuleta vitu vya kiotomatiki kwa kutumia vifaa mbalimbali vya kiumeme kwa njia za kiumbali
SoftwareSerial
Servo
Libraries
za SoftwareSerial
na Servo
(Mara nyingi huwa zinakuja na IDE ya Arduino)readSMS()
: Inasoma ujumbe ulioingiagetSenderNumber(String sms)
: Unasoma namba ya aliyetumagetMessage(String sms)
: Ichabue ujumbe husikalockDoor()
: Amri ya kufunga mlangounlockDoor()
: Amri ya kufungua mlangovoid setup() {
Serial.begin(9600);
mySerial.begin(9600);
doorMotor.attach(8);
lockMotor.attach(9);
}
void loop() {
if (mySerial.available()) {
String sms = readSMS();
Serial.println(sms);
String senderNumber = getSenderNumber(sms); // Namba ya mtumaji
String message = getMessage(sms); // Meseji ya mtumaji
...
}
}
String readSMS() {
String sms = "";
while (mySerial.available()) {
char c = mySerial.read();
sms += c;
delay(10);
}
return sms;
}
Kupata namba ya mtumaji
String getSenderNumber(String sms) {
int start = sms.indexOf("+");
int end = sms.indexOf(",", start);
return sms.substring(start, end);
}
String getMessage(String sms) {
int start = sms.indexOf("\n");
int end = sms.indexOf("\n", start + 1);
if (end == -1) {
end = sms.length();
}
String message = sms.substring(start + 1, end);
message.trim();
return message;
}
void lockDoor() {
Serial.println("TAARIFA:\n Mlango unafungwa");
doorMotor.write(90);
delay(1000);
Serial.println("TAARIFA:\n Kitasa kinafungwa");
lockMotor.write(90);
delay(1000);
Serial.println("TAARIFA:\n Mlango na kitasa viimefungwa");
}
void unlockDoor() {
Serial.println("TAARIFA:\n Mlango unafunguliwa");
doorMotor.write(0);
delay(1000);
Serial.println("TAARIFA:\n Kitasa kinafunguliwa");
lockMotor.write(0);
delay(1000);
Serial.println("TAARIFA:\n Mlango na kitasa vimefunguliwa");
}