The assignment for this week is to make a smart device with multiple inputs and actions. I will make roulette game with ultra sonic sensor activation. I was inspired by a mini game.
We Used Tinker CAD to simulate The Circuit and its component.
It is easy to use and safer to test our project without risking the component.
We Used Arduino as the brain for the project.
We use Arduino IDE to write the code.
Components:
Cardboard
Wires
Power adapter
Breadboard
LEDs
DC motor
Crocodile wires
Arduino Uno
Bluetooth module
Ultrasonic sensor
Driver Module L298n
Adapter
For Input we use Ultrasonic sensor and on and off switch.
The ultrasonic sensor will turn on the circuit at certain distance and turn it off when the distance increase.
For output we use LED and DC motor.
We use driver module to protect Arduino.
We put adapter because Arduino cannot power the DC motor efficiently.
Connect the (+) of the breadboard with the 5v pin on the Arduino.
Connect the (-) of the breadboard with the ground pin on the Arduino.
Put the LED on the breadboard.
Connect the one end of a resistor with the cathode end of the LED and the other with the (-) of the breadboard which is connected to the Arduino.
Connect the anode end of the LED with the digital pin 12.
Connect the Ultrasound distance sensor as follows: Power to the (+) of the breadboard, Ground to the (-) of the breadboard, Trigger to pin 9, Echo to pin 10.
connected the DC motor in parallel to the circuit so every component receives the full voltage of the power.
We connect the DC motor to the motor Driver and because we do not need to control direction of rotation, we use one pin to control the on and another for off function.
Dc motor connected to pin 11 = High
Dc motor connected to pin 8 = Low
Added a switch to the circuit and connected it to pin 13.
Code:
We Set the on function based on one of these conditions:
If the ultrasonic sensor read distance less than 3 cm or the switch is on
when on, The Dc motor starts, and the LED turns on.
We set the off function based on one of these conditions:
If ultra sonic sensor read distance other than 3cm or the switch is off.
When off, The DC motor stops, and the LED turns off.
The challenge was that the DC motor was not working after connecting to the motor drive. I searched and found out that it has to be connected to adapter because the 5v from Arduino board is not enough to run the DC Motor and it needs 9v or 12v adapter and it needs a common ground with Arduino so I did it and it worked.
Now I can after many tries I guess, make a simple code for my project.
Coding !!!