hey deepak hi cj what's up
remember that we wanted to build a solar
tracking system with a solar cell and a
servo controlled by an arduino
want to build it now yeah that would be
great but i don't have access to the
hardware
how do we dissolve that well if you
create the model using simulink
and simulate it on your end to make sure
it works then i can deploy the model to
my hardware
that way we can work remotely and it
could be like a fun virtual lab
assignment for us
that's a good idea cj and we can make it
into an iot
project i can use thinkspeak to control
the hardware over the internet and
collect sensor output
okay that sounds good and maybe this
video could inspire some students and
professors to make their own remote
learning project
great so let's define the problem with
some more details
we want to build a miniature solar
tracking system and we will use simulink
to build a model and simulate the
behavior
we have three components in our simulink
model user input from think speed
a state flow chart to program states and
lastly sending sensor readings to things
peak
we will focus on the state flow chart as
it's the real brains of the system
the chart has two main states it's
either going to stay at a particular
angle or it will scan to find the angle
at which the maximum voltage is present
we are going to run the simulink model
in simulation as i don't have access to
the hardware
right now the system is set to a desired
angle of 50 degrees
let's pause here and talk about things p
as i mentioned earlier i can use
thinkspeak to change the system behavior
as well as collect sensor output let's
take a look at how simulink and tank
speak are working together
here i have some things we greet blocks
that are reading a thingspeak channel
each block is reading one field from the
channel
operation mode desired position reset
time between scans
and wait time between readings now let's
take a look at how we can write data
back to thingspeak
here i have a similar setup where i am
writing data to several fields of a
different thingspeak channel
okay so now that we've seen the setup
let's try to use thinkspeak to change
the mode
so that we can simulate a scan from 0 to
180 degrees
this is the thinkspeak channel i'm using
to send data to my simulink model
if i want to change any of the field
values i can simply copy this url
and paste it before i press enter i will
make sure i change the mode to 1.
since we are now scanning you can see
the state flow chart highlight different
blocks during the scan
our second things peak channel is now
updating and showing the current angle
and voltage
note that for our simulation we chose a
predefined signal and hence it repeats
if you want to track the angle at which
the maximum voltage is occurring for a
full day
then these two graphs will show you that
long term trend if you want to learn
more about
how to use thingspeak here is an example
that will help you out
now let's get back to the problem at
hand i have now been able to simulate
how our system should behave
but i don't have access to the hardware
let's see how cj can use my simulation
model
and modify it to work on the hardware
now we can get to the fun part
let's deploy the model and the hardware
here's the model updated for deployment
in the hardware sections we'll make a
few slight changes to the
input and to the output blocks
the brain or the state flowchart remains
unchanged
be sure to change the hardware type in
the hardware settings and it's ready to
run on the arduino
let's check to make sure that our
simulink model still works
use the monitor and tune button for
hardware-in-the-loop testing
we're going to run the simulink model in
external mode so we can use the hardware
to run the model but see any changes on
our laptop
as we see the model runs as expected
entering mode 1
which is what i have set in thinkspeak
now you might wonder
how can i deploy this model in the
arduino so it's not connected to the
computer anymore
just click on the build and deploy
button sim link will take care of the
rest
it will convert the simulink model into
code that the hardware can understand
now our system is running independent of
the laptop
now my colleague can control the
hardware remotely in this entire project
he never directly interacted with the
hardware
let's add another complication to this
problem how can we get both the
simulation model and the hardware
deployment model in the same simulink
model
the answer is to use various subsystems
simulink will intelligently determine
which blocks to connect depending on if
you want to simulate
or deploy to hardware the variant
subsystems
have both the hardware and simulation
blocks the ports that get connected are
determined by which block you click at
the top level of the model
the output variant subsystem is similar
the ports that are connected are
determined by the top level model
settings
thank you cj for working remotely with
me on this cool virtual assignment
if you want to reference the simulink
models we use in this video then check
the links in the description below
we are excited to learn how you will use
things we can simulink together
comment below