Arduino PWM signal from PID controller

13 visualizaciones (últimos 30 días)
Dechao Zeng
Dechao Zeng el 31 de Jul. de 2020
Respondida: Daniel Velazquez el 6 de Jul. de 2021
I am working on a project using Arduino Leonardo to control the brightness of an LED ring based on the brightness of the environment which is detected by a webcam as a sensor. My end goal is to have 8 independent zones on the ring that control their own brightnesses. However, as a trial this attached code has only 4 zones working. I have attached my matlab file below and I get the following error when I run the code:
"Operands to the || and && operators must be convertible to logical scalar values.
Error in Untitled44 (line 101)
elseif ((0 < PIDGLg(i)) && (PIDGLg(i) < 1)) "
I wanted to know how to convert this to a logical scalar value and also use this similar scalar value in the WritePWMVoltage function for the Arudino.
I am new to MATLAB and would really appreciate the help!!

Respuestas (2)

Pranav Verma
Pranav Verma el 11 de Nov. de 2020
Hi Dechao,
In line 102, you are accessing the index using 'i' in PIDGLg after incrementing it. So in the last iteration, the index will go out of bounds. You can try incrementing 'i' (Line 94) at the end of the loop instead.
Thanks

Daniel Velazquez
Daniel Velazquez el 6 de Jul. de 2021
How about doing this PID with Simulink? You would still use the Arduino board
Attached is the example

Categorías

Más información sobre Arduino Hardware en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by