Hi, i am still new to this and i have been trying different ways to solve the problem to no avail. What i am trying to archive is to be able to activate actuator and display the value of the temperature sensor, I was able to activate actuator but not able to receive the data from temperature sensor Thank you in advance for the help.
Sensor: Grove - Temperature Sensor V1.2 (Temp Only)
The empty box are for making the button/list picking central to my phone
Code(App Inventor):
Arduino Mega code:
type or paste code here
```#include <RGBmatrixPanel.h>
#include <Servo.h>
#define CLK 11 // For Arduino Mega
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2
#define D A3
#define LED 12
int servoPin = 4; // Declare the Servo pin
Servo Servo1;
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 64);
//Temperature
int sensorPin = A4; // Analog pin where the temperature sensor is connected
int sensorValue;
float temperature;
void setup()
{
//Led
pinMode(LED, OUTPUT);
//Servo motor
Servo1.attach(servoPin);
int startpoint = 5; // Set the starting point (0 to 180)
Servo1.write(startpoint); // Move the servo to the start position
//Serial Monitor
Serial.begin(9600); // Start Serial Monitor for debugging
Serial1.begin(9600); // Start Bluetooth Serial on Serial1
Serial.println("Bluetooth test: Waiting for messages...");
//Matrix
matrix.begin();
matrix.setTextSize(1); // Set text size to 1 (8 pixels high)
matrix.setTextWrap(false); // Don't wrap text when false, wrap text when true
matrix.fillScreen(matrix.Color333(0, 0, 0)); // Clear the matrix screen
matrix.setTextColor(matrix.Color333(7, 7, 0)); // Bright yellow text color
}
void loop()
{
sensorValue = analogRead(sensorPin); // Read the raw analog value from the sensor
temperature = (sensorValue * 5.0 / 1023.0) * 10;
// Send temperature to Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
// Send temperature data via Bluetooth
Serial1.println(String(temperature));
Serial.println(String(temperature));
delay(1000); // Wait for 1 second before reading again
static String incomingMessage = "";
bool messageComplete = false;
// Collect data from Bluetooth serial input
while (Serial1.available())
{
char c = Serial1.read();
if (c >= 32 && c <= 126)
{
incomingMessage += c;
}
else if (c == '\n') // End of message (newline received)
{
messageComplete = true;
incomingMessage.trim();
incomingMessage.toLowerCase(); // Convert to lowercase for case-insensitive check
Serial.print("Received Message: ");
Serial.println(incomingMessage);
}
}
// Process complete message
if (messageComplete)
{
if (incomingMessage == "on" || incomingMessage == "1")
{
digitalWrite(LED, HIGH);
}
else if (incomingMessage == "off" || incomingMessage == "0")
{
digitalWrite(LED, LOW);
}
else if (incomingMessage == "open")
{
Servo1.write(65); // Move the servo to 65 degrees
delay(1000);
}
else if (incomingMessage == "close")
{
Servo1.write(5); // Move the servo to 5 degrees
delay(1000);
}
else
{
displayMessage(incomingMessage.c_str()); // Display other messages on matrix
}
incomingMessage = ""; // Clear the message buffer
messageComplete = false; // Reset the flag
}
}
void displayMessage(const char* message)
{
matrix.fillScreen(matrix.Color333(0, 0, 0)); // Clear the matrix screen
int textWidth = strlen(message) * 6; // Approximate width: 6 pixels per character
if (textWidth <= 64)
{
// If the message fits, display it statically on the left side
matrix.setCursor(0, 0);
matrix.print(message);
}
else
{
// If the message is too wide, scroll it from left to right
//for (int x = 64; x <= -textWidth; x--)
// If the message is too wide, scroll it from right to left
for (int x = 64; x >= -textWidth; x--)
{
matrix.fillScreen(matrix.Color333(0, 0, 0)); // Clear screen each time
matrix.setCursor(x, 0); // Update cursor position
matrix.print(message);
delay(50); // Adjust scrolling speed here
}
}
}