in this lesson we are going to learn how to control an active buzzer with Arduino
the next project we are controlling a motor that is attached to a wheel
so we are turning it on and off which will later will be using it with our smart car
the third project is a water pump control where later on where water with a soil moisture sensor
so we can water it automatically this course is based on SunFounder three in one Arduino
kit sold on Amazon everything that you learn in this course is included in this kit the course
comes with tons of components and projects all with instruction and video for smart car and
other projects that you can use for school or home automation you can purchase it from sunfounder.com
the kit also comes with full documentation code download learning projects with full
explanation wiring diagram and the code that you can download a link to purchase the kit
and documentation is below the video in the description welcome to Arduino course by Robojax
this is called an active buzzer which means there are components
that you have to pay attention to the polarity the longer pin is positive the
shorter pin is negative there is also a label so this will operate with 5 volts
now if we go to the SunFounder documentation page under the learning project click on beep you will
see this page and here is how you wire it the positive will be connected to pin 8 of Arduino
and the negative will be connected to ground and on the breadboard we will insert it like that
positive is on this side and we have two lines of whole empty the right one we will connect it via
yellow to pin 8 and after two lines of hole empty the left or the negative is connected to ground
here I'm inserting It Like That by holding the long pen on this side just somewhere
and then on the edge that's where the yellow is and then the black will go after two empty lines
here's Arduino pin it and ground is connected like that
now let's go and open the project click on file open go to download SunFounder three and one
three in one kit main learning project 1.2 and click and click open
there are things in this code that are incorrect
and also some elements are ahead of time so let's remove everything
and like this so I'm just highlighting copy and then in here right click paste or Ctrl V
okay so let's explain the code again like the other code that I've explained we are
defining a pen called buzzer pen so the buzzer will be connected to pin 8 so we are assigning
it to this variable of type integer which is constant now inside the setup using pen mode
we set buzzer pen which is pin 8 as output so this is outputting and inside the loop
the loop using digital right we are setting the buzzer pin to high so this is sending
5 volts or high to buzzer pen which is pin 8 and then we keep it waiting for one second it
buzzes and then we send Using we send low to this pen using digital right now that
line is 0 for 1 second and the loop ends and the code will come back so
it will be high low one second beep one second of one second big one second off
now Arduino is not connected I'm connecting it
so, we have old code running now let's upload the code
I was sure that it was working but you can click on
I was sure that it was working but you can click on verify to get error and here as you can see
the buzzer is running if I disconnect the wire, it will turn off, I'm connecting it again
now let's change the code
to 500 second a millisecond of 500 millisecond on and then uploaded so we can see the effect
I can make it 300 so it will be quick
foreign
how to turn on a wheel for smart car this is just a beginning we are just learning
how to turn it on and off using digital right we are using l298n motor driver
do not worry about this so this can control two Motors one motor on this side one motor on this
side we are just using one motor and it needs power so we will connect five volts to power
this up and also we just send signal to control the motor we are just turning it on and off only
here this is a l298n motor driver this is our motor in order to turn this motor on we
cannot connect it to Arduino because this Arduino can supply very little current so
we need a driver so the motor driver where we will attach this wheel or tire for a Smart car
so it works like this the weak signal from Arduino comes to the motor driver and the strong signal
will drive the motor we cannot connect the motor directly to Arduino because we have a
very weak signal which is not capable of driving the motor for that purpose we need motor driver
this is called a geared motor so actually this motor is this this type but we have here gears
that is slowing it down so this will run around 10 000 RPM or maybe 6000 I'm not sure about it
but this is slowing it down slowing it down so the wheel can rotate and car will Drive slowly
from the right side of the motor driver we will connect a negative for example to one
pen this negative and positive will determine the direction of rotation of the motor so the
posit the negative will be connected to the Top Line and the red will be connected to positive
to the second one from these two pins we get N4 to pen 10 and entry using blue wire to pin 9. this is
sending signal to the motor driver then from this positive which says 12 volts we are connecting it
to 5 and from ground it is connected to ground even though this motor needs a lot of power but
for this demonstration purpose we can connect it but later on we will learn that this needs higher
power and this should not be connected to 5 volts first let's prepare the wires we will connect
from red and black here let's open it I think red in here and black and then tighten it
ill to female disconnect the yellow to the first hole in here like that and then blue
to the second one now this is ready for our motor and
connect it like that and tighten it we'll connect the positive to 5 volts this black to ground
yellow boost to pen 10. and blue goes to pen 9.
now let's open the sketch open
go to download
learning kit 1.3 wheel open it
now let me explain it first we Define motor pen for pen a which has been 9 and as you can see
it's showing you highlighted that's very nice and pin B pin 9 so pin a was eight again integer and
constant inside the setup we Define pen a as output and then pin B motor pin b as an output
two pin is output now inside the loop first we turn pin a high and pin B low we must do this
so the two pin one is high one is low and it's sending signal for the motor so the motor is
rotating and keeping it with waiting for two seconds after that we are setting both pens
then a and pin B to low for half a second now pay attention here when a was high now we are making
pin a low and pin B was low we are making it high so these two are sending motor in One Direction
these two lines ascending it into the other direction so one could be clockwise the other
could be counterclockwise and we are waiting for two seconds and again sending 0 0 to both pens to
stop the motor for half a second and the loop will come back and do the same thing all over again
so, the code is loaded and as you can see the motor is rotating in One Direction
and stopping and going into the other direction the time that it waits is 500 milliseconds if you
want to increase it or decrease it or turning it on for longer period it's your choice
this is a small water pump where we can connect a pipe here so it can suck the water from the bottom
and pump it via this uh pipe hole to wherever we want it here this is a pipe that we can connect it
like that to be secure and this will be connected to the motor driver
so the same as before definite high power so we send very weak signal from Arduino to the motor
driver and motor driver will send strong signal to control the rotation of this pump or motor
here is the wiring if I click on 1.4 this is pumping,
we are connecting exactly the same as before you see the same l298n and the motor is
connected exactly the same way wiring is the same way so there is no difference
and here the two wires of N3 and 4 are connected to the same point
everything is the same except we are just replacing the wheel motor to pump motor
for the water pump project all the wiring is exactly the same except we replace the wheel
driver with a water pump and make sure to connect the red on this side and black on this side
now let's open the code file open
go to go to download fan founder
learning project 1.4 pumping and open it
so the codes are as follow we have a here pin 9
defined as motor pin and motorPinA spin 10 everything is exactly the same as before we first
this time we don't have anything inside loop so the setup runs only once and the motor run forever
so when the motor runs forever using pen mode pen a is output and pin B is also output first
we Define them as an output and then we drive them using digital right to plan a we write high
and using digital right we write low to motor Plan B and this will keep the motor running
this is my setup I have why I have water here and a pump so we are going to pump water from
this dish to this one to the glass to the transparent one but because it will be very
messy and every everywhere might get a lot of watery so what you do is you put it in
the dish that does not have water like that and turn it on and then we will immerse it in water
this is a blank sketch I've uploaded it now let's upload the actual code
this is now an empty dish the code is successfully uploaded
now let's immerse the motor and water be careful I have to hold it in here
do not worry keep it few seconds until it pumps the water
see now it's pumping here initially because the motor is weak it takes sometimes don't worry
so, the Water started pumping
now if I lift it up it will be empty now let's put it back now it's pouring it into the other dish
let me disconnect it
and stop it