One of my wishes is to live in a smart house🤩.. so I tried to fulfill the seed of that wish
TinkerCad
I used it to simulate the electrical circuit before implementing it.
Software
Arduino Bluetooth control
To control the code operation By mobile
Arduino Uno
To write the code and transfer it to be implemented using Arduino board
Electrical tools:
Jumper Wires
Crocodile wire🐊
1-Make a mind map .
2-Research for ways to write dc motor code.
3-Build the electrical circuit on tinkercad
not : I replaced the components that are not on the program, such as the driver and Bluetooth (the connections are similar).
Writing the code
char userInput = '0';
int motor1pin1 = 7;
int motor1pin2 = 8;
int motor1Speed = 9;
int ledY = 2;
int ledG = 3;
int ledW = 4;
void setup() {
Serial.begin(9600);
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(motor1Speed, OUTPUT);
pinMode(ledW, OUTPUT);
pinMode(ledG, OUTPUT);
pinMode(ledY, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
userInput = Serial.read();
Serial.println(userInput);
digitalWrite(ledW, LOW);
digitalWrite(ledG, LOW);
digitalWrite(ledY, LOW);
if (userInput == '1') {
analogWrite(motor1Speed, 80);
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
digitalWrite(ledW, HIGH);
}
else if (userInput == '2') {
analogWrite(motor1Speed, 110);
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
digitalWrite(ledG, HIGH);
digitalWrite(ledW, HIGH);
}
else if (userInput == '3') {
analogWrite(motor1Speed, 165);
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
digitalWrite(ledY, HIGH);
digitalWrite(ledG, HIGH);
digitalWrite(ledW, HIGH);
}
else {
analogWrite(motor1Speed, 0);
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, LOW);
digitalWrite(ledW, LOW);
digitalWrite(ledG, LOW);
digitalWrite(ledY, LOW);
}
}
}
Finally, there were some grammatical errors. I had ChatGPT review them and send the code without errors.
Definition of variables
definition of the motor pins from the driver (7, 8, 9 ).
definition of the LED pins (2,3,40.
char .... is the variable user will enter it
setup
The definition of all pins is that they are outputs
loop
Use if function :
When you enter 1, the first speed of the motor 80 is turned on and the first LED lights up...
When you enter 2, the second speed of the motor is turned on and the first and second LEDs are lit...
When you enter 3, the third speed is turned on and three LEDs are lit...
When you press any other number, the motor is turned off
Real electrical circuit
Search for drive connection
cardboard mode
Finally 🥳
Three speed fan with lights indicating speed
I couldn't use the Bluetooth program on my iPhone... so Basmala helped me download it on my mother's mobile (Huawei has a special method)
This message appeared after an incorrect upload.
problem:
When I run the code..the motor doesn't work just makes a noise
The reason:
I uploaded the code to the Arduino and the Bluetooth module is connected to it
Sol:
The main reason🙂
I can make my project smarter using bluetooth.
our صنارة 😂